This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
generated from dthain/compilerbook-starter-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtest.sh
executable file
·81 lines (73 loc) · 1.71 KB
/
runtest.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
#!/bin/sh
export PATH=$PATH:.
if [ $# -lt 1 ]; then
echo "Please specify the module to test."
exit 1
fi
module="$1"
printer_test () {
for testfile in ./test/printer/good*.bminor; do
if bminor --print "$testfile" > "$testfile.out" &&
bminor --print "$testfile.out" > "$testfile.tmp" &&
diff "$testfile.out" "$testfile.tmp" > /dev/null; then
echo "$testfile success (as expected)"
rm "$testfile.tmp"
else
echo "$testfile failure (INCORRECT)"
fi
done
}
codegen_test () {
for testfile in ./test/codegen/good*.bminor; do
if bminor --codegen "$testfile" > "$testfile.out" &&
gcc -x assembler "$testfile.out" -o "$testfile.exe"; then
echo "$testfile success (as expected)"
else
echo "$testfile failure (INCORRECT)"
fi
rm "$testfile.exe"
done
}
case $module in
"encoder")
command="encode"
;;
"scanner")
command="scan"
;;
"parser")
command="parse"
;;
"printer")
printer_test
exit
;;
"resolver")
command="resolve"
;;
"typechecker")
command="typecheck"
;;
"codegen")
codegen_test
exit
;;
*)
echo "Unknown module: $module"
exit 1
;;
esac
for testfile in ./test/"$module"/good*.bminor; do
if bminor --"$command" "$testfile" > "$testfile.out" 2>&1; then
echo "$testfile success (as expected)"
else
echo "$testfile failure (INCORRECT)"
fi
done
for testfile in ./test/"$module"/bad*.bminor; do
if bminor --"$command" "$testfile" > "$testfile.out" 2>&1; then
echo "$testfile success (INCORRECT)"
else
echo "$testfile failure (as expected)"
fi
done