-
Notifications
You must be signed in to change notification settings - Fork 55
/
tapview
executable file
·195 lines (184 loc) · 4.12 KB
/
tapview
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#! /bin/sh
# tapview - a TAP (Test Anything Protocol) viewer in pure POSIX shell
#
# Copyright by Eric S. Raymond
#
# This code is intended to be embedded in your project. The author
# grants permission for it to be distributed under the prevailing
# license of your project if you choose, provided that license is
# OSD-compliant; otherwise the following SPDX tag incorporates a
# license by reference.
#
# SPDX-License-Identifier: BSD-2-Clause
#
# This is version 1.1
# A newer version may be available at https://gitlab.com/esr/tapview
#
# POSIX allows but does not mandate that -n suppresses emission of a
# trailing newline in echo. Thus, some shell builtin echos don't do
# that. Cope gracefully.
# shellcheck disable=SC2039
if [ "$(echo -n "a"; echo "b")" = "ab" ]
then
ECHO="echo"
elif [ "$(/bin/echo -n "a"; /bin/echo "b")" = "ab" ]
then
ECHO="/bin/echo"
else
echo "tapview: bailing out, your echo lacks -n support."
exit 3
fi
OK="."
FAIL="F"
SKIP="s"
TODO_NOT_OK="x"
TODO_OK="u"
ship_char() {
# shellcheck disable=SC2039
"${ECHO}" -n "$1"
}
ship_line() {
report="${report}${1}\n"
}
testcount=0
failcount=0
skipcount=0
todocount=0
test_before_plan=no
test_after_plan=no
expect=""
status=0
report=""
IFS=""
state=start
while read -r line
do
if expr "$line" : "Bail out!" >/dev/null
then
ship_line "$line"
status=2
break
fi
# Process a plan line
if expr "$line" : '1\.\.[0-9][0-9]*' >/dev/null
then
if [ "$expect" != "" ]
then
if [ "${testcount}" -gt 0 ]
then
echo ""
fi
ship_line "tapview: cannot have more than one plan line."
echo "${report}"
exit 1
fi
if expr "$line" : ".* *SKIP" >/dev/null || expr "$line" : ".* *skip" >/dev/null
then
ship_line "$line"
echo "${report}"
exit 1 # Not specified in the standard whether this should exit 1 or 0
fi
expect=$(expr "$line" : '1\.\.\([0-9][0-9]*\)')
continue
fi
# Process an ok line
if expr "$line" : "ok" >/dev/null
then
testcount=$((testcount + 1))
if [ "$expect" = "" ]
then
test_before_plan=yes
else
test_after_plan=yes
fi
if expr "$line" : ".*# *TODO" >/dev/null || expr "$line" : ".*# *todo" >/dev/null
then
ship_char ${TODO_OK}
ship_line "$line"
todocount=$((todocount + 1))
elif expr "$line" : ".*# *SKIP" >/dev/null || expr "$line" : ".*# *skip" >/dev/null
then
ship_char ${SKIP}
ship_line "$line"
skipcount=$((skipcount + 1))
else
ship_char ${OK}
fi
state=ok
continue
fi
# Process a not-ok line
if expr "$line" : "not ok" >/dev/null
then
testcount=$((testcount + 1))
if [ "$expect" = "" ]
then
test_before_plan=yes
else
test_after_plan=yes
fi
if expr "$line" : ".*# *SKIP" >/dev/null || expr "$line" : ".*# *skip" >/dev/null
then
ship_char "${SKIP}"
state=ok
skipcount=$((skipcount + 1))
continue
fi
if expr "$line" : ".*# *TODO" >/dev/null || expr "$line" : ".*# *todo" >/dev/null
then
ship_char ${TODO_NOT_OK}
state=ok
todocount=$((todocount + 1))
continue
fi
ship_char "${FAIL}"
ship_line "$line"
state=not_ok
failcount=$((failcount + 1))
status=1
continue
fi
# shellcheck disable=SC2166
if [ "${state}" = "yaml" ]
then
ship_line "$line"
if expr "$line" : '[ ]*\.\.\.' >/dev/null
then
state=ok
fi
elif expr "$line" : "[ ]*---" >/dev/null
then
ship_line "$line"
state=yaml
fi
done
/bin/echo ""
if [ -z "$expect" ]
then
ship_line "Missing a plan."
status=1
elif [ "$test_before_plan" = "yes" ] && [ "$test_after_plan" = "yes" ]
then
ship_line "A plan line may only be placed before or after all tests."
status=1
elif [ "${expect}" -gt "${testcount}" ]
then
ship_line "Expected ${expect} tests but only ${testcount} ran."
status=1
elif [ "${expect}" -lt "${testcount}" ]
then
ship_line "Expected ${expect} tests but ${testcount} ran."
status=1
fi
report="${report}${testcount} tests, ${failcount} failures"
if [ "$todocount" != 0 ]
then
report="${report}, ${todocount} TODOs"
fi
if [ "$skipcount" != 0 ]
then
report="${report}, ${skipcount} SKIPs"
fi
echo "${report}."
exit "${status}"
# end