-
Notifications
You must be signed in to change notification settings - Fork 3
/
run-tests.sh
executable file
·97 lines (78 loc) · 1.36 KB
/
run-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
#!/bin/bash
RED="$(tput bold)$(tput setab 1)"
GREEN="$(tput bold)$(tput setab 2)$(tput setaf 0)"
RESET="$(tput sgr0)"
PARSER="solc"
PASSES=0
FAILS=0
die () {
>&2 echo "error: $1"
exit 1
}
pass () {
echo "$GREEN PASS $RESET $1"
PASSES=$((PASSES + 1))
}
fail () {
echo "$RED FAIL $RESET $1"
FAILS=$((FAILS + 1))
}
assert_pass () {
$PARSER "$1" > "output/$1" 2>&1
if [ $? -eq 0 ]; then
pass "$1"
else
fail "$1"
fi
}
assert_fail () {
$PARSER "$1" > "output/$1" 2>&1
if [ $? -ne 0 ]; then
pass "$1"
else
fail "$1"
fi
}
filter_file () {
if [ -z "$FILTER" ]; then
return 0
fi
[[ "$1" == $FILTER ]]
}
test_init () {
if [ ! -f "$PARSER" ]; then
die "could not find parser: $PARSER"
fi
mkdir -p output/{passes,fails}
}
test_execute () {
for test in passes/*.sol; do
if filter_file "$test"; then
assert_pass "$test"
fi
done
for test in fails/*.sol; do
if filter_file "$test"; then
assert_fail "$test"
fi
done
}
test_finalize () {
printf "\n%s tests passed, %s tests failed.\n" "$PASSES" "$FAILS"
}
usage () {
echo "usage: ./run_tests.sh [-p <parser>] [-f <glob>]"
exit
}
while getopts f:p:h opt; do
case $opt in
p) PARSER=$OPTARG;;
f) FILTER=$OPTARG;;
h) usage;;
\?) exit 64;;
esac
done
test_init
test_execute
test_finalize
[ $FAILS -gt 0 ] && exit 1 || exit 0