Update tapview.
This commit is contained in:
parent
96c869e5c9
commit
65cc1235ca
1 changed files with 86 additions and 82 deletions
168
bin/tapview
168
bin/tapview
|
|
@ -1,25 +1,24 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# tapview - a TAP (Test Anything Protocol) viewer in pure POSIX shell
|
# tapview - a TAP (Test Anything Protocol) viewer in pure POSIX shell
|
||||||
#
|
#
|
||||||
# SPDX-FileCopyrightText: Eric S. Raymond <esr@thyrsus.com>
|
|
||||||
# SPDX-License-Identifier: MIT-0
|
|
||||||
#
|
|
||||||
# This code is intended to be embedded in your project. The author
|
# This code is intended to be embedded in your project. The author
|
||||||
# grants permission for it to be distributed under the prevailing
|
# grants permission for it to be distributed under the prevailing
|
||||||
# license of your project if you choose, provided that license is
|
# license of your project if you choose, provided that license is
|
||||||
# OSD-compliant; otherwise the following SPDX tag incorporates the
|
# OSD-compliant; otherwise the following SPDX tag incorporates the
|
||||||
# MIT No Attribution license by reference.
|
# MIT No Attribution license by reference.
|
||||||
#
|
#
|
||||||
# A newer version may be available at https://gitlab.com/esr/tapview
|
# SPDX-FileCopyrightText: (C) Eric S. Raymond <esr@thyrsus.com>
|
||||||
# Check your last commit dqte for this file against the commit list
|
# SPDX-License-Identifier: MIT-0
|
||||||
# there to see if it might be a good idea to update.
|
|
||||||
#
|
#
|
||||||
|
# This version shipped on 2024-01-31. A newer version may be available
|
||||||
|
# at https://gitlab.com/esr/tapview; check the ship date oagainst the
|
||||||
|
# commit list there to see if it might be a good idea to update.
|
||||||
|
|
||||||
OK="."
|
OK="."
|
||||||
FAIL="F"
|
FAIL="F"
|
||||||
SKIP="s"
|
SKIP="s"
|
||||||
TODO_NOT_OK="x"
|
TODO_NOT_OK="x"
|
||||||
TODO_OK="u"
|
TODO_OK="u"
|
||||||
|
|
||||||
LF='
|
LF='
|
||||||
'
|
'
|
||||||
|
|
||||||
|
|
@ -49,7 +48,6 @@ skipcount=0
|
||||||
todocount=0
|
todocount=0
|
||||||
status=0
|
status=0
|
||||||
report=""
|
report=""
|
||||||
IFS=""
|
|
||||||
ln=0
|
ln=0
|
||||||
state=plaintext
|
state=plaintext
|
||||||
|
|
||||||
|
|
@ -80,24 +78,47 @@ context_pop () {
|
||||||
then
|
then
|
||||||
ship_line "Expected $(context_get expect) tests but only ${testcount} ran."
|
ship_line "Expected $(context_get expect) tests but only ${testcount} ran."
|
||||||
status=1
|
status=1
|
||||||
|
elif [ "$(context_get plan)" != "" ] && [ "$(context_get expect)" -lt "$(context_get count)" ]
|
||||||
|
then
|
||||||
|
ship_line "${testcount} ran but $(context_get expect) expected."
|
||||||
|
status=1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
directive () {
|
||||||
|
case "$1" in
|
||||||
|
*[[:space:]]#[[:space:]]*$2*) return 0;;
|
||||||
|
*) return 1;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
depth=0
|
depth=0
|
||||||
context_push
|
context_push
|
||||||
|
|
||||||
while read -r line
|
while read -r line
|
||||||
do
|
do
|
||||||
ln=$((ln + 1))
|
ln=$((ln + 1))
|
||||||
|
IFS=" "
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
set -- $line
|
||||||
|
tok1="$1"
|
||||||
|
tok2="$2"
|
||||||
|
tok3="$3"
|
||||||
|
IFS=""
|
||||||
|
# Ignore blank lines and comments
|
||||||
|
if [ -z "$tok1" ] || [ "$tok1" = '#' ]
|
||||||
|
then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
# Process bailout
|
# Process bailout
|
||||||
if expr "$line" : "Bail out!" >/dev/null
|
if [ "$tok1" = "Bail" ] && [ "$tok2" = "out!" ]
|
||||||
then
|
then
|
||||||
ship_line "$line"
|
ship_line "$line"
|
||||||
status=2
|
status=2
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
# Use the current indent to choose a scope level
|
# Use the current indent to choose a scope level
|
||||||
indent=$(expr "$line" : '[ ]*')
|
leading_spaces="${line%%[! ]*}"
|
||||||
|
indent=${#leading_spaces}
|
||||||
if [ "${indent}" -lt "${depth}" ]
|
if [ "${indent}" -lt "${depth}" ]
|
||||||
then
|
then
|
||||||
context_pop
|
context_pop
|
||||||
|
|
@ -107,35 +128,45 @@ do
|
||||||
depth="${indent}"
|
depth="${indent}"
|
||||||
context_push
|
context_push
|
||||||
fi
|
fi
|
||||||
# Process a plan line
|
# Process a plan line (outer case is because expr is expensive)
|
||||||
if expr "$line" : '[ ]*1\.\.[0-9][0-9]*' >/dev/null
|
case "$tok1" in
|
||||||
then
|
[0123456789]*)
|
||||||
if [ "$(context_get plan)" != "" ]
|
if expr "$line" : '[ ]*1\.\.[0-9][0-9]*' >/dev/null
|
||||||
then
|
then
|
||||||
ship_error "tapview: cannot have more than one plan line."
|
if [ "$(context_get plan)" != "" ]
|
||||||
fi
|
then
|
||||||
if expr "$line" : ".* *SKIP" >/dev/null || expr "$line" : ".* *skip" >/dev/null
|
ship_error "tapview: cannot have more than one plan line."
|
||||||
then
|
fi
|
||||||
ship_line "$line"
|
if directive "$line" [Ss][Kk][Ii][Pp]
|
||||||
echo "${report}"
|
then
|
||||||
exit 1 # Not specified in the standard whether this should exit 1 or 0
|
ship_line "$line"
|
||||||
fi
|
echo "${report}"
|
||||||
context_set plan "${line}"
|
exit 1 # Not specified in the standard whether this should exit 1 or 0
|
||||||
context_set expect "$(expr "$line" : '[ ]*1\.\.\([0-9][0-9]*\)')"
|
fi
|
||||||
continue
|
context_set plan "${line}"
|
||||||
elif expr "$line" : '[ ]*[0-9][0-9]*\.\.[0-9][0-9]*' >/dev/null
|
context_set expect "$(expr "$line" : '[ ]*1\.\.\([0-9][0-9]*\)')"
|
||||||
then
|
continue
|
||||||
echo "Ill-formed plan line at ${ln}"
|
elif expr "$line" : '[ ]*[0-9][0-9]*\.\.[0-9][0-9]*' >/dev/null
|
||||||
exit 1
|
then
|
||||||
fi
|
echo "Ill-formed plan line at ${ln}"
|
||||||
# Check for out-of-order test point numbers with the sequence (TAP 14)
|
exit 1
|
||||||
testpoint=$(expr "$line" : '.*ok *\([0-9][0-9]*\)')
|
fi
|
||||||
if [ "${testpoint}" != "" ] && [ "$(context_get expect)" != "" ] && [ "${testpoint}" -gt "$(context_get expect)" ]
|
;; esac
|
||||||
then
|
# Check for test point numbers out-of-order with the sequence (TAP 14)
|
||||||
ship_error "tapview: testpoint number ${testpoint} is out of range for plan $(context_get plan)."
|
testpoint=""
|
||||||
fi
|
case "$tok1" in
|
||||||
|
ok) testpoint="$tok2";;
|
||||||
|
not) testpoint="$tok3";;
|
||||||
|
esac
|
||||||
|
case "$testpoint" in
|
||||||
|
*[0123456789]*)
|
||||||
|
if [ "${testpoint}" != "" ] && [ "$(context_get expect)" != "" ] && [ "${testpoint}" -gt "$(context_get expect)" ]
|
||||||
|
then
|
||||||
|
ship_error "tapview: testpoint number ${testpoint} is out of range for plan $(context_get plan)."
|
||||||
|
fi
|
||||||
|
;; esac
|
||||||
# Process an ok line
|
# Process an ok line
|
||||||
if expr "$line" : "[ ]*ok" >/dev/null
|
if [ "$tok1" = "ok" ]
|
||||||
then
|
then
|
||||||
context_set count $(($(context_get count) + 1))
|
context_set count $(($(context_get count) + 1))
|
||||||
testcount=$((testcount + 1))
|
testcount=$((testcount + 1))
|
||||||
|
|
@ -145,24 +176,16 @@ do
|
||||||
else
|
else
|
||||||
context_set test_after_plan yes
|
context_set test_after_plan yes
|
||||||
fi
|
fi
|
||||||
if expr "$line" : "[^#]* # *TODO" >/dev/null || expr "$line" : "[^#]* # *todo" >/dev/null
|
if directive "$line" [Tt][Oo][Dd][Oo]
|
||||||
then
|
then
|
||||||
ship_char ${TODO_OK}
|
ship_char ${TODO_OK}
|
||||||
ship_line "$line"
|
ship_line "$line"
|
||||||
todocount=$((todocount + 1))
|
todocount=$((todocount + 1))
|
||||||
if expr "$line" : "[^#]*#[^ ]" >/dev/null
|
elif directive "$line" [Ss][Kk][Ii][Pp]
|
||||||
then
|
|
||||||
ship_line "Suspicious comment leader at ${ln}"
|
|
||||||
fi
|
|
||||||
elif expr "$line" : "[^#]* # *SKIP" >/dev/null || expr "$line" : "[^#]* # *skip" >/dev/null
|
|
||||||
then
|
then
|
||||||
ship_char ${SKIP}
|
ship_char ${SKIP}
|
||||||
ship_line "$line"
|
ship_line "$line"
|
||||||
skipcount=$((skipcount + 1))
|
skipcount=$((skipcount + 1))
|
||||||
if expr "$line" : "[^#]*#[^ ]" >/dev/null
|
|
||||||
then
|
|
||||||
ship_line "Suspicious comment leader at ${ln}"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
ship_char ${OK}
|
ship_char ${OK}
|
||||||
fi
|
fi
|
||||||
|
|
@ -170,7 +193,7 @@ do
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
# Process a not-ok line
|
# Process a not-ok line
|
||||||
if expr "$line" : "[ ]*not ok" >/dev/null
|
if [ "$tok1" = "not" ] && [ "$tok2" = "ok" ]
|
||||||
then
|
then
|
||||||
context_set count $(($(context_get count) + 1))
|
context_set count $(($(context_get count) + 1))
|
||||||
testcount=$((testcount + 1))
|
testcount=$((testcount + 1))
|
||||||
|
|
@ -180,26 +203,18 @@ do
|
||||||
else
|
else
|
||||||
context_set test_after_plan yes
|
context_set test_after_plan yes
|
||||||
fi
|
fi
|
||||||
if expr "$line" : "[^#]* # *SKIP" >/dev/null || expr "$line" : "[^#]* # *skip" >/dev/null
|
if directive "$line" [Ss][Kk][Ii][Pp]
|
||||||
then
|
then
|
||||||
ship_char "${SKIP}"
|
ship_char "${SKIP}"
|
||||||
state=plaintext
|
state=plaintext
|
||||||
skipcount=$((skipcount + 1))
|
skipcount=$((skipcount + 1))
|
||||||
if expr "$line" : "[^#]* #[^ ]" >/dev/null
|
|
||||||
then
|
|
||||||
ship_line "Suspicious comment leader at lime ${ln}"
|
|
||||||
fi
|
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
if expr "$line" : "[^#]* # *TODO" >/dev/null || expr "$line" : "[^#]* # *todo" >/dev/null
|
if directive "$line" [Tt][Oo][Dd][Oo]
|
||||||
then
|
then
|
||||||
ship_char ${TODO_NOT_OK}
|
ship_char ${TODO_NOT_OK}
|
||||||
state=plaintext
|
state=plaintext
|
||||||
todocount=$((todocount + 1))
|
todocount=$((todocount + 1))
|
||||||
if expr "$line" : "[^#]* #[^ ]" >/dev/null
|
|
||||||
then
|
|
||||||
ship_line "Suspicious comment leader at line ${ln}"
|
|
||||||
fi
|
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
ship_char "${FAIL}"
|
ship_char "${FAIL}"
|
||||||
|
|
@ -215,42 +230,34 @@ do
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
# Process a TAP 14 pragma
|
# Process a TAP 14 pragma
|
||||||
if expr "$line" : "pragma" >/dev/null
|
case "$line" in
|
||||||
then
|
pragma*)
|
||||||
unset IFS
|
case "$line" in
|
||||||
# shellcheck disable=SC2086
|
*+bail*) context_set bail yes;;
|
||||||
set -- $line
|
*-bail*) context_set bail yes;;
|
||||||
case "$2" in
|
*+strict*) context_set strict yes;;
|
||||||
+bail) context_set bail yes;;
|
*-strict*) context_set strict yes;;
|
||||||
-bail) context_set bail yes;;
|
|
||||||
+strict) context_set strict yes;;
|
|
||||||
-strict) context_set strict yes;;
|
|
||||||
*) ship_line "Pragma '$line' ignored";;
|
*) ship_line "Pragma '$line' ignored";;
|
||||||
esac
|
esac
|
||||||
IFS=""
|
|
||||||
continue
|
continue
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
# shellcheck disable=SC2166
|
# shellcheck disable=SC2166
|
||||||
if [ "${state}" = "yaml" ]
|
if [ "${state}" = "yaml" ]
|
||||||
then
|
then
|
||||||
ship_line "$line"
|
ship_line "$line"
|
||||||
if expr "$line" : '[ ]*\.\.\.' >/dev/null
|
if [ "$tok1" = "..." ]
|
||||||
then
|
then
|
||||||
state=plaintext
|
state=plaintext
|
||||||
else
|
else
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
elif expr "$line" : "[ ]*---" >/dev/null
|
elif [ "$tok1" = "---" ]
|
||||||
then
|
then
|
||||||
ship_line "$line"
|
ship_line "$line"
|
||||||
state=yaml
|
state=yaml
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
# Ignore blank lines and comments
|
|
||||||
if [ -z "$line" ] || expr "$line" : '[ ]+$' >/dev/null || expr "$line" : "#" >/dev/null
|
|
||||||
then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
# Any line that is not a valid plan, test result, pragma,
|
# Any line that is not a valid plan, test result, pragma,
|
||||||
# or comment lands here.
|
# or comment lands here.
|
||||||
if [ "$(context_get strict)" = yes ]
|
if [ "$(context_get strict)" = yes ]
|
||||||
|
|
@ -262,10 +269,8 @@ do
|
||||||
done
|
done
|
||||||
|
|
||||||
/bin/echo ""
|
/bin/echo ""
|
||||||
|
|
||||||
depth=0
|
depth=0
|
||||||
context_pop
|
context_pop
|
||||||
|
|
||||||
report="${report}${testcount} tests, ${failcount} failures"
|
report="${report}${testcount} tests, ${failcount} failures"
|
||||||
if [ "$todocount" != 0 ]
|
if [ "$todocount" != 0 ]
|
||||||
then
|
then
|
||||||
|
|
@ -277,7 +282,6 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${report}."
|
echo "${report}."
|
||||||
|
|
||||||
exit "${status}"
|
exit "${status}"
|
||||||
|
|
||||||
# end
|
# end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue