-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtests.sh
executable file
·121 lines (111 loc) · 3.6 KB
/
tests.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
if [ -n "$ZSH_NAME" ]; then
setopt extended_glob;
else
shopt -s globstar nullglob dotglob;
fi;
declare K_RED="\033[31m";
declare K_END="\033[0m";
declare -i failed=0;
declare -i ran=0;
read -r -d '' usage << 'EOF'
usage: yasl [option] [input]
options:
-C: checks `input` for syntax errors but doesn't run it.
-e input: executes `input` as code and prints result of last statement.
-E input: executes `input` as code.
-h: show this text.
-V: print current version.
input: name of file containing script (or literal to execute with -e or -E).
EOF
[[ "$1" == "-m" ]];
declare NO_MEM=$?;
# Memory tests may take a long time to run, so we print out the files as we run the tests, to help us see hangs.
run_mem_tests () {
declare folder="$1";
echo "Running memory tests in $folder...";
for f in test/$folder/**/*.yasl; do
printf "\rRunning $f";
size=$((${#f} + 18));
valgrind --error-exitcode=-1 --leak-check=full --exit-on-first-error=yes ./yasl $f > /dev/null 2>&1;
declare exit_code=$?;
if (( exit_code == 255 )); then
case ${f%.yasl} in
test/inputs/scripts/fib_match|test/inputs/scripts/fib|test/errors/stackoverflow/fib|test/errors/stackoverflow/list_eq|test/inputs/closures/memoize|test/inputs/scripts/heap|test/inputs/vargs/*|test/errors/assert/foreach)
(( ++skipped ));
;;
*)
>&2 echo "Memory Error in $f";
(( ++failed ));
;;
esac;
fi;
printf \\r
printf '%0.s ' $(seq 1 "$size");
done;
}
run_tests () {
declare folder="$1";
declare expected_exit="$2";
echo "Running tests in $folder...";
if [[ ! -d "test/$folder" ]]; then
>&2 echo "Error: could not find $folder";
exit -1;
fi;
declare ext;
case "$expected_exit" in
0) ext=".out" ;;
*) ext=".err" ;;
esac;
for f in test/$folder/**/*.yasl; do
expected=$(<"$f$ext");
actual=$(./yasl "$f" 2>&1);
declare exit_code=$?;
if [[ "$expected" != "$actual" || $exit_code -ne $expected_exit ]]; then
>&2 echo -e "Failed test for $K_RED$f$K_END. Exited with $exit_code, expected $expected_exit.";
>&2 echo "Expected:";
>&2 echo "$expected";
>&2 echo "Got:";
>&2 echo "$actual";
(( ++failed ));
fi;
(( ++ran ));
done;
if (( NO_MEM != 0 )); then
run_mem_tests $1;
fi;
}
run_cli_test () {
declare expected="$1";
shift;
declare torun="./yasl $@";
declare actual=$(./yasl "$@");
if [[ "$expected" != "$actual" ]]; then
>&2 echo -e "Failed test $K_RED$torun$K_END.";
>&2 echo "Expected:";
>&2 echo "$expected";
>&2 echo "Got:";
>&2 echo "$actual";
(( ++failed ));
fi;
(( ++ran ));
}
run_cli_tests () {
echo "Running CLI tests...";
run_cli_test 'YASL v0.13.6' '-V';
run_cli_test '10' '-e' "let x=10; x;";
run_cli_test '' '-E' 'let x = 10; x;';
run_cli_test '10' '-E' 'let x = 10; echo x;';
run_cli_test "$usage" '-h';
# run_cli_test $'A = 10\nB = 11\n[test/inputs/syntax/ifdef_simple.yasl, a, b, c]' '-DA=10' '-DB=11' '-Duse_args=true' 'test/inputs/syntax/ifdef_simple.yasl' 'a' 'b' 'c'
}
run_tests inputs 0;
run_tests errors/assert 10;
run_tests errors/stackoverflow 11;
run_tests errors/type 5;
run_tests errors/divisionbyzero 6;
run_tests errors/syntax 4;
run_tests errors/value 7;
run_cli_tests;
echo "Passed $(( ran - failed ))/$(( ran )) script tests. (Skipped $((skipped)).)";
exit $failed;