From 661dac0cfb22094850593d630136327b4de51ecc Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Fri, 13 Apr 2012 16:47:04 +0200 Subject: [PATCH 1/3] test-lib: Avoid eating leading whitespace in expected output. Currently, todo.sh produces no indented output, so this hasn't affected tests so far. I found this while testing one of my custom actions with the test-lib. By unsetting IFS, the read command won't strip off leading and trailing whitespace while parsing the test session definition. --- tests/test-lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-lib.sh b/tests/test-lib.sh index b3022dd..35f4a2a 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -582,7 +582,7 @@ test_todo_session () { cmd="" status=0 > expect - while read -r line + while IFS= read -r line do case $line in ">>> "*) From 35f9c4276cbcedbbcd5a7ffb6f4fbad4029f5f96 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Fri, 13 Apr 2012 16:54:40 +0200 Subject: [PATCH 2/3] test-lib: Allow expected output with empty lines. An empty line is used to delimit test commands in test_todo_session. (This wasn't properly reflected in the usage comment, fixed that, too.) This prevents us from testing commands that include empty lines. (Currently, there is no such output in todo.sh, but custom add-ons may have this.) Instead of forcing the test to filter out the empty lines, extend the syntax to allow empty lines in the expected output by escaping them with a single backslash. (When redirecting via <>> command # output1 # output2 +# # >>> command # === exit status -# output3 -# output4 +# output3 with empty line (must be escaped here) +# \ +# output5 # EOF test_todo_session () { test "$#" = 1 || @@ -606,6 +608,9 @@ test_todo_session () { > expect fi ;; + \\) + echo "" >> expect + ;; *) echo "$line" >> expect ;; From 6a3ddad78729af4386c4adc68ff69581e494349c Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Fri, 27 Apr 2012 21:58:07 +0200 Subject: [PATCH 3/3] FIX: test-lib: Print differences when test_expect_output fails. When the command-under-test fails with a non-zero exit code, neither the different exit code nor any output differences are printed. Also, there's a lot of duplication between test_expect_output and test_expect_code_and_output. So, let's fix both by delegating the first to the latter. --- tests/test-lib.sh | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/tests/test-lib.sh b/tests/test-lib.sh index cf197be..79d58f8 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -264,25 +264,7 @@ test_expect_success () { test_expect_output () { test "$#" = 2 || error "bug in the test script: not 2 parameters to test-expect-output" - if ! test_skip "$@" - then - say >&3 "expecting success and output: $2" - test_run_ "$2" - if [ "$?" = 0 -a "$eval_ret" = 0 ] - then - cmp_output=$(test_cmp expect output) - if [ "$?" = 0 ] - then - test_ok_ "$1" - else - test_failure_ "$@" " -$cmp_output" - fi - else - test_failure_ "$@" - fi - fi - echo >&3 "" + test_expect_code_and_output 0 "$@" } test_expect_code_and_output () { @@ -290,7 +272,11 @@ test_expect_code_and_output () { error "bug in the test script: not 3 parameters to test-expect-code-and-output" if ! test_skip "$@" then - say >&3 "expecting exit code $1 and output: $3" + if [ "$1" = 0 ]; then + say >&3 "expecting success and output: $3" + else + say >&3 "expecting exit code $1 and output: $3" + fi test_run_ "$3" if [ "$?" = 0 -a "$eval_ret" = "$1" ] then