commit bcbeda04ca5558cceaa58058ce4b4c4b3660c708 from: Sven M. Hallberg date: Sat Jul 5 20:55:06 2025 UTC add adapter for the test.h ("tst") protocol commit - 6ae7a56e0f08ffd6e04a5312789e91ddb3059fc9 commit + bcbeda04ca5558cceaa58058ce4b4c4b3660c708 blob - /dev/null blob + 62bfc4b3c8a7702c53c285c2a13a4d3c7f30b69c (mode 755) --- /dev/null +++ tests/support/adapt-tst.t @@ -0,0 +1,28 @@ +#!/bin/sh + +tmp=$0.tmp.tst +trap "rm -f $tmp" EXIT +cat >$tmp <<-"EOF" + #!/bin/sh + if [ -n "$D" ] + then + echo "test_1()" + echo "test_2()" + echo "test_3()" + else + echo "test_1() OK" + echo "test_2() OK" + echo "something something unexpected" >&2 + echo "test_3() FAIL" + exit 1 + fi +EOF +chmod +x $tmp + +tst=$0.tests ./assert-exercise $0 \ + "run 3 ok 2 fail 1 error 0\n" \ + "something something unexpected\ntest_3()\tFAIL\n" \ + <<-EOF + #!/bin/sh + exec ../../support/adapt-tst $tmp + EOF blob - /dev/null blob + a233dc1ec26e6a1e06280008ce4935e1ccf48ffa (mode 755) --- /dev/null +++ support/adapt-tst @@ -0,0 +1,48 @@ +#!/bin/sh +# +# This script adapts a test suite that exposes the simple report protocol of +# test.h for use with exercise. +# +# Usage: adapt-tst cmd [arg ...] +# +# Example: Given a test suite in 'foo.tst.c' that is built into an executable +# 'foo.tst', create the script 'foo.tests' containing the following: +# +# #!/bin/sh +# exec ./adapt-tst ./foo.tst +# + +cmd="$1" +shift + +tmp=/tmp/adapt-tst.$$ +trap "rm -f $tmp" EXIT + +# initialize the counters +run=0 ok=0 fail=0 error=0 + +# clear the flag variables for the test executable +unset D V K X + +# determine the total number of tests by performing a dry run +D=1 "$cmd" "$@" >$tmp || exit 127 +run=$(echo $(wc -l <$tmp)) + +# perform the tests, counting and reporting results +echo "run $run ok $ok fail $fail error $error" +"$cmd" "$@" >$tmp +IFS=' ' +while read name result +do + case "$result" in + OK) ok=$((ok + 1)) ;; + FAIL) fail=$((fail + 1)) + echo "$name $result" >&2 ;; + *) error=$((error + 1)) ;; + esac + + echo "run $run ok $ok fail $fail error $error" +done <$tmp + +# exit 0 if and only if the counters indicate a perfect run +[ $ok -eq $run -a $fail -eq 0 -a $error -eq 0 ]