diff --git a/t/t2008-checkout-subdir.sh b/t/t2008-checkout-subdir.sh index f78945ed8e..3e098ab31e 100755 --- a/t/t2008-checkout-subdir.sh +++ b/t/t2008-checkout-subdir.sh @@ -67,16 +67,16 @@ test_expect_success 'checkout with simple prefix' ' ' -test_expect_failure 'relative path outside tree should fail' \ - 'git checkout HEAD -- ../../Makefile' +test_expect_success 'relative path outside tree should fail' \ + 'test_must_fail git checkout HEAD -- ../../Makefile' -test_expect_failure 'incorrect relative path to file should fail (1)' \ - 'git checkout HEAD -- ../file0' +test_expect_success 'incorrect relative path to file should fail (1)' \ + 'test_must_fail git checkout HEAD -- ../file0' -test_expect_failure 'incorrect relative path should fail (2)' \ - '( cd dir1 && git checkout HEAD -- ./file0 )' +test_expect_success 'incorrect relative path should fail (2)' \ + '( cd dir1 && test_must_fail git checkout HEAD -- ./file0 )' -test_expect_failure 'incorrect relative path should fail (3)' \ - '( cd dir1 && git checkout HEAD -- ../../file0 )' +test_expect_success 'incorrect relative path should fail (3)' \ + '( cd dir1 && test_must_fail git checkout HEAD -- ../../file0 )' test_done 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 test_create_repo () {