git-commit-vandalism/t/t3104-ls-tree-format.sh
Ævar Arnfjörð Bjarmason 1d232d38bd ls-tree: test for the regression in 9c4d58ff2c
Add a test for the regression introduced in my 9c4d58ff2c (ls-tree:
split up "fast path" callbacks, 2022-03-23) and fixed in
350296cc78 (ls-tree: `-l` should not imply recursive listing,
2022-04-04), and test for the test of ls-tree option/mode combinations
to make sure we don't have other blind spots.

The setup for these tests can be shared with those added in the
1041d58b4d (Merge branch 'tl/ls-tree-oid-only', 2022-04-04) topic, so
let's create a new t/lib-t3100.sh to help them share data.

The existing tests in "t3104-ls-tree-format.sh" didn't deal with a
submodule, which they'll now encounter with as the
setup_basic_ls_tree_data() sets one up.

This extensive testing should give us confidence that there were no
further regressions in this area. The lack of testing was noted back
in [1], but unfortunately we didn't cover that blind-spot before
9c4d58ff2c.

1. https://lore.kernel.org/git/211115.86o86lqe3c.gmgdl@evledraar.gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-06-03 09:47:11 -07:00

76 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
test_description='ls-tree --format'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-t3100.sh
test_expect_success 'ls-tree --format usage' '
test_expect_code 129 git ls-tree --format=fmt -l HEAD &&
test_expect_code 129 git ls-tree --format=fmt --name-only HEAD &&
test_expect_code 129 git ls-tree --format=fmt --name-status HEAD
'
test_expect_success 'setup' '
setup_basic_ls_tree_data
'
test_ls_tree_format () {
format=$1 &&
opts=$2 &&
fmtopts=$3 &&
shift 2 &&
test_expect_success "ls-tree '--format=<$format>' is like options '$opts $fmtopts'" '
git ls-tree $opts -r HEAD >expect &&
git ls-tree --format="$format" -r $fmtopts HEAD >actual &&
test_cmp expect actual
'
test_expect_success "ls-tree '--format=<$format>' on optimized v.s. non-optimized path" '
git ls-tree --format="$format" -r $fmtopts HEAD >expect &&
git ls-tree --format="> $format" -r $fmtopts HEAD >actual.raw &&
sed "s/^> //" >actual <actual.raw &&
test_cmp expect actual
'
}
test_ls_tree_format \
"%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
""
test_ls_tree_format \
"%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)" \
"--long"
test_ls_tree_format \
"%(path)" \
"--name-only"
test_ls_tree_format \
"%(objectname)" \
"--object-only"
test_ls_tree_format \
"%(objectname)" \
"--object-only --abbrev" \
"--abbrev"
test_ls_tree_format \
"%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
"-t" \
"-t"
test_ls_tree_format \
"%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
"--full-name" \
"--full-name"
test_ls_tree_format \
"%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
"--full-tree" \
"--full-tree"
test_done