From 90d0ed96b76ee51f8ae6f32923b92e7b20ba73c0 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 28 Feb 2008 13:09:30 -0800 Subject: 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 --- t/t2008-checkout-subdir.sh | 16 ++++++++-------- t/test-lib.sh | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) (limited to 't') diff --git a/t/t2008-checkout-subdir.sh b/t/t2008-checkout-subdir.sh index f78945ed8..3e098ab31 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 142540e1b..c0c5e21ad 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 () { -- cgit v1.2.1 From 0f2d4476c12c15106be20d53c507035e157b66f1 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 3 Mar 2008 01:30:56 -0500 Subject: revert: actually check for a dirty index The previous code mistakenly used wt_status_prepare to check whether the index had anything commitable in it; however, that function is just an init function, and will never report a dirty index. The correct way with wt_status_* would be to call wt_status_print with the output pointing to /dev/null or similar. However, that does extra work by both examining the working tree and spewing status information to nowhere. Instead, let's just implement the useful subset of wt_status_print as an "is_index_dirty" function. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t3501-revert-cherry-pick.sh | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 't') diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh index 2dbe04fb2..6da212825 100755 --- a/t/t3501-revert-cherry-pick.sh +++ b/t/t3501-revert-cherry-pick.sh @@ -59,4 +59,13 @@ test_expect_success 'revert after renaming branch' ' ' +test_expect_success 'revert forbidden on dirty working tree' ' + + echo content >extra_file && + git add extra_file && + test_must_fail git revert HEAD 2>errors && + grep "Dirty index" errors + +' + test_done -- cgit v1.2.1