From: Stephan Beyer Date: Sun, 06 Jul 2008 20:22:31 GMT Subject: [HACK] t/test-lib.sh HACK: Add -s/--show-hack to test suite. Message-ID: <1215375751-30853-1-git-send-email-s-beyer@gmx.net> This option realizes a stupid hack that tries to run the test cases line by line (separated by &&). Furthermore it shows the line it is testing. With that information it is easier to find the reason why a test fails. This hack works as long as there are no multi-line for/while/subshell/... in the test cases. Note, that the -s option should only be used if a test case failed. It is slow and error-prone. Signed-off-by: Stephan Beyer --- Hi, I wrote that before I started to make the sequencer prototype and then I used this hack more than expected ;-) Today I cherry-picked this commit into another branch and then I thought this could be useful for others, too. (Explicitly not for inclusion!) So how to use it? When running a test case in t/, add the -s option and then it shows something like this: --snip--[...] ------- Testing: ! test -d "$SEQDIR" ------- Testing: session_ok * FAIL 3: "pick", "squash", "ref" from stdin next_session squashCE && valgrind git sequencer &3 2>&4 "$1" +test_run__ () { + eval "$1" eval_ret="$?" +} + +test_run_op_ () { + echo "Testing:" + printf "%s\n" "$op_" + echo + eval "$op_" + eval_ret="$?" +} + +test_run_hack_ () { + i_=1 + j_=1 + total_=$(printf '%s' "$1" | wc -l) + while test "$j_" -lt $(expr "$total_" + 1) + do + op_=$(printf '%s' "$1" | sed -n -e "$i_,$j_ p") + if test -n "$(printf '%s' "$op_" | sed -n -e '/<<[-\\ A-Za-z]/q;/&& *$/p;')" + then + i_=$(expr "$j_" + 1) + op_=$(printf '%s' "$op_" | sed -e 's/ *&& *$//') + test_run_op_ + test "$eval_ret" -ne 0 && return 0 + echo ------- + fi + j_=$(expr "$j_" + 1) + done + op_="$(printf '%s' "$1" | sed -n -e "$i_,$j_ p")" + test_run_op_ + return 0 +} + +test_run_ () { + if test -z "$show_hack" + then + test_run__ >&3 2>&4 "$1" + else + test_run_hack_ >&3 2>&4 "$1" + fi return 0 } -- 1.5.6.363.g7ba71