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

Re: [PATCH] test-lib: limit the output of the yes utility

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 2, 2016, 08:21 UTC
Message-ID
<alpine.DEB.2.20.1602020907290.2964@virtualbox>
In-Reply-To
<56B05A95.3000808@kdbg.org>
Hi Hannes,
On Tue, 2 Feb 2016, Johannes Sixt wrote:
> On Windows, there is no SIGPIPE.

True. But we do get some sort of write failure, no? Otherwise https://github.com/git/git/commit/2b86292ed would not work...

Show 25 quoted lines
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index bd4b02e..97e6491 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -902,15 +902,15 @@ fi
>  yes () {
>  	if test $# = 0
>  	then
> -		y=y
> +		set -- y
>  	else
> -		y="$*"
> +		set -- "$*"
>  	fi
> -
> -	while echo "$y"
> -	do
> -		:
> -	done
> +	# we do not need an infinite supply of output for tests
> +	set -- "$@" "$@" "$@" "$@"	# 4
> +	set -- "$@" "$@" "$@" "$@"	# 16
> +	set -- "$@" "$@" "$@" "$@"	# 64
> +	printf "%s\n" "$@"
>  }

I agree with the idea, but I would like to have a less intrusive patch. Something like this should do the job as well, and is a little easier on the eyes IMHO:

-- snipsnap --
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 32ac1a6..ae381b9 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -907,9 +907,11 @@ yes () {
 		y="$*"
 	fi
 
-	while echo "$y"
+	i=0
+	while test $i -lt 99
 	do
-		:
+		echo "$y"
+		i=$(($i+1))
 	done
 }
 
Previous: Johannes SixtNext: Johannes Sixt
Message 2 of 4 in “test-lib: limit the output of the yes utility”
  1. test-lib: limit the output of the yes utilityJohannes Sixt, Feb 2, 2016
  2. Johannes SchindelinFeb 2, 2016
  3. test-lib: limit the output of the yes utilityJohannes Sixt, Feb 2, 2016
  4. Johannes SchindelinFeb 3, 2016

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.