-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·238 lines (195 loc) · 6.15 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# **************************************************************************** #
# #
# ::: :::::::: #
# test.sh :+: :+: :+: #
# +:+ +:+ +:+ #
# By: gshona <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/03/17 14:04:59 by gshona #+# #+# #
# Updated: 2021/03/18 14:25:55 by gshona ### ########.fr #
# #
# **************************************************************************** #
#!/bin/bash
############## USER SETTINGS ##########################
#
#Root of project
DIR="../cub3d"
#
#
#Name of the executable
EXEC_NAME="cub3d"
#
#
#
#Path to sample to a valid map from DIR directory
SAMPLE_MAP="maps/1.cub"
# for example: if your executable is in DIR and your map is in DIR/maps
# then thi value must be maps/map.cub
#
#
#
#Name of screenshot which generated when executing with "--save" from DIR
SCREENSHOT="picture.bmp"
# for exmple: if your cub3D drops the image to the same dir where executeble is located
# then this value must be only name of the image
#
#######################################################
############# KEYS ####################################
#
# --map # prints map to stdin
# --save # runs cub3D with --save key
# --valid # runs cub3D with only valid maps
# --invalid # runs cub3D with only invalid maps
# --undefined # runs cub3D with only maps wich are nither valid nor invalid
# --leaks # runs cub3D and checks leaks (not implemented yet)
#
#
# If you want to check leaks
# just run this script without --save flag
# and keep game window opened for few seconds
#
#######################################################
############# EXAMPLES ################################
#
# ./test.sh # run all maps
# ./test.sh --save # run all maps with --save key
# ./test.sh --map # run all tests and print maps to stdout
# ./test.sh squares # run only one map called squares.cub
# ./test.sh squares --save # same as previous but with --save key
# ./test.sh --valid --save # run only valid maps with --save key
# ./test.sh --valid # run only valid maps playable
#
#######################################################
############ VVVV!!! DANGER ZONE !!!VVVV ############
TEMPLATES="map_templates"
SCREENSHOTS="screenshots"
MAP="./map.cub"
SAVE_KEY=""
DISPLAY_MAP=0
fail_count=0
only_valid=0
only_ivalid=0
only_undef=0
skip=0
check_leaks=0
map_count=0
save_f=0
function single_map()
{
f=$(find map_templates -type f -name '*.cub' | grep $1 | tail -n 1)
#echo $f " <<<<<<<<<<<< "
#echo $WE " <<<<<<<<<<<<<<<"
common_step $f
}
function common_step()
{
f=$1
TESTNAME=$(basename $f | sed 's/\.cub//g')
echo "======================= " $TESTNAME " =========================\n"
cp $f $MAP
SHOT=$(basename $f | sed 's/\.cub/\.bmp/g')
sed -i '' "s/NNNNN/$DIR_S\/$NO/g" map.cub
sed -i '' "s/WWWWW/$DIR_S\/$WE/g" map.cub
sed -i '' "s/EEEEE/$DIR_S\/$EA/g" map.cub
sed -i '' "s/SSSSS/$DIR_S\/$SO/g" map.cub
sed -i '' "s/SPSPSP/$DIR_S\/$S/g" map.cub
if (($DISPLAY_MAP == 1)); then
echo "filename: " $f
cat $MAP
echo ''
fi
$DIR/$EXEC_NAME $MAP $SAVE_KEY
if (( $? != 0)); then
echo "FAIL"
(( fail_count++ ))
fi
if [[ $SAVE_KEY == '--save' ]]
then
if test -f "$SCREENSHOT"; then
mv $SCREENSHOT $SCREENSHOTS/$SHOT
else
echo "SCREENSHOT IS MISSING"
fi
fi
echo ''
}
for arg in $@ ; do
if [[ $(echo $arg | cut -c -2) == '--' ]] ; then
case $arg in
"--save")SAVE_KEY='--save'; save_f=1;;
"--map")DISPLAY_MAP=1;;
"--leaks")check_leaks=1;;
"--valid")only_valid=1;skip=1;;
"--invalid")only_invalid=1;skip=1;;
"--undefined")only_undef=1;skip=1;;
*)echo "unrecognized key: " $arg; exit 2;;
esac
fi
done
if (( save_f == 0 && check_leaks )); then
echo "Leaks may be checked only in playable mode"
echo "If you want to check leaks just run this script without --save flag and keep game window opened for few seconds"
exit 4
fi
make -C $DIR
if test -f "$DIR/$EXEC_NAME"; then
echo "Executable found"
else
echo "EXECUTABLE NOT FOUND"
fi
mkdir $SCREENSHOTS 2> /dev/null
SAMPLE=$DIR/$SAMPLE_MAP
NO=$(cat $SAMPLE | grep 'NO ' | awk '{print ($2)}' | sed 's/\.\///g' | sed 's/\//\\\//g')
WE=$(cat $SAMPLE | grep 'WE ' | awk '{print ($2)}' | sed 's/\.\///g' | sed 's/\//\\\//g')
EA=$(cat $SAMPLE | grep 'EA ' | awk '{print ($2)}' | sed 's/\.\///g' | sed 's/\//\\\//g')
SO=$(cat $SAMPLE | grep 'SO ' | awk '{print ($2)}' | sed 's/\.\///g' | sed 's/\//\\\//g')
S=$(cat $SAMPLE | grep 'S ' | awk '{print ($2)}' | sed 's/\.\///g' | sed 's/\//\\\//g')
DIR_S=$(echo $DIR | sed 's/\./\\\./g' | sed 's/\//\\\//g')
if [ -z $1 ]
then
SAVE_KEY=""
else
if [[ $(echo $1 | cut -c -2) == '--' ]]
then
echo ''
else
if [[ -z $(find map_templates -type f -name '*.cub' | grep $1) ]]; then
echo "Unknown argument " $1
exit 1
else
single_map $1;
exit 0
fi
fi
fi
if (( skip == 0 || (skip == 1 && only_valid == 1 ) )); then
echo "+++++++++++++++++ VALID MAPS +++++++++++++++++++++++\n"
map_count=$(ls -1 $TEMPLATES/valid | grep '.cub' | wc -l)
i=1
for f in $TEMPLATES/valid/*; do
echo "======= [ " $i " / " $map_count " ] ======"
common_step $f
(( i++ ))
done
fi
if (( skip == 0 || (skip == 1 && only_invalid == 1 ) )); then
echo "+++++++++++++++++ INVALID MAPS +++++++++++++++++++++++\n"
map_count=$(ls -1 $TEMPLATES/invalid | grep '.cub' | wc -l)
i=1
for f in $TEMPLATES/invalid/*; do
echo "======= [ " $i " / " $map_count " ] ======"
common_step $f
(( i++ ))
done
fi
if (( skip == 0 || (skip == 1 && only_undef == 1 ) )); then
echo "+++++++++++++++++ UNDEFINED MAPS +++++++++++++++++++++++\n"
map_count=$(ls -1 $TEMPLATES/undefined | grep '.cub' | wc -l)
i=1
for f in $TEMPLATES/undefined/*; do
echo "======= [ " $i " / " $map_count " ] ======"
common_step $f
(( i++ ))
done
rm $MAP
fi