-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·74 lines (65 loc) · 1.58 KB
/
test
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
#!/bin/sh
#
# Executes the given tests.
#
# Glob patterns are matched against the tests in `tests/`.
#
# Execute without arguments to run all tests or list specific tests.
#
# Returns the number of failed tests.
#
set -e
dir="${0%${0##*/}}"
dir="${dir%/}"
cd "${dir:-.}/tests" || return 1
# Match all tests when no arguments are given
if [ $# -eq 0 ]; then
set -- *
fi
fails=0
for test in $@; do
# Remove folder component
test="${test##*/}"
# Skip hidden files, `.` and `..`
if [ -z "${test##.*}" ]; then
echo "${test} failed: skipping"
fails=$((fails + 1))
continue
fi
# Need to exist
if [ ! -e "$test" ]; then
echo "${test} failed: missing"
fails=$((fails + 1))
continue
fi
# Need read access
if [ ! -r "$test" ]; then
echo "${test} failed: cannot access"
fails=$((fails + 1))
continue
fi
# Inject bsda:test and add `|| bsda:test:err $LINENO` to every line
# The true call is to ensure that bash has called a non-builtin
# function, before executing a test, because that causes it
# to initialise some variables, which is undesirable to happen
# during the test run.
code="/usr/bin/true;bsda_dir='../src';readonly bsda_dir;. ../src/bsda_test.sh;$(
awk -f../src/testify.awk "$test")" || return 1
for shell in sh bash; do
which $shell >&- || continue
echo "${test} running: ${shell} ${test}"
if $shell -c "$code"; then
if [ -t 1 ]; then
tput up
fi
echo "${test} passed: ${shell} ${test}"
else
echo "${test} failed: ${shell} ${test}"
fails=$((fails + 1))
fi
done
done
if [ $fails -ne 0 ]; then
echo "Test runs failed: $fails"
fi
exit $fails