This repository has been archived by the owner on Nov 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathruntests.sh
executable file
·83 lines (63 loc) · 1.46 KB
/
runtests.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
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
CLR_ERR="\x1b[1;31m"
CLR_SUC="\x1b[1;32m"
CLR_BLD="\x1b[1;49m"
CLR_RST="\x1b[0m"
function test_valid {
PROGRAM=$1
FILE=$2
printf "Testing %s... " $FILE
if [[ $USE_VALGRIND -ne 0 ]]; then
$VALGRIND $PROGRAM $FILE;
else
$PROGRAM $FILE 2>/dev/null 1>/dev/null;
fi || {
echo "${CLR_ERR}unexpectedly rejected valid input$CLR_RST";
FAILED=$((FAILED+1))
false;
} && {
echo "OK"
PASSED=$((PASSED+1))
}
}
function test_invalid {
PROGRAM=$1
FILE=$2
printf "Testing %s... " $FILE
if [[ $USE_VALGRIND -ne 0 ]]; then
$VALGRIND $PROGRAM $FILE;
else
$PROGRAM $FILE 2>/dev/null 1>/dev/null;
fi && {
echo "${CLR_ERR}unexpectedly accepted invalid input$CLR_RST";
FAILED=$((FAILED+1))
} || {
echo "OK"
PASSED=$((PASSED+1))
}
}
function run_tests_in_directory {
TESTDIR=$1
SPARKLING=$2
for f in $TESTDIR/p_*; do
test_valid "$SPARKLING" "$f";
done
for f in $TESTDIR/f_*; do
test_invalid "$SPARKLING" "$f";
done
}
PASSED=0
FAILED=0
USE_VALGRIND=1
WORKDIR=$(pwd)
pushd 'test'
# Run unit tests for parser
run_tests_in_directory parser "$WORKDIR/bld/spn --dump-ast";
# Run unit tests for compiler
# run_tests_in_directory compiler "$WORKDIR/bld/spn --compile";
# Run unit tests for VM/runtime
# run_tests_in_directory runtime "$WORKDIR/bld/spn";
# Run unit tests for library functions
# run_tests_in_directory stdlib "$WORKDIR/bld/spn";
popd
echo "$CLR_BLD$((PASSED+FAILED)) total, $CLR_SUC$PASSED passed, $CLR_ERR$FAILED failed$CLR_RST"