-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·71 lines (59 loc) · 1.95 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
70
71
#!/bin/bash
# If this is set to true, compare the output of the user compiler to that of the
# reference compiler.
CHECK_OUTPUT=true
# Fill in your compiler command here.
COMPILER=civcc
# Fill in the reference compiler here.
REFERENCE_COMPILER=civcc
# Fill in the assembler and virtual machine here.
ASSEMBLER=civas
VM=civvm
# Do not touch anything below. Actually, I don't really care what you do because
# it's a local copy so go ahead.
FAIL=0
TOTAL=0
execute() {
$1 -o _tmp_$2.s $3 >/dev/null 2>&1
$ASSEMBLER -o _tmp_$2.out _tmp_$2.s 2>&1
$VM _tmp_$2.out 2>&1
RV=$?
rm -f _tmp_$2.s _tmp_$2.out
return $RV
}
cd "$(dirname "${BASH_SOURCE[0]}")"
shopt -s nullglob
command -v $COMPILER >/dev/null 2>&1 || { echo "$COMPILER is not an executable file."; exit 1; }
echo "Running failure tests..."
for x in fail/*.cvc; do
TOTAL=$((TOTAL+1))
$COMPILER $x 1>/dev/null 2>/dev/null && {
echo "Test $x should not succeed!";
FAIL=$((FAIL+1));
}
done
echo "Running runtime failure tests..."
for x in runtime/*.cvc; do
TOTAL=$((TOTAL+1))
$COMPILER $x 1>/dev/null 2>/dev/null && execute $COMPILER usr $x >/dev/null && {
echo "Test $x should not run!";
FAIL=$((FAIL+1));
}
done
echo "Running success tests..."
for x in success/*.cvc; do
TOTAL=$((TOTAL+1))
$COMPILER $x 1>/dev/null 2>/dev/null || {
echo "Test $x should not fail!";
FAIL=$((FAIL+1));
continue;
}
if [ $CHECK_OUTPUT = true ]; then
diff <(execute $REFERENCE_COMPILER ref $x) \
<(execute $COMPILER usr $x) > /dev/null \
|| { echo "Test $x did not match reference output!"; FAIL=$((FAIL+1)); }
fi
done
if [ $TOTAL -eq 0 ]; then echo "No tests were run. Make sure you are in the right directory."; exit 1; fi
echo "Passed $((TOTAL-FAIL)) out of $((TOTAL)) tests. Your grade: $(bc -l <<< "scale=1; ($TOTAL-$FAIL) * 10 / $TOTAL")."
if [ $FAIL -eq 0 ]; then echo "Well done! :)"; fi