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

Re: [PATCH] t1500-rev-parse: rewrite each test to run in isolation

From
Jeff King <peff@peff.net>
Date
Apr 13, 2016, 18:29 UTC
Message-ID
<20160413182928.GA31787@sigill.intra.peff.net>
In-Reply-To
<CAPig+cT8oD1jJdDrk+YPoquGfTh6m3m-ha0J+er42jOoxnVxzg@mail.gmail.com>
On Wed, Apr 13, 2016 at 12:54:16AM -0400, Eric Sunshine wrote:
Show 7 quoted lines
> > -# label is-bare is-inside-git is-inside-work prefix git-dir absolute-git-dir
> > +test_expect_success '.git/: is-inside-git-dir' '
> > +       (cd .git && test true = "$(git rev-parse --is-inside-git-dir)")
> 
> Simpler:
> 
>     test true = "$(git -C .git rev-parse --is-inside-git-dir)"

While we are modernizing, I wonder if it is a good idea to drop the use of "test" for string comparisons here. We usually save output to a file and use test_cmp, for two reasons:

  1. It tests the exit code of the command substitution.
  2. It's easier to debug when it goes wrong (the test produces useful
     output, and the state is left in the filesystem).
It is more verbose to do so, but we could easily wrap that in:
  test_stdout "true" git -C .git rev-parse --is-inside-git-dir

or something. The other problem is that it uses an extra process to do the test_cmp, which might make the tests slower (especially on Windows). We could do something like:

  test_stdout () {
          expect=$1; shift
	  if ! actual=$("$@")
	  then
		echo >&2 "test_stdout: command failed: $*"
		return 1
	  fi
	  if test "$expect" != "$actual"
	  then
	          echo >&2 "test_stdout: unexpected output for $*"
		  echo >&2 "test_stdout: $expect != $actual"
		  return 1
	  fi
	  return 0
  }

which is more thorough without incurring extra processes (we lose the nice diff output of test_cmp, but since this interface is only useful for short outputs anyway, I don't think that's a big deal.

-Peff
Previous: Mike Rappazzo
Message 7 of 7 in “rewrite t1500-rev-parse.sh”
  1. rewrite t1500-rev-parse.shMichael Rappazzo, Apr 9, 2016
  2. t1500-rev-parse: rewrite each test to run in isolationMichael Rappazzo, Apr 9, 2016
  3. Junio C HamanoApr 13, 2016
  4. SZEDER GáborApr 16, 2016
  5. Eric SunshineApr 13, 2016
  6. Mike RappazzoApr 13, 2016
  7. Jeff KingApr 13, 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.