From: Junio C Hamano Date: Wed, 25 Jun 2008 20:18:46 +0000 (-0700) Subject: Merge branch 'lw/perlish' X-Git-Tag: v1.6.0-rc0~212 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/14f0e48db7e1b0c5ec1b831f47214b972b4582d4?ds=inline;hp=-c Merge branch 'lw/perlish' * lw/perlish: Git.pm: add test suite t/test-lib.sh: add test_external and test_external_without_stderr --- 14f0e48db7e1b0c5ec1b831f47214b972b4582d4 diff --combined t/test-lib.sh index e331cadcff,4be466edb7..f4f35ed433 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@@ -80,8 -80,6 +80,8 @@@ d debug=t; shift ;; -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate) immediate=t; shift ;; + -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests) + export GIT_TEST_LONG=t; shift ;; -h|--h|--he|--hel|--help) help=t; shift ;; -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) @@@ -304,6 -302,64 +304,64 @@@ test_expect_code () echo >&3 "" } + # test_external runs external test scripts that provide continuous + # test output about their progress, and succeeds/fails on + # zero/non-zero exit code. It outputs the test output on stdout even + # in non-verbose mode, and announces the external script with "* run + # : ..." before running it. When providing relative paths, keep in + # mind that all scripts run in "trash directory". + # Usage: test_external description command arguments... + # Example: test_external 'Perl API' perl ../path/to/test.pl + test_external () { + test "$#" -eq 3 || + error >&5 "bug in the test script: not 3 parameters to test_external" + descr="$1" + shift + if ! test_skip "$descr" "$@" + then + # Announce the script to reduce confusion about the + # test output that follows. + say_color "" " run $(expr "$test_count" + 1): $descr ($*)" + # Run command; redirect its stderr to &4 as in + # test_run_, but keep its stdout on our stdout even in + # non-verbose mode. + "$@" 2>&4 + if [ "$?" = 0 ] + then + test_ok_ "$descr" + else + test_failure_ "$descr" "$@" + fi + fi + } + + # Like test_external, but in addition tests that the command generated + # no output on stderr. + test_external_without_stderr () { + # The temporary file has no (and must have no) security + # implications. + tmp="$TMPDIR"; if [ -z "$tmp" ]; then tmp=/tmp; fi + stderr="$tmp/git-external-stderr.$$.tmp" + test_external "$@" 4> "$stderr" + [ -f "$stderr" ] || error "Internal error: $stderr disappeared." + descr="no stderr: $1" + shift + say >&3 "expecting no stderr from previous command" + if [ ! -s "$stderr" ]; then + rm "$stderr" + test_ok_ "$descr" + else + if [ "$verbose" = t ]; then + output=`echo; echo Stderr is:; cat "$stderr"` + else + output= + fi + # rm first in case test_failure exits. + rm "$stderr" + test_failure_ "$descr" "$@" "$output" + fi + } + # This is not among top-level (test_expect_success | test_expect_failure) # but is a prefix that can be used in the test script, like: #