Skip to content

Commit a46a848

Browse files
avargitster
authored andcommitted
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. 5312ab1 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2df546e commit a46a848

File tree

1 file changed

+38
-40
lines changed

1 file changed

+38
-40
lines changed

t/t6120-describe.sh

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ check_describe () {
2121
shift
2222
describe_opts="$@"
2323
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
3028
'
3129
}
3230

@@ -59,29 +57,29 @@ test_expect_success setup '
5957
test_commit --no-tag x file
6058
'
6159

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
6664
check_describe B HEAD^^2^
67-
check_describe R-* HEAD^^^
65+
check_describe R-1-gHASH HEAD^^^
6866

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
7371
check_describe B --tags HEAD^^2^
7472
check_describe e --tags HEAD^^^
7573

7674
check_describe heads/main --all HEAD
77-
check_describe tags/c-* --all HEAD^
75+
check_describe tags/c-6-gHASH --all HEAD^
7876
check_describe tags/e --all HEAD^^^
7977

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
8280

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
8583

8684
test_expect_success 'describe --contains defaults to HEAD without commit-ish' '
8785
echo "A^0" >expect &&
@@ -102,7 +100,7 @@ test_expect_success 'rename tag A to Q locally' '
102100
cat - >err.expect <<EOF
103101
warning: tag 'Q' is externally known as 'A'
104102
EOF
105-
check_describe A-* HEAD
103+
check_describe A-8-gHASH HEAD
106104
test_expect_success 'warning was displayed for Q' '
107105
test_cmp err.expect err.actual
108106
'
@@ -129,22 +127,22 @@ test_expect_success 'rename tag Q back to A' '
129127
'
130128

131129
test_expect_success 'pack tag refs' 'git pack-refs'
132-
check_describe A-* HEAD
130+
check_describe A-8-gHASH HEAD
133131

134132
test_expect_success 'describe works from outside repo using --git-dir' '
135133
git clone --bare "$TRASH_DIRECTORY" "$TRASH_DIRECTORY/bare" &&
136134
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
138136
'
139137

140-
check_describe "A-*[0-9a-f]" --dirty
138+
check_describe "A-8-gHASH" --dirty
141139

142140
test_expect_success 'describe --dirty with --work-tree' '
143141
(
144142
cd "$TEST_DIRECTORY" &&
145143
git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
146144
) &&
147-
grep -E "^A-[1-9][0-9]?-g[0-9a-f]+$" out
145+
grep -E "^A-8-g[0-9a-f]+$" out
148146
'
149147

150148
test_expect_success 'set-up dirty work tree' '
@@ -157,7 +155,7 @@ test_expect_success 'describe --dirty with --work-tree (dirty)' '
157155
cd "$TEST_DIRECTORY" &&
158156
git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
159157
) &&
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 &&
161159
test_cmp expected out
162160
'
163161

@@ -167,7 +165,7 @@ test_expect_success 'describe --dirty=.mod with --work-tree (dirty)' '
167165
cd "$TEST_DIRECTORY" &&
168166
git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty=.mod >"$TRASH_DIRECTORY/out"
169167
) &&
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 &&
171169
test_cmp expected out
172170
'
173171

@@ -191,21 +189,21 @@ test_expect_success 'set-up matching pattern tests' '
191189
192190
'
193191

194-
check_describe "test-annotated-*" --match="test-*"
192+
check_describe "test-annotated-3-gHASH" --match="test-*"
195193

196-
check_describe "test1-lightweight-*" --tags --match="test1-*"
194+
check_describe "test1-lightweight-2-gHASH" --tags --match="test1-*"
197195

198-
check_describe "test2-lightweight-*" --tags --match="test2-*"
196+
check_describe "test2-lightweight-1-gHASH" --tags --match="test2-*"
199197

200-
check_describe "test2-lightweight-*" --long --tags --match="test2-*" HEAD^
198+
check_describe "test2-lightweight-0-gHASH" --long --tags --match="test2-*" HEAD^
201199

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^
203201

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^
205203

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
207205

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
209207

210208
test_expect_success 'set-up branches' '
211209
git branch branch_A A &&
@@ -215,11 +213,11 @@ test_expect_success 'set-up branches' '
215213
git update-ref refs/original/original_branch_A test-annotated~2
216214
'
217215

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
219217

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
221219

222-
check_describe "original/original_branch_A*" --all test-annotated~1
220+
check_describe "original/original_branch_A-6-gHASH" --all test-annotated~1
223221

224222
test_expect_success '--match does not work for other types' '
225223
test_must_fail git describe --all --match="*original_branch_*" test-annotated~1
@@ -489,7 +487,7 @@ test_expect_success 'describe commits with disjoint bases' '
489487
git tag B -a -m B &&
490488
git merge --no-ff --allow-unrelated-histories main -m x &&
491489
492-
check_describe "A-3-*" HEAD
490+
check_describe "A-3-gHASH" HEAD
493491
)
494492
'
495493

@@ -515,7 +513,7 @@ test_expect_success 'describe commits with disjoint bases 2' '
515513
git tag B -a -m B &&
516514
git merge --no-ff --allow-unrelated-histories main -m x &&
517515
518-
check_describe "B-3-*" HEAD
516+
check_describe "B-3-gHASH" HEAD
519517
)
520518
'
521519

0 commit comments

Comments
 (0)