Skip to content

Commit 3cc43bf

Browse files
committed
Merge branch 'ab/mktag-tests'
Fill test gaps. * ab/mktag-tests: mktag tests: test fast-export mktag tests: test for-each-ref mktag tests: test update-ref and reachable fsck mktag tests: test hash-object --literally and unreachable fsck mktag tests: invert --no-strict test mktag tests: parse out options in helper
2 parents 1fb3445 + 2f61b3e commit 3cc43bf

File tree

1 file changed

+106
-15
lines changed

1 file changed

+106
-15
lines changed

t/t3800-mktag.sh

Lines changed: 106 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,93 @@ test_description='git mktag: tag object verify test'
1212
# given in the expect.pat file.
1313

1414
check_verify_failure () {
15-
test_expect_success "$1" "
16-
test_must_fail git mktag <tag.sig 2>message &&
17-
grep '$2' message &&
18-
if test '$3' != '--no-strict'
15+
subject=$1 &&
16+
message=$2 &&
17+
shift 2 &&
18+
19+
no_strict= &&
20+
fsck_obj_ok= &&
21+
no_strict= &&
22+
while test $# != 0
23+
do
24+
case "$1" in
25+
--no-strict)
26+
no_strict=yes
27+
;;
28+
--fsck-obj-ok)
29+
fsck_obj_ok=yes
30+
;;
31+
esac &&
32+
shift
33+
done &&
34+
35+
test_expect_success "fail with [--[no-]strict]: $subject" '
36+
test_must_fail git mktag <tag.sig 2>err &&
37+
if test -z "$no_strict"
1938
then
20-
test_must_fail git mktag --no-strict <tag.sig 2>message.no-strict &&
21-
grep '$2' message.no-strict
39+
test_must_fail git mktag <tag.sig 2>err2 &&
40+
test_cmp err err2
41+
else
42+
git mktag --no-strict <tag.sig
2243
fi
23-
"
44+
'
45+
46+
test_expect_success "setup: $subject" '
47+
tag_ref=refs/tags/bad_tag &&
48+
49+
# Reset any leftover state from the last $subject
50+
rm -rf bad-tag &&
51+
52+
git init --bare bad-tag &&
53+
bad_tag=$(git -C bad-tag hash-object -t tag -w --stdin --literally <tag.sig)
54+
'
55+
56+
test_expect_success "hash-object & fsck unreachable: $subject" '
57+
if test -n "$fsck_obj_ok"
58+
then
59+
git -C bad-tag fsck
60+
else
61+
test_must_fail git -C bad-tag fsck
62+
fi
63+
'
64+
65+
test_expect_success "update-ref & fsck reachable: $subject" '
66+
# Make sure the earlier test created it for us
67+
git rev-parse "$bad_tag" &&
68+
69+
# The update-ref of the bad content will fail, do it
70+
# anyway to see if it segfaults
71+
test_might_fail git -C bad-tag update-ref "$tag_ref" "$bad_tag" &&
72+
73+
# Manually create the broken, we cannot do it with
74+
# update-ref
75+
echo "$bad_tag" >"bad-tag/$tag_ref" &&
76+
77+
# Unlike fsck-ing unreachable content above, this
78+
# will always fail.
79+
test_must_fail git -C bad-tag fsck
80+
'
81+
82+
test_expect_success "for-each-ref: $subject" '
83+
# Make sure the earlier test created it for us
84+
git rev-parse "$bad_tag" &&
85+
86+
echo "$bad_tag" >"bad-tag/$tag_ref" &&
87+
88+
printf "%s tag\t%s\n" "$bad_tag" "$tag_ref" >expected &&
89+
git -C bad-tag for-each-ref "$tag_ref" >actual &&
90+
test_cmp expected actual &&
91+
92+
test_must_fail git -C bad-tag for-each-ref --format="%(*objectname)"
93+
'
94+
95+
test_expect_success "fast-export & fast-import: $subject" '
96+
# Make sure the earlier test created it for us
97+
git rev-parse "$bad_tag" &&
98+
99+
test_must_fail git -C bad-tag fast-export --all &&
100+
test_must_fail git -C bad-tag fast-export "$bad_tag"
101+
'
24102
}
25103

26104
test_expect_mktag_success() {
@@ -167,7 +245,8 @@ tagger . <> 0 +0000
167245
EOF
168246

169247
check_verify_failure 'verify object (hash/type) check -- correct type, nonexisting object' \
170-
'^fatal: could not read tagged object'
248+
'^fatal: could not read tagged object' \
249+
--fsck-obj-ok
171250

172251
cat >tag.sig <<EOF
173252
object $head
@@ -200,7 +279,8 @@ tagger . <> 0 +0000
200279
EOF
201280

202281
check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \
203-
'^fatal: object.*tagged as.*tree.*but is.*commit'
282+
'^fatal: object.*tagged as.*tree.*but is.*commit' \
283+
--fsck-obj-ok
204284

205285
############################################################
206286
# 9.5. verify object (hash/type) check -- replacement
@@ -229,7 +309,8 @@ tagger . <> 0 +0000
229309
EOF
230310

231311
check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \
232-
'^fatal: object.*tagged as.*tree.*but is.*blob'
312+
'^fatal: object.*tagged as.*tree.*but is.*blob' \
313+
--fsck-obj-ok
233314

234315
############################################################
235316
# 10. verify tag-name check
@@ -243,7 +324,9 @@ tagger . <> 0 +0000
243324
EOF
244325

245326
check_verify_failure 'verify tag-name check' \
246-
'^error:.* badTagName:' '--no-strict'
327+
'^error:.* badTagName:' \
328+
--no-strict \
329+
--fsck-obj-ok
247330

248331
############################################################
249332
# 11. tagger line label check #1
@@ -257,7 +340,9 @@ This is filler
257340
EOF
258341

259342
check_verify_failure '"tagger" line label check #1' \
260-
'^error:.* missingTaggerEntry:' '--no-strict'
343+
'^error:.* missingTaggerEntry:' \
344+
--no-strict \
345+
--fsck-obj-ok
261346

262347
############################################################
263348
# 12. tagger line label check #2
@@ -272,7 +357,9 @@ This is filler
272357
EOF
273358

274359
check_verify_failure '"tagger" line label check #2' \
275-
'^error:.* missingTaggerEntry:' '--no-strict'
360+
'^error:.* missingTaggerEntry:' \
361+
--no-strict \
362+
--fsck-obj-ok
276363

277364
############################################################
278365
# 13. allow missing tag author name like fsck
@@ -301,7 +388,9 @@ tagger T A Gger <
301388
EOF
302389

303390
check_verify_failure 'disallow malformed tagger' \
304-
'^error:.* badEmail:' '--no-strict'
391+
'^error:.* badEmail:' \
392+
--no-strict \
393+
--fsck-obj-ok
305394

306395
############################################################
307396
# 15. allow empty tag email
@@ -425,7 +514,9 @@ this line should not be here
425514
EOF
426515

427516
check_verify_failure 'detect invalid header entry' \
428-
'^error:.* extraHeaderEntry:' '--no-strict'
517+
'^error:.* extraHeaderEntry:' \
518+
--no-strict \
519+
--fsck-obj-ok
429520

430521
test_expect_success 'invalid header entry config & fsck' '
431522
test_must_fail git mktag <tag.sig &&

0 commit comments

Comments
 (0)