Skip to content

Commit fc12aa7

Browse files
rscharfegitster
authored andcommitted
t1450: increase test coverage of in-tree d/f detection
Exercise the case of putting a conflict candidate file name back on the stack because a matching directory might yet come up later. Do that by factoring out the test code into a function to allow for more concise notation in the form of parameters indicating names of trees (with trailing slash) and blobs (without trailing slash) in no particular order (they are sorted by git mktree). Then add the new test case as a second function call. Fix a typo in the test title while at it ("dublicate"). Reported-by: Derrick Stolee <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8671559 commit fc12aa7

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

t/t1450-fsck.sh

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -234,21 +234,33 @@ test_expect_success 'tree object with duplicate entries' '
234234
test_i18ngrep "error in tree .*contains duplicate file entries" out
235235
'
236236

237-
test_expect_success 'tree object with dublicate names' '
238-
test_when_finished "remove_object \$blob" &&
239-
test_when_finished "remove_object \$tree" &&
240-
test_when_finished "remove_object \$badtree" &&
241-
blob=$(echo blob | git hash-object -w --stdin) &&
242-
printf "100644 blob %s\t%s\n" $blob x.2 >tree &&
243-
tree=$(git mktree <tree) &&
244-
printf "100644 blob %s\t%s\n" $blob x.1 >badtree &&
245-
printf "100644 blob %s\t%s\n" $blob x >>badtree &&
246-
printf "040000 tree %s\t%s\n" $tree x >>badtree &&
247-
badtree=$(git mktree <badtree) &&
248-
test_must_fail git fsck 2>out &&
249-
test_i18ngrep "$badtree" out &&
250-
test_i18ngrep "error in tree .*contains duplicate file entries" out
251-
'
237+
check_duplicate_names () {
238+
expect=$1 &&
239+
shift &&
240+
names=$@ &&
241+
test_expect_$expect "tree object with duplicate names: $names" '
242+
test_when_finished "remove_object \$blob" &&
243+
test_when_finished "remove_object \$tree" &&
244+
test_when_finished "remove_object \$badtree" &&
245+
blob=$(echo blob | git hash-object -w --stdin) &&
246+
printf "100644 blob %s\t%s\n" $blob x.2 >tree &&
247+
tree=$(git mktree <tree) &&
248+
for name in $names
249+
do
250+
case "$name" in
251+
*/) printf "040000 tree %s\t%s\n" $tree "${name%/}" ;;
252+
*) printf "100644 blob %s\t%s\n" $blob "$name" ;;
253+
esac
254+
done >badtree &&
255+
badtree=$(git mktree <badtree) &&
256+
test_must_fail git fsck 2>out &&
257+
test_i18ngrep "$badtree" out &&
258+
test_i18ngrep "error in tree .*contains duplicate file entries" out
259+
'
260+
}
261+
262+
check_duplicate_names success x x.1 x/
263+
check_duplicate_names success x x.1.2 x.1/ x/
252264

253265
test_expect_success 'unparseable tree object' '
254266
test_oid_cache <<-\EOF &&

0 commit comments

Comments
 (0)