forked from fram-lang/dbl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·109 lines (90 loc) · 1.82 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
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
#!/bin/bash
if ! [ -n "$1" ] || ! [ -n "$2" ]; then
echo "USAGE: ./test.sh PROGRAM TEST_SUITE"
exit 1
fi
if ! dune build; then
exit 1
fi
export DBL_LIB="lib/"
TIMEOUT=1.0
binary="_build/default/src/$1.exe"
flags=""
RED='\033[0;31m'
NC='\033[0m'
total_tests=0
passed_tests=0
function start_test {
total_tests=$(($total_tests + 1))
}
function pass_test {
passed_tests=$(($passed_tests + 1))
}
function print_status {
echo "stdout: >>>>>"
cat $1
echo "<<<<<"
echo "stderr: >>>>>"
cat $2
echo "<<<<<"
echo "exit_code: $3"
}
function check_output {
IFS=$'\n'
for exp in $(cat $2 | grep "^// @$1:" | sed "s/^\/\/ @$1://"); do
if ! grep $exp $3 > /dev/null; then
echo -e "${RED}$1 does not contain phrase: $exp${NC}"
unset IFS
return 1
fi
done
unset IFS
return 0
}
function run_test {
start_test
local tmp_stdout=$(mktemp)
local tmp_stderr=$(mktemp)
echo "$1"
timeout $TIMEOUT $1 >$tmp_stdout 2>$tmp_stderr
local status=$?
if $2 $status $tmp_stdout $tmp_stderr; then
if check_output "stderr" $4 $tmp_stderr && check_output "stdout" $4 $tmp_stdout; then
pass_test
else
print_status $tmp_stdout $tmp_stderr $status
fi
else
echo -e "${RED}$3${NC}"
print_status $tmp_stdout $tmp_stderr $status
fi
rm $tmp_stdout
rm $tmp_stderr
}
function check_simple_test {
[ $1 -eq 0 ]
}
function simple_test {
local cmd="$binary $flags $1"
local err="Command ${cmd} failed."
run_test "$cmd" check_simple_test "$err" $1
}
function check_exit_code_test {
[ $2 -eq $1 ]
}
function exit_code_test {
local cmd="$binary $flags $2"
local err="Command ${cmd} does not exited with code $1."
run_test "$cmd" "check_exit_code_test $1" "$err" $2
}
function run_with_flags {
flags=$2
$1
}
source "$2"
echo "Passed: ${passed_tests}/${total_tests}"
if [ $passed_tests -eq $total_tests ]; then
exit 0
else
exit 1
fi