Sane use of test_expect_failure

Originally, test_expect_failure was designed to be the opposite
of test_expect_success, but this was a bad decision.  Most tests
run a series of commands that leads to the single command that
needs to be tested, like this:

    test_expect_{success,failure} 'test title' '
	setup1 &&
        setup2 &&
        setup3 &&
        what is to be tested
    '

And expecting a failure exit from the whole sequence misses the
point of writing tests.  Your setup$N that are supposed to
succeed may have failed without even reaching what you are
trying to test.  The only valid use of test_expect_failure is to
check a trivial single command that is expected to fail, which
is a minority in tests of Porcelain-ish commands.

This large-ish patch rewrites all uses of test_expect_failure to
use test_expect_success and rewrites the condition of what is
tested, like this:

    test_expect_success 'test title' '
	setup1 &&
        setup2 &&
        setup3 &&
        ! this command should fail
    '

test_expect_failure is redefined to serve as a reminder that
that test *should* succeed but due to a known breakage in git it
currently does not pass.  So if git-foo command should create a
file 'bar' but you discovered a bug that it doesn't, you can
write a test like this:

    test_expect_failure 'git-foo should create bar' '
        rm -f bar &&
        git foo &&
        test -f bar
    '

This construct acts similar to test_expect_success, but instead
of reporting "ok/FAIL" like test_expect_success does, the
outcome is reported as "FIXED/still broken".

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano
2008-02-01 01:50:53 -08:00
parent 6ce8e44a1e
commit 41ac414ea2
48 changed files with 496 additions and 425 deletions

View File

@ -56,19 +56,19 @@ test_expect_success "$name" "
name='detect node change from file to directory #1'
test_expect_failure "$name" "
test_expect_success "$name" "
mkdir dir/new_file &&
mv dir/file dir/new_file/file &&
mv dir/new_file dir/file &&
git update-index --remove dir/file &&
git update-index --add dir/file/file &&
git commit -m '$name' &&
git-svn set-tree --find-copies-harder --rmdir \
git commit -m '$name' &&
! git-svn set-tree --find-copies-harder --rmdir \
remotes/git-svn..mybranch" || true
name='detect node change from directory to file #1'
test_expect_failure "$name" "
test_expect_success "$name" "
rm -rf dir '$GIT_DIR'/index &&
git checkout -f -b mybranch2 remotes/git-svn &&
mv bar/zzz zzz &&
@ -77,12 +77,12 @@ test_expect_failure "$name" "
git update-index --remove -- bar/zzz &&
git update-index --add -- bar &&
git commit -m '$name' &&
git-svn set-tree --find-copies-harder --rmdir \
! git-svn set-tree --find-copies-harder --rmdir \
remotes/git-svn..mybranch2" || true
name='detect node change from file to directory #2'
test_expect_failure "$name" "
test_expect_success "$name" "
rm -f '$GIT_DIR'/index &&
git checkout -f -b mybranch3 remotes/git-svn &&
rm bar/zzz &&
@ -91,12 +91,12 @@ test_expect_failure "$name" "
echo yyy > bar/zzz/yyy &&
git update-index --add bar/zzz/yyy &&
git commit -m '$name' &&
git-svn set-tree --find-copies-harder --rmdir \
! git-svn set-tree --find-copies-harder --rmdir \
remotes/git-svn..mybranch3" || true
name='detect node change from directory to file #2'
test_expect_failure "$name" "
test_expect_success "$name" "
rm -f '$GIT_DIR'/index &&
git checkout -f -b mybranch4 remotes/git-svn &&
rm -rf dir &&
@ -105,7 +105,7 @@ test_expect_failure "$name" "
echo asdf > dir &&
git update-index --add -- dir &&
git commit -m '$name' &&
git-svn set-tree --find-copies-harder --rmdir \
! git-svn set-tree --find-copies-harder --rmdir \
remotes/git-svn..mybranch4" || true
@ -213,18 +213,18 @@ EOF
test_expect_success "$name" "git diff a expected"
test_expect_failure 'exit if remote refs are ambigious' "
test_expect_success 'exit if remote refs are ambigious' "
git config --add svn-remote.svn.fetch \
bar:refs/remotes/git-svn &&
git-svn migrate
"
! git-svn migrate
"
test_expect_failure 'exit if init-ing a would clobber a URL' "
test_expect_success 'exit if init-ing a would clobber a URL' "
svnadmin create ${PWD}/svnrepo2 &&
svn mkdir -m 'mkdir bar' ${svnrepo}2/bar &&
git config --unset svn-remote.svn.fetch \
'^bar:refs/remotes/git-svn$' &&
git-svn init ${svnrepo}2/bar
! git-svn init ${svnrepo}2/bar
"
test_expect_success \