From 2df546e17fa1c28ac44c886f59ba39ea2f00124a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 12 Apr 2021 13:21:43 +0200 Subject: [PATCH 1/5] describe tests: improve test for --work-tree & --dirty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improve tests added in 9f67d2e8279 (Teach "git describe" --dirty option, 2009-10-21) and 2ed5c8e174d (describe: setup working tree for --dirty, 2019-02-03) so that they make sense in combination with each other. The "check_describe" being removed here was the earlier test, we then later added these --work-tree tests which really just wanted to check if we got the exact same output from "describe", but the test wasn't structured to test for that. Let's change it to do that, which both improves test coverage and makes it more obvious what's going on here. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t6120-describe.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index 88fddc9142..a83ea15faa 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -151,24 +151,24 @@ test_expect_success 'set-up dirty work tree' ' echo >>file ' -check_describe "A-*[0-9a-f]-dirty" --dirty - test_expect_success 'describe --dirty with --work-tree (dirty)' ' + git describe --dirty >expected && ( cd "$TEST_DIRECTORY" && git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out" ) && - grep -E "^A-[1-9][0-9]?-g[0-9a-f]+-dirty$" out + grep -E "^A-[1-9][0-9]?-g[0-9a-f]+-dirty$" out && + test_cmp expected out ' -check_describe "A-*[0-9a-f].mod" --dirty=.mod - test_expect_success 'describe --dirty=.mod with --work-tree (dirty)' ' + git describe --dirty=.mod >expected && ( cd "$TEST_DIRECTORY" && git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty=.mod >"$TRASH_DIRECTORY/out" ) && - grep -E "^A-[1-9][0-9]?-g[0-9a-f]+.mod$" out + grep -E "^A-[1-9][0-9]?-g[0-9a-f]+.mod$" out && + test_cmp expected out ' test_expect_success 'describe --dirty HEAD' ' From a46a84829650fbe6077e5a33f4ac1c9d2041d1df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 12 Apr 2021 13:21:44 +0200 Subject: [PATCH 2/5] describe tests: refactor away from glob matching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change the glob matching via a "case" statement to a "test_cmp" after we've stripped out the hash-specific g suffix. 5312ab11fbf (Add describe test., 2007-01-13). This means that we can use test_cmp to compare the output. I could omit the "-8" change of e.g. "A-*" to "A-8-gHASH", but I think it makes sense to test that here explicitly. It means you need to add new tests to the bottom of the file, but that's not a burden in this case. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t6120-describe.sh | 78 ++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index a83ea15faa..13117bbcfb 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -21,12 +21,10 @@ check_describe () { shift describe_opts="$@" test_expect_success "describe $describe_opts" ' - R=$(git describe $describe_opts 2>err.actual) && - case "$R" in - $expect) echo happy ;; - *) echo "Oops - $R is not $expect" && - false ;; - esac + git describe $describe_opts 2>err.actual >raw && + sed -e "s/-g[0-9a-f]*\$/-gHASH/" actual && + echo "$expect" >expect && + test_cmp expect actual ' } @@ -59,29 +57,29 @@ test_expect_success setup ' test_commit --no-tag x file ' -check_describe A-* HEAD -check_describe A-* HEAD^ -check_describe R-* HEAD^^ -check_describe A-* HEAD^^2 +check_describe A-8-gHASH HEAD +check_describe A-7-gHASH HEAD^ +check_describe R-2-gHASH HEAD^^ +check_describe A-3-gHASH HEAD^^2 check_describe B HEAD^^2^ -check_describe R-* HEAD^^^ +check_describe R-1-gHASH HEAD^^^ -check_describe c-* --tags HEAD -check_describe c-* --tags HEAD^ -check_describe e-* --tags HEAD^^ -check_describe c-* --tags HEAD^^2 +check_describe c-7-gHASH --tags HEAD +check_describe c-6-gHASH --tags HEAD^ +check_describe e-1-gHASH --tags HEAD^^ +check_describe c-2-gHASH --tags HEAD^^2 check_describe B --tags HEAD^^2^ check_describe e --tags HEAD^^^ check_describe heads/main --all HEAD -check_describe tags/c-* --all HEAD^ +check_describe tags/c-6-gHASH --all HEAD^ check_describe tags/e --all HEAD^^^ -check_describe B-0-* --long HEAD^^2^ -check_describe A-3-* --long HEAD^^2 +check_describe B-0-gHASH --long HEAD^^2^ +check_describe A-3-gHASH --long HEAD^^2 -check_describe c-7-* --tags -check_describe e-3-* --first-parent --tags +check_describe c-7-gHASH --tags +check_describe e-3-gHASH --first-parent --tags test_expect_success 'describe --contains defaults to HEAD without commit-ish' ' echo "A^0" >expect && @@ -102,7 +100,7 @@ test_expect_success 'rename tag A to Q locally' ' cat - >err.expect <out && - grep -E "^A-[1-9][0-9]?-g[0-9a-f]+$" out + grep -E "^A-8-g[0-9a-f]+$" out ' -check_describe "A-*[0-9a-f]" --dirty +check_describe "A-8-gHASH" --dirty test_expect_success 'describe --dirty with --work-tree' ' ( cd "$TEST_DIRECTORY" && git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out" ) && - grep -E "^A-[1-9][0-9]?-g[0-9a-f]+$" out + grep -E "^A-8-g[0-9a-f]+$" out ' test_expect_success 'set-up dirty work tree' ' @@ -157,7 +155,7 @@ test_expect_success 'describe --dirty with --work-tree (dirty)' ' cd "$TEST_DIRECTORY" && git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out" ) && - grep -E "^A-[1-9][0-9]?-g[0-9a-f]+-dirty$" out && + grep -E "^A-8-g[0-9a-f]+-dirty$" out && test_cmp expected out ' @@ -167,7 +165,7 @@ test_expect_success 'describe --dirty=.mod with --work-tree (dirty)' ' cd "$TEST_DIRECTORY" && git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty=.mod >"$TRASH_DIRECTORY/out" ) && - grep -E "^A-[1-9][0-9]?-g[0-9a-f]+.mod$" out && + grep -E "^A-8-g[0-9a-f]+.mod$" out && test_cmp expected out ' @@ -191,21 +189,21 @@ test_expect_success 'set-up matching pattern tests' ' ' -check_describe "test-annotated-*" --match="test-*" +check_describe "test-annotated-3-gHASH" --match="test-*" -check_describe "test1-lightweight-*" --tags --match="test1-*" +check_describe "test1-lightweight-2-gHASH" --tags --match="test1-*" -check_describe "test2-lightweight-*" --tags --match="test2-*" +check_describe "test2-lightweight-1-gHASH" --tags --match="test2-*" -check_describe "test2-lightweight-*" --long --tags --match="test2-*" HEAD^ +check_describe "test2-lightweight-0-gHASH" --long --tags --match="test2-*" HEAD^ -check_describe "test2-lightweight-*" --long --tags --match="test1-*" --match="test2-*" HEAD^ +check_describe "test2-lightweight-0-gHASH" --long --tags --match="test1-*" --match="test2-*" HEAD^ -check_describe "test2-lightweight-*" --long --tags --match="test1-*" --no-match --match="test2-*" HEAD^ +check_describe "test2-lightweight-0-gHASH" --long --tags --match="test1-*" --no-match --match="test2-*" HEAD^ -check_describe "test1-lightweight-*" --long --tags --match="test1-*" --match="test3-*" HEAD +check_describe "test1-lightweight-2-gHASH" --long --tags --match="test1-*" --match="test3-*" HEAD -check_describe "test1-lightweight-*" --long --tags --match="test3-*" --match="test1-*" HEAD +check_describe "test1-lightweight-2-gHASH" --long --tags --match="test3-*" --match="test1-*" HEAD test_expect_success 'set-up branches' ' git branch branch_A A && @@ -215,11 +213,11 @@ test_expect_success 'set-up branches' ' git update-ref refs/original/original_branch_A test-annotated~2 ' -check_describe "heads/branch_A*" --all --match="branch_*" --exclude="branch_C" HEAD +check_describe "heads/branch_A-11-gHASH" --all --match="branch_*" --exclude="branch_C" HEAD -check_describe "remotes/origin/remote_branch_A*" --all --match="origin/remote_branch_*" --exclude="origin/remote_branch_C" HEAD +check_describe "remotes/origin/remote_branch_A-11-gHASH" --all --match="origin/remote_branch_*" --exclude="origin/remote_branch_C" HEAD -check_describe "original/original_branch_A*" --all test-annotated~1 +check_describe "original/original_branch_A-6-gHASH" --all test-annotated~1 test_expect_success '--match does not work for other types' ' test_must_fail git describe --all --match="*original_branch_*" test-annotated~1 @@ -489,7 +487,7 @@ test_expect_success 'describe commits with disjoint bases' ' git tag B -a -m B && git merge --no-ff --allow-unrelated-histories main -m x && - check_describe "A-3-*" HEAD + check_describe "A-3-gHASH" HEAD ) ' @@ -515,7 +513,7 @@ test_expect_success 'describe commits with disjoint bases 2' ' git tag B -a -m B && git merge --no-ff --allow-unrelated-histories main -m x && - check_describe "B-3-*" HEAD + check_describe "B-3-gHASH" HEAD ) ' From 7f07c1cdb7f46d2b0ec4468a90da7a4d697d2978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 12 Apr 2021 13:21:45 +0200 Subject: [PATCH 3/5] describe tests: don't rely on err.actual from "check_describe" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Convert the one test that relied on the "err.actual" file produced by check_describe() to instead do its own check of "git describe" output. This means that the two tests won't have an inter-dependency (e.g. if the earlier test is skipped). An earlier version of this patch instead asserted that no other test had any output on stderr. We're not doing that here out of fear that "gc --auto" or another future change to "git describe" will cause it to legitimately emit output on stderr unexpectedly[1]. I'd think that inverting the test added in 3291fe4072e (Add git-describe test for "verify annotated tag names on output", 2008-03-03) to make checking that we don't have warnings the rule rather than the exception would be the sort of thing the describe tests should be catching, but for now let's leave it as it is. 1. http://lore.kernel.org/git/xmqqwnuqo8ze.fsf@gitster.c.googlers.com Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t6120-describe.sh | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index 13117bbcfb..911b192805 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -21,7 +21,7 @@ check_describe () { shift describe_opts="$@" test_expect_success "describe $describe_opts" ' - git describe $describe_opts 2>err.actual >raw && + git describe $describe_opts >raw && sed -e "s/-g[0-9a-f]*\$/-gHASH/" actual && echo "$expect" >expect && test_cmp expect actual @@ -90,20 +90,17 @@ test_expect_success 'describe --contains defaults to HEAD without commit-ish' ' ' check_describe tags/A --all A^0 -test_expect_success 'no warning was displayed for A' ' - test_must_be_empty err.actual -' -test_expect_success 'rename tag A to Q locally' ' - mv .git/refs/tags/A .git/refs/tags/Q -' -cat - >err.expect <err >out && + cat >expected <<-\EOF && + warning: tag 'Q' is externally known as 'A' + EOF + test_cmp expected err && + grep -E '^A-8-g[0-9a-f]+$' out +" + test_expect_success 'misnamed annotated tag forces long output' ' description=$(git describe --no-long Q^0) && expr "$description" : "A-0-g[0-9a-f]*$" && From 33b4ae11146ba0c468176d238d231e1101ba19cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 12 Apr 2021 13:21:46 +0200 Subject: [PATCH 4/5] describe tests: fix nested "test_expect_success" call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix a nested invocation of "test_expect_success", the "check_describe()" function is a wrapper for calling test_expect_success, and therefore needs to be called outside the body of another "test_expect_success". The two tests added in 30b1c7ad9d6 (describe: don't abort too early when searching tags, 2020-02-26) were not testing for anything due to this logic error. Without this fix reverting the C code changes in that commit still has all tests passing, with this fix we're actually testing the "describe" output. This is because "test_expect_success" calls "test_finish_", whose last statement happens to be true. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t6120-describe.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index 911b192805..9dc07782ea 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -469,7 +469,7 @@ test_expect_success 'name-rev covers all conditions while looking at parents' ' # o-----o---o----x # A # -test_expect_success 'describe commits with disjoint bases' ' +test_expect_success 'setup: describe commits with disjoint bases' ' git init disjoint1 && ( cd disjoint1 && @@ -482,19 +482,22 @@ test_expect_success 'describe commits with disjoint bases' ' git checkout --orphan branch && rm file && echo B > file2 && git add file2 && git commit -m B && git tag B -a -m B && - git merge --no-ff --allow-unrelated-histories main -m x && - - check_describe "A-3-gHASH" HEAD + git merge --no-ff --allow-unrelated-histories main -m x ) ' +( + cd disjoint1 && + check_describe "A-3-gHASH" HEAD +) + # B # o---o---o------------. # \ # o---o---x # A # -test_expect_success 'describe commits with disjoint bases 2' ' +test_expect_success 'setup: describe commits with disjoint bases 2' ' git init disjoint2 && ( cd disjoint2 && @@ -508,10 +511,13 @@ test_expect_success 'describe commits with disjoint bases 2' ' echo o >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:01" git commit -m o && echo B >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:02" git commit -m B && git tag B -a -m B && - git merge --no-ff --allow-unrelated-histories main -m x && - - check_describe "B-3-gHASH" HEAD + git merge --no-ff --allow-unrelated-histories main -m x ) ' +( + cd disjoint2 && + check_describe "B-3-gHASH" HEAD +) + test_done From 64568c717159b31b5a37d2c1bb284c71e6cd011f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 12 Apr 2021 13:21:47 +0200 Subject: [PATCH 5/5] describe tests: support -C in "check_describe" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change a subshell added in a preceding commit to instead use a new "-C" option to "check_describe". The idiom for this is copied as-is from the "test_commit" function in test-lib-functions.sh Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t6120-describe.sh | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index 9dc07782ea..1a501ee09e 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -17,11 +17,26 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh check_describe () { + indir= && + while test $# != 0 + do + case "$1" in + -C) + indir="$2" + shift + ;; + *) + break + ;; + esac + shift + done && + indir=${indir:+"$indir"/} && expect="$1" shift describe_opts="$@" test_expect_success "describe $describe_opts" ' - git describe $describe_opts >raw && + git ${indir:+ -C "$indir"} describe $describe_opts >raw && sed -e "s/-g[0-9a-f]*\$/-gHASH/" actual && echo "$expect" >expect && test_cmp expect actual @@ -486,10 +501,7 @@ test_expect_success 'setup: describe commits with disjoint bases' ' ) ' -( - cd disjoint1 && - check_describe "A-3-gHASH" HEAD -) +check_describe -C disjoint1 "A-3-gHASH" HEAD # B # o---o---o------------. @@ -515,9 +527,6 @@ test_expect_success 'setup: describe commits with disjoint bases 2' ' ) ' -( - cd disjoint2 && - check_describe "B-3-gHASH" HEAD -) +check_describe -C disjoint2 "B-3-gHASH" HEAD test_done