diff mbox series

[RFC] Sample of test for git branch -vv

Message ID 20190202012210.46950-1-nbelakovski@gmail.com (mailing list archive)
State New, archived
Headers show
Series [RFC] Sample of test for git branch -vv | expand

Commit Message

Nickolai Belakovski Feb. 2, 2019, 1:22 a.m. UTC
From: Nickolai Belakovski <nbelakovski@gmail.com>

I remember now why I didn't add a test for this one earlier.

Testing git branch -vv is a little tricky for a couple reasons.

For one thing, the output contains commit hashes, so the 'expect' file cannot be simply static.

For another, the output doesn't have clear delimiters for all columns, so trying to extract only
the commit hashes is tough.

I took the approach of stripping all information before and including the commit hashes.

You can see below how I did this. For the patch with worktreepath information, the worktreepath would
appear before the commit message on just one of those lines, but I crafted this patch so that it can be applied
to master.

This works, but it's rather awkward and ugly. Does anyone have better suggestions either for how to test or
how to implement?

---
 t/t3203-branch-output.sh | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index 94ab05ad59..b836ca21fa 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -285,4 +284,22 @@  test_expect_success '--color overrides auto-color' '
 	test_cmp expect.color actual
 '
 
+test_expect_success 'test verbose verbose output' '
+	cat >expect <<-EOF &&
+	one
+	one
+	two
+	one
+	two
+	two
+	two
+	EOF
+	git branch -vv >tmp &&
+	head -1 tmp >tmp2 &&
+	SUBSTRLENGTH=$(awk "{print index(\$0, \"one\")}" <tmp2) &&
+	awk -v len="$SUBSTRLENGTH" "{print substr(\$0,len,length(\$0))}" <tmp >actual &&
+	test_cmp expect actual
+'
+
+
 test_done