From: Stefano Lattarini Date: Sat, 6 Aug 2011 20:42:24 +0000 (+0200) Subject: testsuite: improve and refactor our custom TAP shell library X-Git-Tag: ng-0.5a~89^2~135 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f5dcfb065552773b4b0fe295647a9c16363d180;p=thirdparty%2Fautomake.git testsuite: improve and refactor our custom TAP shell library This change is mostly done in preparation for the next one. * tests/tap-functions.sh (result_with_directive_): Merge into ... (result_): ... this function, which has been greatly extended and improved in various ways. (ok_, not_ok_, skip_, xfail_, xpass_): Adjust. Adjust comments. Remove an extra empty line. * tests/instspc.tap: Use the new improved interface of `result_'. * tests/tap-bad-prog.tap: Likewise. --- diff --git a/ChangeLog b/ChangeLog index a87953cf0..f18162467 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2011-08-07 Stefano Lattarini + + testsuite: improve and refactor our custom TAP shell library + This change is mostly done in preparation for the next one. + * tests/tap-functions.sh (result_with_directive_): Merge into ... + (result_): ... this function, which has been greatly extended and + improved in various ways. + (ok_, not_ok_, skip_, xfail_, xpass_): Adjust. + Adjust comments. Remove an extra empty line. + * tests/instspc.tap: Use the new improved interface of `result_'. + * tests/tap-bad-prog.tap: Likewise. + 2011-08-07 Stefano Lattarini testsuite: update "user interface" description in tests/README diff --git a/tests/instspc.tap b/tests/instspc.tap index 4c8115158..f421fc793 100755 --- a/tests/instspc.tap +++ b/tests/instspc.tap @@ -257,11 +257,16 @@ for test_name in $test_names_list; do && DESTDIR="$dest" file="./$test_string" $MAKE -e test-inst \ || r='not ok' - tap_text="$test_name in ${where}dir" + description="$test_name in ${where}dir" if expected_to_fail "$where" "$test_name"; then - tap_text="$tap_text # TODO long-standing limitation" + directive=TODO + reason="long-standing limitation" + else + directive= + reason= fi - result_ "$r" "$tap_text" # Test case outcome is here. + # Test case outcome is here. + result_ "$r" -D "$directive" -r "$reason" -- "$description" cd "$ocwd" || fatal_ "cannot chdir back to test directory" diff --git a/tests/tap-bad-prog.tap b/tests/tap-bad-prog.tap index 0cc3a1124..086b38e34 100755 --- a/tests/tap-bad-prog.tap +++ b/tests/tap-bad-prog.tap @@ -82,6 +82,7 @@ then else r='not ok' fi -result_ "$r" 'no spurious results # TODO still get "missing plan"' +result_ "$r" --directive TODO --reason 'still get "missing plan"' \ + 'no spurious results' : diff --git a/tests/tap-functions.sh b/tests/tap-functions.sh index d87a32c00..b638e6f0e 100644 --- a/tests/tap-functions.sh +++ b/tests/tap-functions.sh @@ -83,29 +83,46 @@ warn_ () diag_ "WARNING:" ${1-"(unknown warning)"} ${1+"$@"} } -# result_ RESULT [DESCRIPTION...] -# ------------------------------- -# Report a test case with the given result. +# result_ RESULT [-D DIRECTIVE] [-r REASON] [--] [DESCRIPTION...] +# --------------------------------------------------------------- +# Report a test case with the given RESULT (valid values are "ok" and +# "not ok") and the given DESCRIPTION (if any). If DIRECTIVE is given +# and non-empty (valid values being "TODO" and "SKIP"), it will be +# reported too, with the REASON (if given) appended. result_ () { - incr_tap_count_ + set +x # Don't pollute the log files. + test $# -gt 0 || bailout_ "result_: missing argument" tap_result_=$1; shift - echo "$tap_result_" $tap_count_ ${1+"- $*"} -} - -# tap_with_directive_ RESULT DIRECTIVE [-r REASON] [DESCRIPTION...] -# ----------------------------------------------------------------- -# Write a tap result with the given directive (can be "TODO" or "SKIP"). -# The REASON, if given is appended after the directive. This function is -# for internal use only. -result_with_directive_ () -{ + case $tap_result_ in + "ok"|"not ok") ;; + *) bailout_ "result_: invalid result '$tap_result'" ;; + esac + tap_directive_= tap_reason_= + while test $# -gt 0; do + case $1 in + -D|--directive) tap_directive_=$2; shift;; + -r|--reason) tap_reason_=$2; shift;; + --) shift; break;; + -*) bailout_ "result_: invalid option '$1'";; + *) break;; + esac + shift + done + case $tap_directive_ in + ""|TODO|SKIP) ;; + *) bailout_ "result_: invalid directive '$directive_'" ;; + esac incr_tap_count_ - tap_result_=$1; shift - tap_directive_=$1; shift - case $1 in -r) tap_reason_=" $2" shift 2;; *) tap_reason_="";; esac - echo "$tap_result_" $tap_count_ ${1+"- $*"} \ - "# ${tap_directive_}${tap_reason_}" + tap_text_="$tap_result_ $tap_count_" + if test x"$*" != x; then + tap_text_="$tap_text_ - $*" + fi + if test x"$tap_directive_" != x; then + tap_text_="$tap_text_ # $tap_directive_"${tap_reason_:+" $tap_reason_"} + fi + printf '%s\n' "$tap_text_" + set -x # Restore shell xtraces. } # ok_ [DESCRIPTION...] @@ -113,7 +130,7 @@ result_with_directive_ () # Report a successful test. ok_ () { - result_ 'ok' ${1+"$@"} + result_ 'ok' -- ${1+"$@"} } # not_ok_ [DESCRIPTION...] @@ -121,20 +138,20 @@ ok_ () # Report a failed test. not_ok_ () { - result_ 'not ok' ${1+"$@"} + result_ 'not ok' -- ${1+"$@"} } -# skip_ [-r REASON] [DESCRIPTION...] -# ---------------------------------- +# skip_ [-r REASON] [--] [DESCRIPTION...] +# --------------------------------------- # Report a skipped test. If the `-r' option is present, its argument is # give as the reason of the skip. skip_ () { - result_with_directive_ 'ok' SKIP ${1+"$@"} + result_ 'ok' -D SKIP ${1+"$@"} } -# skip_row_ COUNT [-r REASON] [DESCRIPTION...] -# -------------------------------------------- +# skip_row_ COUNT [-r REASON] [--] [DESCRIPTION...] +# ------------------------------------------------- # Report a COUNT of skipped test, with the given reason and descriptions # (if any). Useful to avoid cascade failures in case a fair number of # tests depend on an earlier one that failed. @@ -150,7 +167,7 @@ skip_row_ () # argument is give as the reason why the failure is expected. xfail_ () { - result_with_directive_ 'not ok' TODO ${1+"$@"} + result_ 'not ok' -D TODO ${1+"$@"} } # xpass_ [-r REASON] [DESCRIPTION...] @@ -159,7 +176,7 @@ xfail_ () # argument is give as the reason why the failure is expected. xpass_ () { - result_with_directive_ 'ok' TODO ${1+"$@"} + result_ 'ok' -D TODO ${1+"$@"} } # skip_all_ [REASON ...] @@ -231,7 +248,6 @@ command_not_ok_ () fi } - # reset_test_count_ COUNT # ----------------------- # Reset the count of the TAP test results seen so far to COUNT.