807147a4ae87 — Eric S. Raymond 3 years ago
TAPify the test suite.
5 files changed, 48 insertions(+), 8 deletions(-)

M .gitignore
M test/Makefile
A => test/tapdiffer
M test/test01.chk
M test/test01.log
M .gitignore +1 -0
@@ 1,6 1,7 @@ 
 index.html
 sst.pyc
 sst.html
+sst-doc.html
 sst.6
 doc/sst.doc
 doc/sst-doc.txt

          
M test/Makefile +14 -6
@@ 2,11 2,20 @@ 
 
 PYTHON=python
 
+TAPFILTER=cat
+ifeq (,$(command -v tapview))
+	TAPFILTER=tapview
+else
+	ifeq (,$(command -v tappy))
+		TAPFILTER=tappy
+	endif
+endif
+
 all:
 	@echo "With Python 2:"
-	@$(MAKE) -e PYTHON=python2 regress
+	@$(MAKE) -e PYTHON=python2 regress | $(TAPFILTER)
 	@echo "With Python 3:"
-	@$(MAKE) -e PYTHON=python3 regress
+	@$(MAKE) -e PYTHON=python3 regress | $(TAPFILTER)
 	@echo "No diff output is good news."
 
 .SUFFIXES: .log .chk

          
@@ 24,14 33,13 @@ buildregress:
 	    fi \
 	done
 regress:
+	echo "1..$$(ls *.log | wc -l)"
 	@for test in $(TESTLOADS); \
 	do \
 	    if [ ! -f $${test}.tst ] ; \
 	    then \
-		(if echo -n "$${test}: " >&2; grep 'Test' $${test}.log >&2;\
-		$(PYTHON) ../sst.py -r $${test}.log >/tmp/regress 2>&1; \
-		then diff -u $${test}.chk /tmp/regress; \
-		else echo "*** Nonzero return status on $${test}!"; exit 1; fi;) \
+		legend=$$(sed -n -e '/# Test/s//Test/p' <$${test}.log); \
+		../sst.py -r "$${test}.log" | ./tapdiffer "$${legend}" "$${test}.chk"; \
 	    fi \
 	done
 	@rm -f /tmp/regress

          
A => test/tapdiffer +31 -0
@@ 0,0 1,31 @@ 
+#! /bin/sh
+#
+# tapdiffer - Render diff between input and checkfile as a TAP report
+#
+# Usage: tapdiffer LEGEND CHECKFILE
+#
+# Output is a TAP report, ok if the diff is empty and not ok otherwisw.
+# A nonempty diff is shipped as a TAP YAML block following "not ok" 
+# unless QUIET=1 in the environment.
+#
+legend=$1
+checkfile=$2
+
+trap 'rm /tmp/tapdiff$$' EXIT HUP INT QUIT TERM
+
+if diff --text -u ${checkfile} - >/tmp/tapdiff$$
+then
+	echo "ok - ${legend}"
+	exit 0
+else
+	echo "not ok - ${checkfile}: ${legend}"
+	if [ ! "${QUIET}" = 1 ]
+	then
+		echo "  --- |"
+		sed </tmp/tapdiff$$ -e 's/^/  /'
+		echo "  ..."
+	fi
+	exit 1
+fi
+
+# end

          
M test/test01.chk +1 -1
@@ 3,7 3,7 @@ 
 -SUPER- STAR TREK
 
 Would you like a regular, tournament, or saved game? # SST2K version 2.4
-# Test bringng game up, viewng galaxy, quitting
+# Test bringing game up, viewing galaxy, quitting
 # recorded by esr@snark on Wed Apr 24 01:46:01 2019
 #seed(1556084761)
 r

          
M test/test01.log +1 -1
@@ 1,7 1,7 @@ 
 # seed 1556084761
 # options 
 # SST2K version 2.4
-# Test bringng game up, viewng galaxy, quitting
+# Test bringing game up, viewing galaxy, quitting
 # recorded by esr@snark on Wed Apr 24 01:46:01 2019
 #seed(1556084761)
 r