summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 301e42e)
raw | patch | inline | side by side (parent: 301e42e)
author | Junio C Hamano <gitster@pobox.com> | |
Thu, 28 Feb 2008 21:09:30 +0000 (13:09 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Fri, 29 Feb 2008 08:00:29 +0000 (00:00 -0800) |
When we expect a git command to notice and signal errors, we
carelessly wrote in our tests:
test_expect_success 'reject bogus request' '
do something &&
do something else &&
! git command
'
but a non-zero exit could come from the "git command" segfaulting.
A new helper function "tset_must_fail" is introduced and it is
meant to be used to make sure the command gracefully fails (iow,
dying and exiting with non zero status is counted as a failure
to "gracefully fail"). The above example should be written as:
test_expect_success 'reject bogus request' '
do something &&
do something else &&
test_must_fail git command
'
Signed-off-by: Junio C Hamano <gitster@pobox.com>
carelessly wrote in our tests:
test_expect_success 'reject bogus request' '
do something &&
do something else &&
! git command
'
but a non-zero exit could come from the "git command" segfaulting.
A new helper function "tset_must_fail" is introduced and it is
meant to be used to make sure the command gracefully fails (iow,
dying and exiting with non zero status is counted as a failure
to "gracefully fail"). The above example should be written as:
test_expect_success 'reject bogus request' '
do something &&
do something else &&
test_must_fail git command
'
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t2008-checkout-subdir.sh | patch | blob | history | |
t/test-lib.sh | patch | blob | history |
index 4a723dc0e564d3b9f8b38a4f85d1b2e917a6edda..3e098ab31e1944abe8e5815c0f219947620b6618 100755 (executable)
'
test_expect_success 'relative path outside tree should fail' \
- '! git checkout HEAD -- ../../Makefile'
+ 'test_must_fail git checkout HEAD -- ../../Makefile'
test_expect_success 'incorrect relative path to file should fail (1)' \
- '! git checkout HEAD -- ../file0'
+ 'test_must_fail git checkout HEAD -- ../file0'
test_expect_success 'incorrect relative path should fail (2)' \
- '( cd dir1 && ! git checkout HEAD -- ./file0 )'
+ '( cd dir1 && test_must_fail git checkout HEAD -- ./file0 )'
test_expect_success 'incorrect relative path should fail (3)' \
- '( cd dir1 && ! git checkout HEAD -- ../../file0 )'
+ '( cd dir1 && test_must_fail git checkout HEAD -- ../../file0 )'
test_done
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 83889c4f4690d30fd2d5e969d5d445dfb47ad579..90df619b9f67374c76ec7506836b78bd2c264cc7 100644 (file)
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
echo >&3 ""
}
+# 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:
+#
+# test_expect_success 'complain and die' '
+# do something &&
+# do something else &&
+# test_must_fail git checkout ../outerspace
+# '
+#
+# Writing this as "! git checkout ../outerspace" is wrong, because
+# the failure could be due to a segv. We want a controlled failure.
+
+test_must_fail () {
+ "$@"
+ test $? -gt 0 -a $? -le 128
+}
+
# Most tests can use the created repository, but some may need to create more.
# Usage: test_create_repo <directory>
test_create_repo () {