-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
69 lines (59 loc) · 1.35 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
#!/bin/bash
# TODO capture output for errors
try_run() {
sh -c "$1" 2>test_run_failed
}
# source dest
try_compile_with_gcc() {
try_run "make -s $1.gcc"
}
try_compile_with_project() {
try_run "make -s $1.tracc"
}
try_compile_normal() {
try_compile_with_gcc $1
}
compare_results() {
qemu-aarch64-static ./$1.tracc
local res1=$?
qemu-aarch64-static ./$1.gcc
local res2=$?
if [ $res1 -eq $res2 ]; then
return 0
else
echo "$res1 (project's compiler) != $res2 (working compiler)" 1> test_run_failed
return 1
fi
}
test_one() {
local res=0
try_compile_with_project $1 && try_compile_normal $1 && compare_results $1 && echo -e '\x1b[32m'$2'\x1b[m' \
|| { echo -e '\x1b[31m'$2'\x1b[m'; echo "---- error message for $2 --------"; cat test_run_failed; echo "----------------------------------"; res=1; }
rm test_run_failed
return $res
}
test_stage() {
echo "---- testing stage $@ ----"
local path="write_a_c_compiler/stage_$1/valid"
while [ $# -gt 1 ]; do
shift
path="$path/$1"
done
local res=0
for i in $path/*.c; do
if ! test_one "${i%%.*}" "`basename $i`"; then
res=1
fi
done
return $res
}
if [ "$1" = "--one" ]; then
test_one "${2%%.*}" "`basename $2`"
exit $?
fi
if [ $1 -eq 6 ] && [ $# -eq 1 ]; then
test_stage 6 expression
test_stage 6 statement
else
test_stage $@
fi