-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.sh
executable file
·115 lines (93 loc) · 2.62 KB
/
run_tests.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
#!/usr/bin/env bash
# We extract everything except levels, since SIDEDEFS and BLOCKMAP lumps
# will not be exactly the same after decompression.
DEUTEX_OPTS="
-v0 -overwrite -png -rgb 0 255 255
-flats -graphics -lumps -musics -patches -sounds -sprites -textures
"
set -eu
wd=$(mktemp -dt wadptr-test.XXXXXX)
trap "rm -rf '$wd'" INT EXIT
file_size() {
ls -l "$1" | while read _ _ _ _ len rest; do
echo "$len"
done
}
deutex_extract() {
local fn=$1
local dir=$2
rm -rf "$dir"
mkdir -p "$dir"
# We set up the bootstrap wad as a fake IWAD to make deutex happy.
cp bootstrap.wad "$dir/doom2.wad"
export -n DOOMWADDIR DOOMWADPATH
pushd "$dir"
if ! deutex $DEUTEX_OPTS -xtract "$fn"; then
echo "deutex exited with status $? when extracting $fn"
fi
popd
}
test_wad_file() {
local fn=$1
local orig_size=$(file_size "$fn")
deutex_extract $fn $wd/deutex-orig
if ! ./wadptr -c $fn; then
return 1
fi
if ! ./wadptr -l $fn; then
return 1
fi
if ! ./wadptr -o $wd/compr2.wad -c $fn || ! diff $fn $wd/compr2.wad; then
echo "WAD differs after compression a second time"
return 1
fi
if ! ./wadptr -l $fn; then
return 1
fi
deutex_extract $fn $wd/deutex-compressed
local new_size=$(file_size "$fn")
if ! [ $new_size -lt $orig_size ]; then
echo "$fn compressed size: $new_size" \
"not smaller than original size: $orig_size"
return 1
fi
if ! ./wadptr -u $fn; then
return 1
fi
if ! ./wadptr -l $fn; then
return 1
fi
if ! ./wadptr -o $wd/uncompr2.wad -u $fn ||
! diff $fn $wd/uncompr2.wad; then
echo "WAD differs after decompression a second time"
return 1
fi
if ! ./wadptr -l $fn; then
return 1
fi
# Decompressed WAD contents (apart from levels) should exactly match
# the original WAD.
deutex_extract $fn $wd/deutex-decompressed
if ! diff -q -r $wd/deutex-orig $wd/deutex-decompressed; then
echo "Decompressed WAD contents do not match original."
return 1
fi
local decompr_size=$(file_size "$fn")
# TODO: Do something to check the uncompressed file vs. original
#echo "$fn $orig_size $new_size $decompr_size"
}
all_success=true
find test -name '*.wad' | while read wad; do
filename=$(basename $wad)
cp $wad $wd
if test_wad_file "$wd/$filename" >$wd/log 2>&1; then
echo "PASS $filename"
else
echo "FAIL $filename"
sed "s/^/| /" < $wd/log
all_success=false
fi
done
if ! $all_success; then
exit 1
fi