Thread (4 messages) flat view 4 messages, 4 authors, 2016-06-15

Re: [PATCH] t6022: Use -eq not = to test output of wc -l

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:50:03
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)

Johannes Sixt wrote:
- It doesn't save any messages or fix-ups during review: instead of "do
not quote!" we have to say "use test_line_count!".
I was nervous about introducing test_line_count for that reason.

Another consideration won out: not syntax but output format.  See
cae3aa79 (t6022 (renaming merge): chain test commands with &&,
2010-10-31).  Kind of analogous to test_cmp, which is a similar
headache to get used over less portable or less pleasant alternatives.

If a piped variant is needed, I would prefer it to work something
like this.  Usage:

	{
		command_producing_five_lines |
		test_line_count = 5 -
	}

Signed-off-by: Jonathan Nieder <redacted>
---
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 1ea0116..35a5634 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -660,15 +660,24 @@ test_path_is_missing () {
 # output through when the number of lines is wrong.
 
 test_line_count () {
+	line_count_tmp=
 	if test $# != 3
 	then
 		error "bug in the test script: not 3 parameters to test_line_count"
-	elif ! test $(wc -l <"$3") "$1" "$2"
+	fi
+	if test "$3" = -
+	then
+		line_count_tmp=test_line_count.output
+		cat >"$line_count_tmp"
+		set -- "$1" "$2" "$line_count_tmp"
+	fi
+	if ! test $(wc -l <"$3") "$1" "$2"
 	then
 		echo "test_line_count: line count for $3 !$1 $2"
 		cat "$3"
 		return 1
 	fi
+	rm -f "$line_count_tmp"
 }
 
 # This is not among top-level (test_expect_success | test_expect_failure)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help