diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-09-07 00:16:44 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-09-07 16:30:34 +0200 |
commit | 93f25fb15faf7dce6d59954665dcb6d594255b12 (patch) | |
tree | c20260254322f3d59d56ee12d54ad4bfce6c02bf /run_tests.sh | |
parent | 916a05516b05bd2c9fd42c730f9a859be9226716 (diff) |
tests: introduce testcases
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'run_tests.sh')
-rwxr-xr-x | run_tests.sh | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 0000000..c5a36ad --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash + +line='........................................' + +extract_section() { + local file=$1 + local tag=$2 + + sed -ne '/^-- '"$tag"' --$/ { :n; n; /^-- End --$/b; p; b n }' "$file" +} + +run_test() { + local file=$1 + local name=${file##*/} + local res + + printf "%s %s " "$name" "${line:${#name}}" + + extract_section "$file" "Expect stdout" >"/tmp/$$.expout" + extract_section "$file" "Expect stderr" >"/tmp/$$.experr" + extract_section "$file" "Testcase" >"/tmp/$$.in" + + ./utpl -i "/tmp/$$.in" >"/tmp/$$.out" 2>"/tmp/$$.err" + + local rc=$? + + if ! cmp -s "/tmp/$$.err" "/tmp/$$.experr"; then + printf "FAILED:\n" + diff -u --color=always --label="Expected stderr" --label="Resulting stderr" "/tmp/$$.experr" "/tmp/$$.err" + printf -- "---\n" + res=1 + elif ! cmp -s "/tmp/$$.out" "/tmp/$$.expout"; then + printf "FAILED:\n" + diff -u --color=always --label="Expected stdout" --label="Resulting stdout" "/tmp/$$.expout" "/tmp/$$.out" + printf -- "---\n" + res=1 + #elif [ "$rc" != 0 ]; then + # local err="$(cat "/tmp/$$.err")" + # printf "FAILED:\n" + # printf "Terminated with exit code %d:\n%s\n---\n" $rc "${err:-(no error output)}" + # res=1 + else + printf "OK\n" + res=0 + fi + + rm -f "/tmp/$$.in" "/tmp/$$.out" "/tmp/$$.err" "/tmp/$$.expout" "/tmp/$$.experr" + + return $res +} + + +n_tests=0 +n_fails=0 + +for catdir in tests/[0-9][0-9]_*; do + [ -d "$catdir" ] || continue + + printf "\n##\n## Running %s tests\n##\n\n" "${catdir##*/[0-9][0-9]_}" + + for testfile in "$catdir/"[0-9][0-9]_*; do + [ -f "$testfile" ] || continue + + n_tests=$((n_tests + 1)) + run_test "$testfile" || n_fails=$((n_fails + 1)) + done +done + +printf "\nRan %d tests, %d okay, %d failures\n" $n_tests $((n_tests - n_fails)) $n_fails |