[RFC/REVIEW 2/7] ls-tree tests: exhaustively test fast & slow path for --format

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Change these tests adapted from my initial version in [1] to
exhaustively test both the fast and slow paths of --format.

In [1] there was a "GIT_TEST_LS_TREE_FORMAT_BACKEND" variable to
ensure that we had test coverage for passing tests that would
otherwise use show_tree() through show_tree_fmt(), and thus that the
formatting mechanism could handle all the same cases as the
non-formatting options.

Somewhere in subsequent re-rolls of that we seem to have drifted away
from what the goal of these tests should be. We're trying to ensure
correctness of show_tree_fmt(). We can't tell if we "hit [the]
fast-path" here, and instead of having an explicit test for that, we
can just add it to something our "test_ls_tree_format" tests for.

1. https://lore.kernel.org/git/RFC-patch-6.7-eac299f06ff-20211217T131635Z-avarab@xxxxxxxxx/
2. https://lore.kernel.org/git/cb717d08be87e3239117c6c667cb32caabaad33d.1646390152.git.dyroneteng@xxxxxxxxx/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx>
---
 t/t3104-ls-tree-format.sh | 89 +++++++++++++++------------------------
 1 file changed, 33 insertions(+), 56 deletions(-)

diff --git a/t/t3104-ls-tree-format.sh b/t/t3104-ls-tree-format.sh
index b86941c2024..12105115eaf 100755
--- a/t/t3104-ls-tree-format.sh
+++ b/t/t3104-ls-tree-format.sh
@@ -22,79 +22,56 @@ test_ls_tree_format () {
 	opts=$2 &&
 	fmtopts=$3 &&
 	shift 2 &&
-	git ls-tree $opts -r HEAD >expect.raw &&
-	sed "s/^/> /" >expect <expect.raw &&
-	git ls-tree --format="> $format" -r $fmtopts HEAD >actual &&
-	test_cmp expect actual
+
+	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_expect_success 'ls-tree --format=<default-like>' '
-	test_ls_tree_format \
-		"%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
-		""
-'
+test_ls_tree_format \
+	"%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
+	""
 
-test_expect_success 'ls-tree --format=<long-like>' '
-	test_ls_tree_format \
-		"%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)" \
-		"--long"
-'
+test_ls_tree_format \
+	"%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)" \
+	"--long"
 
-test_expect_success 'ls-tree --format=<name-only-like>' '
-	test_ls_tree_format \
-		"%(path)" \
-		"--name-only"
-'
+test_ls_tree_format \
+	"%(path)" \
+	"--name-only"
 
-test_expect_success 'ls-tree --format=<object-only-like>' '
-	test_ls_tree_format \
-		"%(objectname)" \
-		"--object-only"
-'
+test_ls_tree_format \
+	"%(objectname)" \
+	"--object-only"
+
+test_ls_tree_format \
+	"%(objectname)" \
+	"--object-only --abbrev" \
+	"--abbrev"
 
-test_expect_success 'ls-tree --format=<object-only-like> --abbrev' '
-	test_ls_tree_format \
-		"%(objectname)" \
-		"--object-only --abbrev" \
-		"--abbrev"
-'
 
-test_expect_success 'ls-tree combine --format=<default-like> and -t' '
-	test_ls_tree_format \
+test_ls_tree_format \
 	"%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
 	"-t" \
 	"-t"
-'
 
-test_expect_success 'ls-tree combine --format=<default-like> and --full-name' '
-	test_ls_tree_format \
+test_ls_tree_format \
 	"%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
 	"--full-name" \
 	"--full-name"
-'
 
-test_expect_success 'ls-tree combine --format=<default-like> and --full-tree' '
-	test_ls_tree_format \
+test_ls_tree_format \
 	"%(objectmode) %(objecttype) %(objectname)%x09%(path)" \
 	"--full-tree" \
 	"--full-tree"
-'
-
-test_expect_success 'ls-tree hit fast-path with --format=<default-like>' '
-	git ls-tree -r HEAD >expect &&
-	git ls-tree --format="%(objectmode) %(objecttype) %(objectname)%x09%(path)" -r HEAD >actual &&
-	test_cmp expect actual
-'
-
-test_expect_success 'ls-tree hit fast-path with --format=<name-only-like>' '
-	git ls-tree -r --name-only HEAD >expect &&
-	git ls-tree --format="%(path)" -r HEAD >actual &&
-	test_cmp expect actual
-'
 
-test_expect_success 'ls-tree hit fast-path with --format=<object-only-like>' '
-	git ls-tree -r --object-only HEAD >expect &&
-	git ls-tree --format="%(objectname)" -r HEAD >actual &&
-	test_cmp expect actual
-'
 test_done
-- 
2.35.1.1295.g6b025d3e231




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux