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

Re: [PATCH v2 1/2] test-lib: add a function to compare an expection with stdout from a command

From
Jeff King <peff@peff.net>
Date
Apr 17, 2016, 03:54 UTC
Message-ID
<20160417035414.GA30002@sigill.intra.peff.net>
In-Reply-To
<CAPig+cSOuFygsScGn_Nu0_d8mvRik1hQJuanrb-Nvw3ozyt7JQ@mail.gmail.com>
On Sat, Apr 16, 2016 at 11:07:02PM -0400, Eric Sunshine wrote:
Show 7 quoted lines
> > test_stdout accepts an expection and a command to execute.  It will execute
> > the command and then compare the stdout from that command to an expectation.
> > If the expectation is not met, a mock diff output is written to stderr.
> 
> I wonder if this deserves more flexibility by accepting a comparison
> operator, such as = and !=, similar to test_line_count()? Although, I
> suppose such functionality could be added later if deemed useful.

IMHO the funny syntax would outweigh the readability benefits. Unlike test_line_count(), which is abstracting a portability solution, this is mostly just about trying to save a few lines.

Though I do actually find that:
  test_stdout false git rev-parse --whatever

isn't great, because there's no syntactic separator between the expected output and the actual command to run. So I dunno, maybe it would be better as:

  test_stdout false = git rev-parse --whatever
and then you get "!=" for free later on if you want it.
We could also do:
  test_stdout git rev-parse --whatever <<-\EOF
  false
  EOF

which is more robust for multi-line output, but I think part of the point is to keep these as simple one-liners. You're not buying all that much over:

  cat >expect <<-\EOF &&
  false
  EOF
  git rev-parse --whatever >actual &&
  test_cmp expect actual

Though I do admit I've considered such a helper for some tests where that pattern is repeated ad nauseam.

Show 5 quoted lines
> > Based-on-a-patch-by: Jeff King <peff@peff.net>
> 
> Since Peff wrote the actual code[1], it might be worthwhile to give
> him authorship by prepending the commit message with a "From: Jeff
> King <peff@peff.net>" header.

Michael contacted me offline asking how to credit, and I actually suggested the "Based-on" route. I'm OK with it either way.

And for the record, my contribution is:
  Signed-off-by: Jeff King <peff@peff.net>
in case there are any DCO questions.
-Peff
Previous: Eric SunshineNext: Eric Sunshine
Message 4 of 13 in “t1500-rev-parse: re-write t1500”
  1. 0/2 t1500-rev-parse: re-write t1500Michael Rappazzo, Apr 16, 2016
  2. 1/2 test-lib: add a function to compare an expection with stdout from a commandMichael Rappazzo, Apr 16, 2016
  3. Eric SunshineApr 17, 2016
  4. Jeff KingApr 17, 2016
  5. Eric SunshineApr 17, 2016
  6. Jeff KingApr 17, 2016
  7. Johannes SixtApr 17, 2016
  8. Eric SunshineApr 17, 2016
  9. 2/2 t1500-rev-parse: rewrite each test to run in isolationMichael Rappazzo, Apr 16, 2016
  10. Eric SunshineApr 17, 2016
  11. Johannes SixtApr 17, 2016
  12. SZEDER GáborApr 17, 2016
  13. Eric SunshineApr 17, 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.