From: Junio C Hamano Date: Tue, 14 Apr 2026 17:00:47 GMT Subject: Re: [PATCH 2/3] t7004: dynamically grab expected state in tests Message-ID: In-Reply-To: <20260414141828.27576-3-r.siddharth.shrimali@gmail.com> Siddharth Shrimali writes: > The tests for 'Multiple -l or --list options' and 'trying to delete > tags without params', hardcodes that exactly one or two specific tags > ('myhead', 'mytag') exist in the repository. > > If other tests are added, modified, or removed earlier in the script, > this expected global state will change, resulting in these tests to fail > for completely unrelated reasons. > > Instead of hardcoding the expected tags, dynamically grab the state > of the repository before running the commands under test ('git tag -l' > and 'git tag -d'), and verify that the output matches or remains > unchanged afterward. This keeps the tests independent from the script's > overall state. > > Signed-off-by: Siddharth Shrimali > --- > t/t7004-tag.sh | 11 ++--------- > 1 file changed, 2 insertions(+), 9 deletions(-) Excellent. I agree with both reasoning above and execution below. > > diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh > index 6ca5c75b57..4fdd47cd21 100755 > --- a/t/t7004-tag.sh > +++ b/t/t7004-tag.sh > @@ -145,9 +145,7 @@ test_expect_success 'listing all tags if one exists should succeed' ' > ' > > test_expect_success 'Multiple -l or --list options are equivalent to one -l option' ' > - cat >expect <<-\EOF && > - mytag > - EOF > + git tag -l >expect && > git tag -l -l >actual && > test_cmp expect actual && > git tag --list --list >actual && > @@ -223,12 +221,7 @@ test_expect_success 'trying to delete an unknown tag should fail' ' > ' > > test_expect_success 'trying to delete tags without params should succeed and do nothing' ' > - cat >expect <<-\EOF && > - myhead > - mytag > - EOF > - git tag -l >actual && > - test_cmp expect actual && > + git tag -l >expect && > git tag -d && > git tag -l >actual && > test_cmp expect actual