-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·130 lines (117 loc) · 2.68 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh
# Parse command line
COLOR=""
if test -t 1; then
COLOR="-v color=1"
fi
WATCH=""
VERBOSE=""
INFO=""
ALWAYS=""
RUNNER=""
TESTOPTS=""
while getopts "wivBCMx:o:V" o; do
case "$o" in
w) WATCH="1";;
B) ALWAYS="1";;
i) INFO="-v info=1";;
v) VERBOSE="-v verbose=1";;
C) COLOR="-v color=1";;
M) COLOR="";;
x) RUNNER="$OPTARG";;
o) TESTOPTS="$OPTARG";;
V) RUNNER="valgrind --log-file=%t.valgrind"
TESTOPTS="-n";
;;
\?) echo >&2 "Usage: $0 [-B] [-w] [-i] [-v] [-C] [-M] " \
"[-x <runner>] [-o <test options>] [pattern ...]";
exit 1;;
esac
done
shift $(expr $OPTIND - 1)
TEST_PATTERN="$@"
# Parse command line for test filters
PATTERNS=
if [ "$#" -ge 1 ]; then
for PAT in "$@"; do PATTERNS="$PATTERNS -e $PAT"; done
TESTS=$(./ms target:test/**/bin | grep $PATTERNS)
else
TESTS=$(./ms target:test/**/bin)
fi
parsetest() {
sed -unf taps/parse-tap.sed |
awk $INFO $VERBOSE $COLOR -f taps/print-results.awk
}
compile() {
COMPILE_TESTS=$(echo "$TESTS" | while read TEST; do
if ! ./ms -q "$TEST"; then
echo $TEST
fi
done)
if [ -n "$COMPILE_TESTS" ]; then
printf '% -39s ' "compile $TEST_PATTERN"
{
ID=1
echo "1..$(echo "$COMPILE_TESTS" | wc -l)"
echo "$COMPILE_TESTS" | while read TEST
do
BUILD_OUT=$TEST.build
mkdir -p $(dirname "$BUILD_OUT")
if ./ms "$TEST" >"$BUILD_OUT" 2>&1; then
echo "ok $ID $TEST"
else
echo "not ok $ID $TEST"
echo " $BUILD_OUT"
fi
ID=$(expr 1 + $ID)
done
} | parsetest
true
else
false
fi
}
clearfail() {
rm -f "$1.fail"
}
setfail() {
awk -f taps/print-failed.awk >"$1.fail" <"$1.out"
}
runtests() {
echo "$TESTS" | while read TEST
do
if [ -n "$ALWAYS" -o \
\( -e "$TEST.fail" -a "$TEST.fail" -ot "$TEST" \) -o \
! -e "$TEST.out" -o \
"$TEST.out" -ot "$TEST" ]
then
printf '% -39s ' "$TEST"
if [ -e "$TEST" ]
then
$(echo "$RUNNER" | sed "s;%t;$TEST;g") $TEST $TESTOPTS | tee "$TEST".out
else
echo 'Bail out! Test does not exist!'
fi | parsetest && clearfail "$TEST" || setfail "$TEST"
elif [ -e "$TEST.fail" ]; then
cat "$TEST.out" | parsetest
fi
done
}
compile
runtests
if [ -n "$WATCH" ]; then
inotifywait -mrq --timefmt '%a %H:%M' --format '%T %w %f' \
--exclude 'sw[op]|~$' \
-e modify,move,delete ./src/ |
while read day time dir file; do
case "$file" in
*.c | *.h)
if compile; then
runtests
echo
fi
;;
*) ;;
esac
done
fi