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

Re: $PATH pollution and t9902-completion.sh

From
Jeff King <peff@peff.net>
Date
Dec 20, 2012, 21:04 UTC
Message-ID
<20121220210447.GA32032@sigill.intra.peff.net>
In-Reply-To
<50D37AB2.1040508@web.de>
On Thu, Dec 20, 2012 at 09:53:06PM +0100, Torsten Bögershausen wrote:
Show 25 quoted lines
> (Good to learn about the comm command, thanks )
> What do we think about this:
> 
> 
> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
> index 3cd53f8..82eeba7 100755
> --- a/t/t9902-completion.sh
> +++ b/t/t9902-completion.sh
> @@ -62,12 +62,16 @@ test_completion ()
>  {
>  	if test $# -gt 1
>  	then
> -		printf '%s\n' "$2" >expected
> +		printf '%s\n' "$2" | sort >expected.sorted
>  	else
> -		sed -e 's/Z$//' >expected
> +		sed -e 's/Z$//' | sort >expected.sorted
>  	fi &&
>  	run_completion "$1" &&
> -	test_cmp expected out
> +	sort <out >actual.sorted &&
> +	>empty &&
> +	comm -23 expected.sorted actual.sorted >actual &&
> +	test_cmp empty actual &&
> +	rm empty actual

I like test_* helpers that tell you what happened on error, but this output will be kind of a weird diff (it is a diff showing things you expected to have but did not get as additions, and no mention of things you expected and got).

The output is human readable, so I think it is perfectly OK to print a message about what is going on (we do this in test_expect_code, for example). Something like:

  test_fully_contains() {
    sort "$1" >expect.sorted &&
    sort "$2" >actual.sorted &&
    comm -23 expect.sorted actual.sorted >missing
    test -f missing -a ! -s missing &&
    rm -f expect.sorted actual.sorted missing &&
    return 0
    {
      echo "test_fully_contains: some lines were missing"
      echo "expected:"
      sed 's/^/  /' <"$1"
      echo "actual:"
      sed 's/^/  /' <"$2"
      echo "missing:"
      sed 's/^/  /' <missing
    } >&2
    return 1
  }

Though come to think of it, just showing the diff between expect.sorted and actual.sorted would probably be enough. It would show the missing elements as deletions, the found elements as common lines, and the "extra" elements as additions (which are not an error, but when you are debugging, might be useful to know about).

-Peff
Previous: Junio C Hamano
Message 10 of 10 in “$PATH pollution and t9902-completion.sh”
  1. Adam SpiersDec 17, 2012
  2. Jeff KingDec 20, 2012
  3. Adam SpiersDec 20, 2012
  4. Torsten BögershausenDec 20, 2012
  5. Junio C HamanoDec 20, 2012
  6. Junio C HamanoDec 20, 2012
  7. Jeff KingDec 20, 2012
  8. Torsten BögershausenDec 20, 2012
  9. Junio C HamanoDec 20, 2012
  10. Jeff KingDec 20, 2012

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.