diff options
author | Junio C Hamano <gitster@pobox.com> | 2008-02-28 13:09:30 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-03-02 23:15:06 -0800 |
commit | 90d0ed96b76ee51f8ae6f32923b92e7b20ba73c0 (patch) | |
tree | 52960079fe7077394215af7fb5b2cac40c061c65 /t/test-lib.sh | |
parent | fcbcfe707ae23b37d72025a229f31c450fb4d3b3 (diff) | |
download | git-90d0ed96b76ee51f8ae6f32923b92e7b20ba73c0.tar.gz |
tests: introduce test_must_fail
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>
Diffstat (limited to 't/test-lib.sh')
-rw-r--r-- | t/test-lib.sh | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/t/test-lib.sh b/t/test-lib.sh index 142540e1b1..c0c5e21adf 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -257,6 +257,23 @@ test_expect_code () { 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 () { |