/
test.sh
executable file
·51 lines (44 loc) · 913 Bytes
/
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
#!/bin/bash
set -uo pipefail
# Using output of compiled executables as actual values, expected values are read from expected.txt
# Unfortunately return values get converted to 8-bit unsigned ints so e.g. -2 is 254.
expectedArr=()
for line in $(cat ./tests/expected.txt); do
expectedArr+=($line)
done
files=()
for file in ./tests/*.c; do
files+=($file)
done
dotnet run c "${files[@]}"
if [ $? -eq 1 ]
then
rm ./tests/*.s
exit 1
fi
i=0
passed=0
failed=0
for asmfile in ./tests/*.s; do
exe="$asmfile.out"
gcc $asmfile -o $exe
$exe
actual=$?
if [ $actual -ne ${expectedArr[i]} ]
then
echo "${files[i]}: expected ${expectedArr[i]}, got $actual"
((failed=failed+1))
else
((passed=passed+1))
fi
rm $asmfile
rm $exe
((i=i+1))
done
echo "$passed tests passed, $failed failed"
if [ $failed -gt 0 ]
then
exit 1
else
exit 0
fi