-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·78 lines (67 loc) · 1.18 KB
/
test.sh
File metadata and controls
executable file
·78 lines (67 loc) · 1.18 KB
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
#!/bin/bash
COVERAGE=false
GP="./greenpass.py"
DEBUG="${1:-false}"
OUT=/dev/null
if test "x$DEBUG" = "xtrue"; then
OUT=/dev/stdout
fi
if test "x$DEBUG" = "xcoverage"; then
COVERAGE=true
GP="tools/coverage.sh"
OUT=/dev/stdout
python3-coverage erase
fi
export OUT
export GP
shift
set -eu
assert_false() {
echo "Asserting $@ == false" >"$OUT"
set +e
$@ >"$OUT" 2>"$OUT"
R="$?"
set -e
echo "Returned $R" >"$OUT"
test "$R" != 0
}
export -f assert_false
assert_true() {
echo "Asserting $@ == true" >"$OUT"
$@ >"$OUT" 2>"$OUT"
R="$?"
echo "Returned $R" >"$OUT"
return "$R"
}
export -f assert_true
assert_string_out() {
S="$1"
shift
echo "Asserting '$S' in $@" >"$OUT"
$@ 2>"$OUT" | grep "$S" >"$OUT"
}
export -f assert_string_out
assert_file_exists() {
echo "Asserting $1 file exists" >"$OUT"
ls "$1" >"$OUT" 2>"$OUT"
}
export -f assert_file_exists
error_exit() {
echo "[x] Test $1 Failed!"
exit 1
}
echo "Running testsuite"
if test $# -gt 0; then
TESTS=( $@ )
else
echo "Executing all tests"
TESTS=( $(ls -1 tests/test*) )
fi
for t in ${TESTS[@]}; do
echo "Executing $t"
"$t" || error_exit "$t"
done
echo "All tests passed"
if "$COVERAGE"; then
python3-coverage xml
fi