From 16034fbe59e88ec9592f73523cde97714d7c727c Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 31 Aug 2010 11:56:36 -0400 Subject: [PATCH 1/4] tests: make test_must_fail more verbose Because test_must_fail fails when a command succeeds, the command frequently does not produce any output (since, after all, it thought it was succeeding). So let's have test_must_fail itself report that a problem occurred. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/test-lib.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/t/test-lib.sh b/t/test-lib.sh index 3a3d4c4723..285bfd8943 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -591,7 +591,15 @@ test_path_is_missing () { test_must_fail () { "$@" - test $? -gt 0 -a $? -le 129 -o $? -gt 192 + exit_code=$? + if test $exit_code = 0; then + echo >&2 "test_must_fail: command succeeded: $*" + return 1 + elif test $exit_code -gt 129 -a $exit_code -le 192; then + echo >&2 "test_must_fail: died by signal: $*" + return 1 + fi + return 0 } # Similar to test_must_fail, but tolerates success, too. This is From a54ce3ca9e780f824f07519a6db83fe2d7575734 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 31 Aug 2010 11:56:53 -0400 Subject: [PATCH 2/4] tests: make test_must_fail fail on missing commands The point of it is to run a command that produces failure. A missing command is more likely an error in the test script (e.g., using 'test_must_fail "command with arguments"', or relying on a missing command). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/test-lib.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/t/test-lib.sh b/t/test-lib.sh index 285bfd8943..dbb13af33e 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -598,6 +598,9 @@ test_must_fail () { elif test $exit_code -gt 129 -a $exit_code -le 192; then echo >&2 "test_must_fail: died by signal: $*" return 1 + elif test $exit_code = 127; then + echo >&2 "test_must_fail: command not found: $*" + return 1 fi return 0 } From 5c8e141414058430155ea179bce38ceb8d750c5d Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 31 Aug 2010 12:10:55 -0500 Subject: [PATCH 3/4] tests: make test_might_fail more verbose Let test_might_fail say something about its failures for consistency with test_must_fail. Cc: Jeff King Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/test-lib.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/t/test-lib.sh b/t/test-lib.sh index dbb13af33e..16ceb5316f 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -618,7 +618,12 @@ test_must_fail () { test_might_fail () { "$@" - test $? -ge 0 -a $? -le 129 -o $? -gt 192 + exit_code=$? + if test $exit_code -gt 129 -a $exit_code -le 192; then + echo >&2 "test_might_fail: died by signal: $*" + return 1 + fi + return 0 } # test_cmp is a helper function to compare actual and expected output. From d0b8a61742714b93b614f9823491a7557879dfb9 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 31 Aug 2010 12:26:57 -0500 Subject: [PATCH 4/4] tests: make test_might_fail fail on missing commands Detect and report hard-to-notice spelling mistakes like test_might_fail "git config --unset whatever" (the extra quotes prevent the shell from running git as intended; instead, the shell looks for a "git config --unset whatever" file). Cc: Jeff King Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/test-lib.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/t/test-lib.sh b/t/test-lib.sh index 16ceb5316f..7da490de01 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -622,6 +622,9 @@ test_might_fail () { if test $exit_code -gt 129 -a $exit_code -le 192; then echo >&2 "test_might_fail: died by signal: $*" return 1 + elif test $exit_code = 127; then + echo >&2 "test_might_fail: command not found: $*" + return 1 fi return 0 }