@@ -12,19 +12,22 @@ WHITE=$(tput setaf 7)
12
12
BOLD=$( tput bold)
13
13
RESET=$( tput sgr0)
14
14
15
- # Die on first error.
16
- set -e
17
-
18
15
function summary {
19
16
echo -e " $BOLD$GREEN ==>$WHITE ${1} $RESET "
20
17
}
21
18
19
+ failed=0
20
+
22
21
function compile_and_run {
23
22
local test_program=$1
24
- summary " Testing $test_program "
25
23
26
24
# Compile the file.
27
25
./target/release/bfc sample_programs/$test_program
26
+ if [[ $? -ne 0 ]]; then
27
+ echo " Compilation failed!"
28
+ failed=1
29
+ return
30
+ fi
28
31
29
32
# Run it, saving output.
30
33
local executable=" ${test_program% .* } "
@@ -35,23 +38,37 @@ function compile_and_run {
35
38
else
36
39
./$executable > output.txt
37
40
fi
41
+ if [[ $? -ne 0 ]]; then
42
+ echo " Program crashed!"
43
+ failed=1
44
+ return
45
+ fi
38
46
39
47
# Compare output.
40
48
local expected_output=sample_programs/${test_program} .out
41
49
if [ -f $expected_output ]; then
42
- echo -n " (checked output)"
43
- diff output.txt $expected_output
50
+ diff output.txt $expected_output > /dev/null
51
+ if [[ $? -ne 0 ]]; then
52
+ echo " Output differs!"
53
+ failed=1
54
+ return
55
+ fi
44
56
fi
57
+ }
45
58
46
- # Cleanup.
47
- rm $executable output.txt
59
+ function check_program {
60
+ summary " Testing $1 "
61
+ compile_and_run $1
48
62
49
- echo
63
+ # Cleanup.
64
+ rm -f ${1% .* } output.txt
50
65
}
51
66
52
- compile_and_run bangbang.bf
53
- compile_and_run hello_world.bf
54
- compile_and_run bottles.bf
55
- compile_and_run factor.bf
56
- compile_and_run mandelbrot.bf
57
- compile_and_run life.bf
67
+ check_program bangbang.bf
68
+ check_program hello_world.bf
69
+ check_program bottles.bf
70
+ check_program factor.bf
71
+ check_program mandelbrot.bf
72
+ check_program life.bf
73
+
74
+ exit $failed
0 commit comments