From a6d6730e74ead27e8a2e634445c34d1e9160341c Mon Sep 17 00:00:00 2001 From: Thomas Levine <_@thomaslevine.com> Date: Wed, 27 Jan 2016 00:32:51 +0000 Subject: [PATCH] start writing non-tap cases --- urchin | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/urchin b/urchin index e13e011..56d5846 100755 --- a/urchin +++ b/urchin @@ -70,21 +70,25 @@ recurse() { [ -f teardown ] && [ -x teardown ] && ./teardown >> "$stdout_file" - indent $indent_level - if [ $exit_code -eq 0 ] - then - # On success, print a green '✓' - printf '\033[32m✓ \033[0m' - printf '%s\n' "${potential_test}" - printf '%s\n' "${potential_test} passed" >> "$logfile" + if $tap_format; then + sleep 0s else - # On fail, print a red '✗' - printf '\033[31m✗ \033[0m' - printf '%s\n' "${potential_test}" - printf '%s\n' "${potential_test} failed" >> "$logfile" - printf '\033[31m' # Print output captured from failed test in red. - cat "$stdout_file" - printf '\033[0m' + indent $indent_level + if [ $exit_code -eq 0 ] + then + # On success, print a green '✓' + printf '\033[32m✓ \033[0m' + printf '%s\n' "${potential_test}" + printf '%s\n' "${potential_test} passed" >> "$logfile" + else + # On fail, print a red '✗' + printf '\033[31m✗ \033[0m' + printf '%s\n' "${potential_test}" + printf '%s\n' "${potential_test} failed" >> "$logfile" + printf '\033[31m' # Print output captured from failed test in red. + cat "$stdout_file" + printf '\033[0m' + fi fi fi [ $indent_level -eq 0 ] && rm "$stdout_file" @@ -107,6 +111,7 @@ $USAGE have shebang line "#!/bin/sh" with the specified shell. -f Force running even if the test directory's name does not contain the word "test". +-t Format output in Test Anything Protocol (TAP) -h This help. Go to https://github.com/tlevine/urchin for documentation on writing tests. @@ -147,12 +152,16 @@ urchin_go() { finish=$(date +%s) elapsed=$(($finish - $start)) - echo "Done, took $elapsed $(plural second $elapsed)." - set -- $(grep -e 'passed$' "$logfile"|wc -l) $(grep -e 'failed$' "$logfile"|wc -l) - printf '%s\n' "$1 $(plural test "$1") passed." - [ $2 -gt 0 ] && printf '\033[31m' || printf '\033[32m' # If tests failed, print the message in red, otherwise in green. - printf '%s\n' "$2 $(plural test "$2") failed." - printf '\033[m' + if $tap_format; then + sleep 0s + else + echo "Done, took $elapsed $(plural second $elapsed)." + set -- $(grep -e 'passed$' "$logfile"|wc -l) $(grep -e 'failed$' "$logfile"|wc -l) + printf '%s\n' "$1 $(plural test "$1") passed." + [ $2 -gt 0 ] && printf '\033[31m' || printf '\033[32m' # If tests failed, print the message in red, otherwise in green. + printf '%s\n' "$2 $(plural test "$2") failed." + printf '\033[m' + fi return "$2" } @@ -170,6 +179,7 @@ urchin_molly_guard() { shell_for_sh_tests= force=false +tap_format=false while [ $# -gt 0 ] do case "$1" in @@ -179,6 +189,7 @@ do shell_for_sh_tests=$1 which "$shell_for_sh_tests" >/dev/null || { echo "Cannot find specified shell: '$shell_for_sh_tests'" >&2; urchin_help >&2; exit 2; } ;; + -t) tap_format=true;; -h|--help) urchin_help exit 0;; -*) urchin_help >&2