Subject: Re: [PATCHv4 06/15] t3600 (rm): add lots of missing &&

From: Jonathan Nieder <[email-masked]>
Date: Fri, 1 Oct 2010 05:48:23 -0500

Elijah Newren wrote:

> Also delete unnecessary, failing code and add some test_when_finished
> calls to make sure tests clean up after themselves.

I don't understand this one.

If tests clean up after themselves, each will restore some pristine
state as though (at least as far as the other tests care) it had never
run at all, right?

> --- a/t/t3600-rm.sh
> +++ b/t/t3600-rm.sh
> @@ -38,37 +38,33 @@ test_expect_success \
>  
>  test_expect_success \
>      'Test that git rm --cached foo succeeds if the index matches the file' \
> -    'echo content > foo
> -     git add foo
> +    'echo content > foo &&
> +     git add foo &&
>       git rm --cached foo'

Before this runs: foo is empty, absent from index.
After it runs: foo has content, still absent from index.
Requires: nothing.
 
>  test_expect_success \
>      'Test that git rm --cached foo succeeds if the index matches the file' \
> -    'echo content > foo
> -     git add foo
> -     git commit -m foo
> -     echo "other content" > foo
> +    'echo content > foo &&
> +     git add foo &&
> +     git commit -m foo &&
> +     echo "other content" > foo &&
> +     test_when_finished "git checkout HEAD -- foo" &&
>       git rm --cached foo'

Before this runs: foo has content, absent from index.
After this runs (without patch): foo has other content, absent from index.
After this runs (with patch): foo has content, matching index.
Requires: nothing.

>  test_expect_success \
>      'Test that git rm --cached foo fails if the index matches neither the file nor HEAD' '
> -     echo content > foo
> -     git add foo
> -     git commit -m foo
> -     echo "other content" > foo
> -     git add foo
> -     echo "yet another content" > foo
> +     echo "other content" > foo &&
> +     git add foo &&
> +     echo "yet another content" > foo &&
> +     test_when_finished "git checkout HEAD -- foo" &&
>       test_must_fail git rm --cached foo
>  '

Before this runs: see above.
After this runs (without patch): foo has yet another content, absent from index.
After this runs (with patch): foo has content, matching index.
Requires (without patch): nothing.
Requires (with patch): HEAD:foo is content.

[etc]

So if I understand correctly, this sacrifices the ability to
skip individual tests.  What does one gain in return?