{"thread":{"id":"61897","subject":"[PATCH v2][Newcomer] t7004-tag: modernize the test script","startedAt":"2024-08-03T14:27:14Z","lastAt":"2024-08-03T14:27:14Z","messageCount":1,"participants":["AbdAlRahman Gad"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"500004","messageId":"20240803142646.52341-1-abdobngad@gmail.com","threadId":"61897","inReplyTo":null,"subject":"[PATCH v2][Newcomer] t7004-tag: modernize the test script","fromName":"AbdAlRahman Gad","fromEmail":"abdobngad@gmail.com","sentAt":"2024-08-03T14:26:46Z","receivedAt":"2024-08-03T14:27:14Z","isPatch":true,"sender":{"key":"abdobngad@gmail.com","avatar":"https://avatars.githubusercontent.com/u/89566409?v=4"},"body":"- remove whitespace after the redirect operators.\n\n- move number of expect files prepared outside of\n  test_expect_success to be inside the tests that use it.\n\n- split some lines that have two commands into two lines\n  one command each.\n\n- turn some \"<<\\EOF\" into \"<<-\\EOF\" and indent their body.\n\n- avoid using pipes in the output from \"test-tool ref-store\"\n  and write the output to a file.\n\nSigned-off-by: AbdAlRahman Gad <abdobngad@gmail.com>\n---\n t/t7004-tag.sh | 304 +++++++++++++++++++++++++++----------------------\n 1 file changed, 165 insertions(+), 139 deletions(-)\n\ndiff --git a/t/t7004-tag.sh b/t/t7004-tag.sh\nindex fa6336edf9..c60167d6fd 100755\n--- a/t/t7004-tag.sh\n+++ b/t/t7004-tag.sh\n@@ -97,7 +97,8 @@ test_expect_success 'creating a tag with --create-reflog should create reflog' '\n \ttest_when_finished \"git tag -d tag_with_reflog1\" &&\n \tgit tag --create-reflog tag_with_reflog1 &&\n \tgit reflog exists refs/tags/tag_with_reflog1 &&\n-\ttest-tool ref-store main for-each-reflog-ent refs/tags/tag_with_reflog1 | sed -e \"s/^.*\t//\" >actual &&\n+\ttest-tool ref-store main for-each-reflog-ent refs/tags/tag_with_reflog1 >actual.body &&\n+\tsed -e \"s/^.*\t//\" actual.body >actual &&\n \ttest_cmp expected actual\n '\n \n@@ -108,7 +109,8 @@ test_expect_success 'annotated tag with --create-reflog has correct message' '\n \ttest_when_finished \"git tag -d tag_with_reflog2\" &&\n \tgit tag -m \"annotated tag\" --create-reflog tag_with_reflog2 &&\n \tgit reflog exists refs/tags/tag_with_reflog2 &&\n-\ttest-tool ref-store main for-each-reflog-ent refs/tags/tag_with_reflog2 | sed -e \"s/^.*\t//\" >actual &&\n+\ttest-tool ref-store main for-each-reflog-ent refs/tags/tag_with_reflog2 >actual.body &&\n+\tsed -e \"s/^.*\t//\" actual.body >actual &&\n \ttest_cmp expected actual\n '\n \n@@ -129,10 +131,10 @@ test_expect_success 'listing all tags if one exists should succeed' '\n \tgit tag\n '\n \n-cat >expect <<EOF\n-mytag\n-EOF\n test_expect_success 'Multiple -l or --list options are equivalent to one -l option' '\n+\tcat >expect <<-\\EOF &&\n+\tmytag\n+\tEOF\n \tgit tag -l -l >actual &&\n \ttest_cmp expect actual &&\n \tgit tag --list --list >actual &&\n@@ -207,15 +209,17 @@ test_expect_success 'trying to delete an unknown tag should fail' '\n \ttest_must_fail git tag -d unknown-tag\n '\n \n-cat >expect <<EOF\n-myhead\n-mytag\n-EOF\n test_expect_success \\\n \t'trying to delete tags without params should succeed and do nothing' '\n-\tgit tag -l > actual && test_cmp expect actual &&\n+\tcat >expect <<-\\EOF &&\n+\tmyhead\n+\tmytag\n+\tEOF\n+\tgit tag -l >actual &&\n+\ttest_cmp expect actual &&\n \tgit tag -d &&\n-\tgit tag -l > actual && test_cmp expect actual\n+\tgit tag -l >actual &&\n+\ttest_cmp expect actual\n '\n \n test_expect_success \\\n@@ -248,18 +252,18 @@ test_expect_success 'trying to delete an already deleted tag should fail' \\\n \n # listing various tags with pattern matching:\n \n-cat >expect <<EOF\n-a1\n-aa1\n-cba\n-t210\n-t211\n-v0.2.1\n-v1.0\n-v1.0.1\n-v1.1.3\n-EOF\n test_expect_success 'listing all tags should print them ordered' '\n+\tcat >expect <<-\\EOF &&\n+\ta1\n+\taa1\n+\tcba\n+\tt210\n+\tt211\n+\tv0.2.1\n+\tv1.0\n+\tv1.0.1\n+\tv1.1.3\n+\tEOF\n \tgit tag v1.0.1 &&\n \tgit tag t211 &&\n \tgit tag aa1 &&\n@@ -269,91 +273,97 @@ test_expect_success 'listing all tags should print them ordered' '\n \tgit tag a1 &&\n \tgit tag v1.0 &&\n \tgit tag t210 &&\n-\tgit tag -l > actual &&\n+\tgit tag -l >actual &&\n \ttest_cmp expect actual &&\n-\tgit tag > actual &&\n+\tgit tag >actual &&\n \ttest_cmp expect actual\n '\n \n-cat >expect <<EOF\n-a1\n-aa1\n-cba\n-EOF\n test_expect_success \\\n \t'listing tags with substring as pattern must print those matching' '\n+\tcat >expect <<-\\EOF &&\n+\ta1\n+\taa1\n+\tcba\n+\tEOF\n \trm *a* &&\n-\tgit tag -l \"*a*\" > current &&\n+\tgit tag -l \"*a*\" >current &&\n \ttest_cmp expect current\n '\n \n-cat >expect <<EOF\n-v0.2.1\n-v1.0.1\n-EOF\n test_expect_success \\\n \t'listing tags with a suffix as pattern must print those matching' '\n-\tgit tag -l \"*.1\" > actual &&\n+\tcat >expect <<-\\EOF &&\n+\tv0.2.1\n+\tv1.0.1\n+\tEOF\n+\tgit tag -l \"*.1\" >actual &&\n \ttest_cmp expect actual\n '\n \n-cat >expect <<EOF\n-t210\n-t211\n-EOF\n test_expect_success \\\n \t'listing tags with a prefix as pattern must print those matching' '\n-\tgit tag -l \"t21*\" > actual &&\n+\tcat >expect <<-\\EOF &&\n+\tt210\n+\tt211\n+\tEOF\n+\tgit tag -l \"t21*\" >actual &&\n \ttest_cmp expect actual\n '\n \n-cat >expect <<EOF\n-a1\n-EOF\n test_expect_success \\\n \t'listing tags using a name as pattern must print that one matching' '\n-\tgit tag -l a1 > actual &&\n+\tcat >expect <<-\\EOF &&\n+\ta1\n+\tEOF\n+\tgit tag -l a1 >actual &&\n \ttest_cmp expect actual\n '\n \n-cat >expect <<EOF\n-v1.0\n-EOF\n test_expect_success \\\n \t'listing tags using a name as pattern must print that one matching' '\n-\tgit tag -l v1.0 > actual &&\n+\tcat >expect <<-\\EOF &&\n+\tv1.0\n+\tEOF\n+\tgit tag -l v1.0 >actual &&\n \ttest_cmp expect actual\n '\n \n-cat >expect <<EOF\n-v1.0.1\n-v1.1.3\n-EOF\n test_expect_success \\\n \t'listing tags with ? in the pattern should print those matching' '\n-\tgit tag -l \"v1.?.?\" > actual &&\n+\tcat >expect <<-\\EOF &&\n+\tv1.0.1\n+\tv1.1.3\n+\tEOF\n+\tgit tag -l \"v1.?.?\" >actual &&\n \ttest_cmp expect actual\n '\n \n test_expect_success \\\n \t'listing tags using v.* should print nothing because none have v.' '\n-\tgit tag -l \"v.*\" > actual &&\n+\tgit tag -l \"v.*\" >actual &&\n \ttest_must_be_empty actual\n '\n \n-cat >expect <<EOF\n-v0.2.1\n-v1.0\n-v1.0.1\n-v1.1.3\n-EOF\n test_expect_success \\\n \t'listing tags using v* should print only those having v' '\n-\tgit tag -l \"v*\" > actual &&\n+\tcat >expect <<-\\EOF &&\n+\tv0.2.1\n+\tv1.0\n+\tv1.0.1\n+\tv1.1.3\n+\tEOF\n+\tgit tag -l \"v*\" >actual &&\n \ttest_cmp expect actual\n '\n \n test_expect_success 'tag -l can accept multiple patterns' '\n+\tcat >expect <<-\\EOF &&\n+\tv0.2.1\n+\tv1.0\n+\tv1.0.1\n+\tv1.1.3\n+\tEOF\n \tgit tag -l \"v1*\" \"v0*\" >actual &&\n \ttest_cmp expect actual\n '\n@@ -367,16 +377,22 @@ test_expect_success 'tag -l can accept multiple patterns' '\n # out if we're going to break this long-documented form of taking\n # multiple patterns.\n test_expect_success 'tag -l <pattern> -l <pattern> works, as our buggy documentation previously suggested' '\n+\tcat >expect <<-\\EOF &&\n+\tv0.2.1\n+\tv1.0\n+\tv1.0.1\n+\tv1.1.3\n+\tEOF\n \tgit tag -l \"v1*\" -l \"v0*\" >actual &&\n \ttest_cmp expect actual\n '\n \n test_expect_success 'listing tags in column' '\n \tCOLUMNS=41 git tag -l --column=row >actual &&\n-\tcat >expected <<\\EOF &&\n-a1      aa1     cba     t210    t211\n-v0.2.1  v1.0    v1.0.1  v1.1.3\n-EOF\n+\tcat >expected <<-\\EOF &&\n+\ta1      aa1     cba     t210    t211\n+\tv0.2.1  v1.0    v1.0.1  v1.1.3\n+\tEOF\n \ttest_cmp expected actual\n '\n \n@@ -384,10 +400,10 @@ test_expect_success 'listing tags in column with column.*' '\n \ttest_config column.tag row &&\n \ttest_config column.ui dense &&\n \tCOLUMNS=40 git tag -l >actual &&\n-\tcat >expected <<\\EOF &&\n-a1      aa1   cba     t210    t211\n-v0.2.1  v1.0  v1.0.1  v1.1.3\n-EOF\n+\tcat >expected <<-\\EOF &&\n+\ta1      aa1   cba     t210    t211\n+\tv0.2.1  v1.0  v1.0.1  v1.1.3\n+\tEOF\n \ttest_cmp expected actual\n '\n \n@@ -398,17 +414,17 @@ test_expect_success 'listing tag with -n --column should fail' '\n test_expect_success 'listing tags -n in column with column.ui ignored' '\n \ttest_config column.ui \"row dense\" &&\n \tCOLUMNS=40 git tag -l -n >actual &&\n-\tcat >expected <<\\EOF &&\n-a1              Foo\n-aa1             Foo\n-cba             Foo\n-t210            Foo\n-t211            Foo\n-v0.2.1          Foo\n-v1.0            Foo\n-v1.0.1          Foo\n-v1.1.3          Foo\n-EOF\n+\tcat >expected <<-\\EOF &&\n+\ta1              Foo\n+\taa1             Foo\n+\tcba             Foo\n+\tt210            Foo\n+\tt211            Foo\n+\tv0.2.1          Foo\n+\tv1.0            Foo\n+\tv1.0.1          Foo\n+\tv1.1.3          Foo\n+\tEOF\n \ttest_cmp expected actual\n '\n \n@@ -1171,7 +1187,7 @@ test_expect_success GPG \\\n \tgit tag -v emptyfile-signed-tag\n '\n \n-printf '\\n\\n  \\n\\t\\nLeading blank lines\\n' > sigblanksfile\n+printf '\\n\\n  \\n\\t\\nLeading blank lines\\n' >sigblanksfile\n printf '\\n\\t \\t  \\nRepeated blank lines\\n' >>sigblanksfile\n printf '\\n\\n\\nTrailing spaces      \\t  \\n' >>sigblanksfile\n printf '\\nTrailing blank lines\\n\\n\\t \\n\\n' >>sigblanksfile\n@@ -1569,7 +1585,7 @@ test_expect_success \\\n \n test_expect_success \\\n \t'message in editor has initial comment' '\n-\t! (GIT_EDITOR=cat git tag -a initial-comment > actual)\n+\t! (GIT_EDITOR=cat git tag -a initial-comment >actual)\n '\n \n test_expect_success 'message in editor has initial comment: first line' '\n@@ -1587,7 +1603,7 @@ test_expect_success \\\n '\n \n get_tag_header reuse $commit commit $time >expect\n-echo \"An annotation to be reused\" >> expect\n+echo \"An annotation to be reused\" >>expect\n test_expect_success \\\n \t'overwriting an annotated tag should use its previous body' '\n \tgit tag -a -m \"An annotation to be reused\" reuse &&\n@@ -1639,7 +1655,7 @@ hash3=$(git rev-parse HEAD)\n \n # simple linear checks of --continue\n \n-cat > expected <<EOF\n+cat >expected <<EOF\n v0.2.1\n v1.0\n v1.0.1\n@@ -1679,23 +1695,21 @@ test_expect_success 'checking that first commit is in all tags (relative)' \"\n \ttest_must_be_empty actual\n \"\n \n-cat > expected <<EOF\n-v2.0\n-EOF\n-\n test_expect_success 'checking that second commit only has one tag' \"\n+\tcat >expected <<-\\EOF &&\n+\tv2.0\n+\tEOF\n \tgit tag -l --contains $hash2 v* >actual &&\n \ttest_cmp expected actual\n \"\n \n-cat > expected <<EOF\n-v0.2.1\n-v1.0\n-v1.0.1\n-v1.1.3\n-EOF\n-\n test_expect_success 'inverse of the last test, with --no-contains' \"\n+\tcat >expected <<-\\EOF &&\n+\tv0.2.1\n+\tv1.0\n+\tv1.0.1\n+\tv1.1.3\n+\tEOF\n \tgit tag -l --no-contains $hash2 v* >actual &&\n \ttest_cmp expected actual\n \"\n@@ -1705,15 +1719,14 @@ test_expect_success 'checking that third commit has no tags' \"\n \ttest_must_be_empty actual\n \"\n \n-cat > expected <<EOF\n-v0.2.1\n-v1.0\n-v1.0.1\n-v1.1.3\n-v2.0\n-EOF\n-\n test_expect_success 'conversely --no-contains on the third commit lists all tags' \"\n+\tcat >expected <<-\\EOF &&\n+\tv0.2.1\n+\tv1.0\n+\tv1.0.1\n+\tv1.1.3\n+\tv2.0\n+\tEOF\n \tgit tag -l --no-contains $hash3 v* >actual &&\n \ttest_cmp expected actual\n \"\n@@ -1723,31 +1736,29 @@ test_expect_success 'conversely --no-contains on the third commit lists all tags\n test_expect_success 'creating simple branch' '\n \tgit branch stable v2.0 &&\n         git checkout stable &&\n-\techo foo-3.0 > foo &&\n+\techo foo-3.0 >foo &&\n \tgit commit foo -m fourth &&\n \tgit tag v3.0\n '\n \n hash4=$(git rev-parse HEAD)\n \n-cat > expected <<EOF\n-v3.0\n-EOF\n-\n test_expect_success 'checking that branch head only has one tag' \"\n+\tcat >expected <<-\\EOF &&\n+\tv3.0\n+\tEOF\n \tgit tag -l --contains $hash4 v* >actual &&\n \ttest_cmp expected actual\n \"\n \n-cat > expected <<EOF\n-v0.2.1\n-v1.0\n-v1.0.1\n-v1.1.3\n-v2.0\n-EOF\n-\n test_expect_success 'checking that branch head with --no-contains lists all but one tag' \"\n+\tcat >expected <<-\\EOF &&\n+\tv0.2.1\n+\tv1.0\n+\tv1.0.1\n+\tv1.1.3\n+\tv2.0\n+\tEOF\n \tgit tag -l --no-contains $hash4 v* >actual &&\n \ttest_cmp expected actual\n \"\n@@ -1757,50 +1768,65 @@ test_expect_success 'merging original branch into this branch' '\n         git tag v4.0\n '\n \n-cat > expected <<EOF\n-v4.0\n-EOF\n-\n test_expect_success 'checking that original branch head has one tag now' \"\n+\tcat >expected <<-\\EOF &&\n+\tv4.0\n+\tEOF\n \tgit tag -l --contains $hash3 v* >actual &&\n \ttest_cmp expected actual\n \"\n \n-cat > expected <<EOF\n-v0.2.1\n-v1.0\n-v1.0.1\n-v1.1.3\n-v2.0\n-v3.0\n-EOF\n-\n test_expect_success 'checking that original branch head with --no-contains lists all but one tag now' \"\n+\tcat >expected <<-\\EOF &&\n+\tv0.2.1\n+\tv1.0\n+\tv1.0.1\n+\tv1.1.3\n+\tv2.0\n+\tv3.0\n+\tEOF\n \tgit tag -l --no-contains $hash3 v* >actual &&\n \ttest_cmp expected actual\n \"\n \n-cat > expected <<EOF\n-v0.2.1\n-v1.0\n-v1.0.1\n-v1.1.3\n-v2.0\n-v3.0\n-v4.0\n-EOF\n-\n test_expect_success 'checking that initial commit is in all tags' \"\n+\tcat >expected <<-\\EOF &&\n+\tv0.2.1\n+\tv1.0\n+\tv1.0.1\n+\tv1.1.3\n+\tv2.0\n+\tv3.0\n+\tv4.0\n+\tEOF\n \tgit tag -l --contains $hash1 v* >actual &&\n \ttest_cmp expected actual\n \"\n \n test_expect_success 'checking that --contains can be used in non-list mode' '\n+\tcat >expected <<-\\EOF &&\n+\tv0.2.1\n+\tv1.0\n+\tv1.0.1\n+\tv1.1.3\n+\tv2.0\n+\tv3.0\n+\tv4.0\n+\tEOF\n \tgit tag --contains $hash1 v* >actual &&\n \ttest_cmp expected actual\n '\n \n test_expect_success 'checking that initial commit is in all tags with --no-contains' \"\n+\tcat >expected <<-\\EOF &&\n+\tv0.2.1\n+\tv1.0\n+\tv1.0.1\n+\tv1.1.3\n+\tv2.0\n+\tv3.0\n+\tv4.0\n+\tEOF\n \tgit tag -l --no-contains $hash1 v* >actual &&\n \ttest_must_be_empty actual\n \"\n-- \n2.43.0\n\n"}]}