describe tests: refactor away from glob matching

Change the glob matching via a "case" statement to a "test_cmp" after we've stripped out the hash-specific g<hash-abbrev> 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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Apr 12, 2021 at 13:21 UTC a46a84829650fbe6077e5a33f4ac1c9d2041d1df
1 file changed +38 -40
t/t6120-describe.sh
+38 -40
@@ -21,12 +21,10 @@ check_describe () {
21 shift
22 describe_opts="$@"
23 test_expect_success "describe $describe_opts" '
24 - R=$(git describe $describe_opts 2>err.actual) &&
25 - case "$R" in
26 - $expect) echo happy ;;
27 - *) echo "Oops - $R is not $expect" &&
28 - false ;;
29 - esac
24 + git describe $describe_opts 2>err.actual >raw &&
25 + sed -e "s/-g[0-9a-f]*\$/-gHASH/" <raw >actual &&
26 + echo "$expect" >expect &&
27 + test_cmp expect actual
28 '
29 }
30
@@ -59,29 +57,29 @@ test_expect_success setup '
57 test_commit --no-tag x file
58 '
59
62 -check_describe A-* HEAD
63 -check_describe A-* HEAD^
64 -check_describe R-* HEAD^^
65 -check_describe A-* HEAD^^2
60 +check_describe A-8-gHASH HEAD
61 +check_describe A-7-gHASH HEAD^
62 +check_describe R-2-gHASH HEAD^^
63 +check_describe A-3-gHASH HEAD^^2
64 check_describe B HEAD^^2^
67 -check_describe R-* HEAD^^^
65 +check_describe R-1-gHASH HEAD^^^
66
69 -check_describe c-* --tags HEAD
70 -check_describe c-* --tags HEAD^
71 -check_describe e-* --tags HEAD^^
72 -check_describe c-* --tags HEAD^^2
67 +check_describe c-7-gHASH --tags HEAD
68 +check_describe c-6-gHASH --tags HEAD^
69 +check_describe e-1-gHASH --tags HEAD^^
70 +check_describe c-2-gHASH --tags HEAD^^2
71 check_describe B --tags HEAD^^2^
72 check_describe e --tags HEAD^^^
73
74 check_describe heads/main --all HEAD
77 -check_describe tags/c-* --all HEAD^
75 +check_describe tags/c-6-gHASH --all HEAD^
76 check_describe tags/e --all HEAD^^^
77
80 -check_describe B-0-* --long HEAD^^2^
81 -check_describe A-3-* --long HEAD^^2
78 +check_describe B-0-gHASH --long HEAD^^2^
79 +check_describe A-3-gHASH --long HEAD^^2
80
83 -check_describe c-7-* --tags
84 -check_describe e-3-* --first-parent --tags
81 +check_describe c-7-gHASH --tags
82 +check_describe e-3-gHASH --first-parent --tags
83
84 test_expect_success 'describe --contains defaults to HEAD without commit-ish' '
85 echo "A^0" >expect &&
@@ -102,7 +100,7 @@ test_expect_success 'rename tag A to Q locally' '
100 cat - >err.expect <<EOF
101 warning: tag 'Q' is externally known as 'A'
102 EOF
105 -check_describe A-* HEAD
103 +check_describe A-8-gHASH HEAD
104 test_expect_success 'warning was displayed for Q' '
105 test_cmp err.expect err.actual
106 '
@@ -129,22 +127,22 @@ test_expect_success 'rename tag Q back to A' '
127 '
128
129 test_expect_success 'pack tag refs' 'git pack-refs'
132 -check_describe A-* HEAD
130 +check_describe A-8-gHASH HEAD
131
132 test_expect_success 'describe works from outside repo using --git-dir' '
133 git clone --bare "$TRASH_DIRECTORY" "$TRASH_DIRECTORY/bare" &&
134 git --git-dir "$TRASH_DIRECTORY/bare" describe >out &&
137 - grep -E "^A-[1-9][0-9]?-g[0-9a-f]+$" out
135 + grep -E "^A-8-g[0-9a-f]+$" out
136 '
137
140 -check_describe "A-*[0-9a-f]" --dirty
138 +check_describe "A-8-gHASH" --dirty
139
140 test_expect_success 'describe --dirty with --work-tree' '
141 (
142 cd "$TEST_DIRECTORY" &&
143 git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
144 ) &&
147 - grep -E "^A-[1-9][0-9]?-g[0-9a-f]+$" out
145 + grep -E "^A-8-g[0-9a-f]+$" out
146 '
147
148 test_expect_success 'set-up dirty work tree' '
@@ -157,7 +155,7 @@ test_expect_success 'describe --dirty with --work-tree (dirty)' '
155 cd "$TEST_DIRECTORY" &&
156 git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
157 ) &&
160 - grep -E "^A-[1-9][0-9]?-g[0-9a-f]+-dirty$" out &&
158 + grep -E "^A-8-g[0-9a-f]+-dirty$" out &&
159 test_cmp expected out
160 '
161
@@ -167,7 +165,7 @@ test_expect_success 'describe --dirty=.mod with --work-tree (dirty)' '
165 cd "$TEST_DIRECTORY" &&
166 git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty=.mod >"$TRASH_DIRECTORY/out"
167 ) &&
170 - grep -E "^A-[1-9][0-9]?-g[0-9a-f]+.mod$" out &&
168 + grep -E "^A-8-g[0-9a-f]+.mod$" out &&
169 test_cmp expected out
170 '
171
@@ -191,21 +189,21 @@ test_expect_success 'set-up matching pattern tests' '
189
190 '
191
194 -check_describe "test-annotated-*" --match="test-*"
192 +check_describe "test-annotated-3-gHASH" --match="test-*"
193
196 -check_describe "test1-lightweight-*" --tags --match="test1-*"
194 +check_describe "test1-lightweight-2-gHASH" --tags --match="test1-*"
195
198 -check_describe "test2-lightweight-*" --tags --match="test2-*"
196 +check_describe "test2-lightweight-1-gHASH" --tags --match="test2-*"
197
200 -check_describe "test2-lightweight-*" --long --tags --match="test2-*" HEAD^
198 +check_describe "test2-lightweight-0-gHASH" --long --tags --match="test2-*" HEAD^
199
202 -check_describe "test2-lightweight-*" --long --tags --match="test1-*" --match="test2-*" HEAD^
200 +check_describe "test2-lightweight-0-gHASH" --long --tags --match="test1-*" --match="test2-*" HEAD^
201
204 -check_describe "test2-lightweight-*" --long --tags --match="test1-*" --no-match --match="test2-*" HEAD^
202 +check_describe "test2-lightweight-0-gHASH" --long --tags --match="test1-*" --no-match --match="test2-*" HEAD^
203
206 -check_describe "test1-lightweight-*" --long --tags --match="test1-*" --match="test3-*" HEAD
204 +check_describe "test1-lightweight-2-gHASH" --long --tags --match="test1-*" --match="test3-*" HEAD
205
208 -check_describe "test1-lightweight-*" --long --tags --match="test3-*" --match="test1-*" HEAD
206 +check_describe "test1-lightweight-2-gHASH" --long --tags --match="test3-*" --match="test1-*" HEAD
207
208 test_expect_success 'set-up branches' '
209 git branch branch_A A &&
@@ -215,11 +213,11 @@ test_expect_success 'set-up branches' '
213 git update-ref refs/original/original_branch_A test-annotated~2
214 '
215
218 -check_describe "heads/branch_A*" --all --match="branch_*" --exclude="branch_C" HEAD
216 +check_describe "heads/branch_A-11-gHASH" --all --match="branch_*" --exclude="branch_C" HEAD
217
220 -check_describe "remotes/origin/remote_branch_A*" --all --match="origin/remote_branch_*" --exclude="origin/remote_branch_C" HEAD
218 +check_describe "remotes/origin/remote_branch_A-11-gHASH" --all --match="origin/remote_branch_*" --exclude="origin/remote_branch_C" HEAD
219
222 -check_describe "original/original_branch_A*" --all test-annotated~1
220 +check_describe "original/original_branch_A-6-gHASH" --all test-annotated~1
221
222 test_expect_success '--match does not work for other types' '
223 test_must_fail git describe --all --match="*original_branch_*" test-annotated~1
@@ -489,7 +487,7 @@ test_expect_success 'describe commits with disjoint bases' '
487 git tag B -a -m B &&
488 git merge --no-ff --allow-unrelated-histories main -m x &&
489
492 - check_describe "A-3-*" HEAD
490 + check_describe "A-3-gHASH" HEAD
491 )
492 '
493
@@ -515,7 +513,7 @@ test_expect_success 'describe commits with disjoint bases 2' '
513 git tag B -a -m B &&
514 git merge --no-ff --allow-unrelated-histories main -m x &&
515
518 - check_describe "B-3-*" HEAD
516 + check_describe "B-3-gHASH" HEAD
517 )
518 '
519