-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·63 lines (54 loc) · 1.33 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
passed=0
failed=0
function failed {
file=$1
msg=$2
prog=$(cat $file | sed -z 's/\s\s*/ /g')
((failed++))
echo -ne "\r\033[K=== $file FAILED ===\n"
echo " $msg"
echo " $prog"
}
function test {
file=$1
prog="$(cat $file)"
# expected output
gcc -std=c99 -pedantic -Werror -Wno-implicit-function-declaration -Wno-builtin-declaration-mismatch -o temp.out $file 2>/dev/null
if [[ $? -ne 0 ]]; then
failed "$file" "can't compile(gcc)"
return
fi
expected="$(./temp.out)"
if [[ $? -ne 0 ]]; then
failed "$file" "non-zero exit code(gcc)"
return
fi
# compile input
./mycc $file -o temp.s 2>/dev/null
if [[ $? -ne 0 ]]; then
failed "$file" "can't compile"
return
fi
# build executable
gcc temp.s -o temp.out 2>/dev/null
if [[ $? -ne 0 ]]; then
failed "$file" "can't assembly"
return
fi
# checkout output
real=$(./temp.out)
if [[ $? -ne 0 ]]; then
failed "$file" "non-zero exit code"
return
fi
if [[ "${real}" != "${expected}" ]]; then
failed "$file" "bad output"
return
fi
((passed++))
}
for file in $(ls test/*.c | sort -n); do
test $file
echo -ne "\r\033[KTest Summary: ${passed} PASSED, ${failed} FAILED"
done
echo -ne "\n"