2 # tapview - a TAP (Test Anything Protocol) viewer in pure POSIX shell
4 # Copyright by Eric S. Raymond
6 # This code is intended to be embedded in your project. The author
7 # grants permission for it to be distributed under the prevailing
8 # license of your project if you choose, provided that license is
9 # OSD-compliant; otherwise the following SPDX tag applies.
11 # SPDX-License-Identifier: BSD-2-Clause
14 # A newer version may be available at https://gitlab.com/esr/tapview
16 # POSIX allows but does not mandate that -n suppresses emission of a
17 # trailing newline in echo. Thus, some shell builtin echos don't do
18 # that. Cope gracefully.
19 # shellcheck disable=SC2039
20 if [ "$(echo -n "a"; echo "b")" != "ab" ]
23 elif [ "$(/bin/echo -n "a"; /bin/echo "b")" = "ab" ]
27 echo "tapview: bailing out, your echo lacks -n support."
38 # shellcheck disable=SC2039
43 report="${report}${1}\n"
60 if expr "$line" : "Bail out!" >/dev/null
66 if expr "$line" : '1\.\.[0-9][0-9]*' >/dev/null >/dev/null
68 if [ "$expect" != "" ]
70 if [ "${testcount}" -gt 0 ]
74 ship_line "Cannot have more than one plan line."
78 if expr "$line" : ".* *SKIP" >/dev/null || expr "$line" : ".* *skip" >/dev/null
82 exit 1 # Not specified in the standard whether this should exit 1 or 0
84 expect=$(expr "$line" : '1\.\.\([0-9][0-9]*\)')
87 if expr "$line" : "ok" >/dev/null
89 testcount=$((testcount + 1))
96 if expr "$line" : ".*# *TODO" >/dev/null || expr "$line" : ".*# *todo" >/dev/null
100 todocount=$((todocount + 1))
101 elif expr "$line" : ".*# *SKIP" >/dev/null || expr "$line" : ".*# *skip" >/dev/null
105 skipcount=$((skipcount + 1))
112 if expr "$line" : "not ok" >/dev/null
114 testcount=$((testcount + 1))
115 if [ "$expect" = "" ]
121 if expr "$line" : ".*# *SKIP" >/dev/null || expr "$line" : ".*# *skip" >/dev/null
125 skipcount=$((skipcount + 1))
128 if expr "$line" : ".*# *TODO" >/dev/null || expr "$line" : ".*# *todo" >/dev/null
130 ship_char ${TODO_NOT_OK}
132 todocount=$((todocount + 1))
138 failcount=$((failcount + 1))
142 # shellcheck disable=SC2166
143 if [ "${state}" = "yaml" ]
146 if expr "$line" : '[ ]*\.\.\.' >/dev/null
150 elif expr "$line" : "[ ]*---" >/dev/null
161 ship_line "Missing a plan."
163 elif [ "$test_before_plan" = "yes" ] && [ "$test_after_plan" = "yes" ]
165 ship_line "A plan line may only be placed before or after all tests."
167 elif [ "${expect}" -gt "${testcount}" ]
169 ship_line "Expected ${expect} tests but only ${testcount} ran."
171 elif [ "${expect}" -lt "${testcount}" ]
173 ship_line "Expected ${expect} tests but ${testcount} ran."
177 report="${report}${testcount} tests, ${failcount} failures"
178 if [ "$todocount" != 0 ]
180 report="${report}, ${todocount} TODOs"
182 if [ "$skipcount" != 0 ]
184 report="${report}, ${skipcount} SKIPs"