Skip to content

Commit 30f882c

Browse files
avargitster
authored andcommitted
mktag tests: improve verify_object() test coverage
The verify_object() function in "mktag.c" is tasked with ensuring that our tag refers to a valid object. The existing test for this might fail because it was also testing that "type taggg" didn't refer to a valid object type (it should be "type tag"), or because we referred to a valid object but got the type wrong. Let's split these tests up, so we're testing all combinations of a non-existing object and in invalid/wrong "type" lines. We need to provide GIT_TEST_GETTEXT_POISON=false here because the "invalid object type" error is emitted by parse_loose_header_extended(), which has that message already marked for translation. Another option would be to use test_i18ngrep, but I prefer always running the test, not skipping it under gettext poison testing. I'm not testing this in combination with "git replace". That'll be done in a subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ca9a1ed commit 30f882c

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

t/t3800-mktag.sh

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ test_description='git mktag: tag object verify test'
1414
check_verify_failure () {
1515
expect="$2"
1616
test_expect_success "$1" '
17-
test_must_fail git mktag <tag.sig 2>message &&
17+
test_must_fail env GIT_TEST_GETTEXT_POISON=false \
18+
git mktag <tag.sig 2>message &&
1819
grep "$expect" message
1920
'
2021
}
@@ -136,19 +137,52 @@ check_verify_failure '"type" line type-name length check' \
136137
'^error: char.*: type too long$'
137138

138139
############################################################
139-
# 9. verify object (SHA1/type) check
140+
# 9. verify object (hash/type) check
140141

141142
cat >tag.sig <<EOF
142143
object $(test_oid deadbeef)
144+
type tag
145+
tag mytag
146+
tagger . <> 0 +0000
147+
148+
EOF
149+
150+
check_verify_failure 'verify object (hash/type) check -- correct type, nonexisting object' \
151+
'^error: char7: could not verify object.*$'
152+
153+
cat >tag.sig <<EOF
154+
object $head
143155
type tagggg
144156
tag mytag
145157
tagger . <> 0 +0000
146158
147159
EOF
148160

149-
check_verify_failure 'verify object (SHA1/type) check' \
161+
check_verify_failure 'verify object (hash/type) check -- made-up type, valid object' \
162+
'^fatal: invalid object type'
163+
164+
cat >tag.sig <<EOF
165+
object $(test_oid deadbeef)
166+
type tagggg
167+
tag mytag
168+
tagger . <> 0 +0000
169+
170+
EOF
171+
172+
check_verify_failure 'verify object (hash/type) check -- made-up type, nonexisting object' \
150173
'^error: char7: could not verify object.*$'
151174

175+
cat >tag.sig <<EOF
176+
object $head
177+
type tree
178+
tag mytag
179+
tagger . <> 0 +0000
180+
181+
EOF
182+
183+
check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \
184+
'^error: char7: could not verify object'
185+
152186
############################################################
153187
# 10. verify tag-name check
154188

0 commit comments

Comments
 (0)