git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 16, 2010, 19:10 UTC
Message-ID
<7vtyjhgk3z.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20101116171031.GB13398@burratino>
Jonathan Nieder <jrnieder@gmail.com> writes:
Show 47 quoted lines
> 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 <jrnieder@gmail.com>
> ---
> 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
You forgot to clean the temporary file here.
Also if the file is huge, do we really want to cat the whole thing?
Show 5 quoted lines
>  	fi
> +	rm -f "$line_count_tmp"
>  }
>  
>  # This is not among top-level (test_expect_success | test_expect_failure)
Previous: Jonathan NiederNext: Jonathan Nieder
Message 8 of 9 in “t6022: Use -eq not = to test output of wc -l”
  1. t6022: Use -eq not = to test output of wc -lBrian Gernhardt, Nov 8, 2010
  2. Ævar Arnfjörð BjarmasonNov 8, 2010
  3. Jonathan NiederNov 8, 2010
  4. Junio C HamanoNov 15, 2010
  5. Bert WesargNov 16, 2010
  6. Johannes SixtNov 16, 2010
  7. Jonathan NiederNov 16, 2010
  8. Junio C HamanoNov 16, 2010
  9. Jonathan NiederNov 16, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.