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

Re: [PATCH v2] diff --shortstat --dirstat: remove duplicate output

From
Jeff King <peff@peff.net>
Date
Mar 4, 2015, 09:07 UTC
Message-ID
<20150304090734.GA31245@peff.net>
In-Reply-To
<20150302020009.Horde.9sATpKnsrWQkGadaRTvxkA3@webmail.informatik.kit.edu>
On Mon, Mar 02, 2015 at 02:00:09AM +0100, SZEDER Gábor wrote:
Show 14 quoted lines
> It's not just 'grep -c' but the 'test' checking its output as well.
> 
> If something goes wrong and the line count doesn't match expectations
> 'test' fails silently leaving the developer clueless as to what went
> wrong.
> 
> 'test_line_count', on the other hand, produces useful output in case
> of a failure:
> 
>    $ printf 'foo\nbar\n' >actual
>    $ test_line_count = 1 actual
>    test_line_count: line count for actual != 1
>    foo
>    bar

Since we have test_line_count, I think it makes sense to use it. But for reference, I recently introduced the `verbose` function to test-lib.sh, which lets you write:

  $ verbose test 1 = 2
  command failed:  'test' '1' '=' '2'

You can use it with any command that might fail without printing a useful error message. The big downside is that it sees only the arguments to the command, so if you write:

  $ test "$(do_something)" = 123
you will only see:
  command failed:  'test '456' '=' '123'

with no notion that $(do_something) was involved. So purpose-built helpers like test_line_count will produce better output.

You may also be introduced in the "-x" option I recently introduced, which can help with "quiet" failures. E.g.:

  $ ./t0001-init.sh -x --verbose-only=15
  [...]
  ok 13 - GIT_DIR & GIT_WORK_TREE (2)
  ok 14 - reinit
  
  expecting success: 
          mkdir template-source &&
          echo content >template-source/file &&
          git init --template=../template-source template-custom &&
          test_cmp template-source/file template-custom/.git/file
  
  + mkdir template-source
  + echo content
  + git init --template=../template-source template-custom
  Initialized empty Git repository in /home/peff/compile/git/t/trash directory.t0001-init/template-custom/.git/
  + test_cmp template-source/file template-custom/.git/file
  + diff -u template-source/file template-custom/.git/file
  ok 15 - init with --template
  ok 16 - init with --template (blank)

(ok, it's not that interesting because the test didn't fail, but hopefully you get the point).

Now I'll stop hijacking your thread to advertise random test-lib features. :)

-Peff
Previous: Junio C Hamano
Message 13 of 13 in “diff --shortstat --dirstat: remove duplicate output”
  1. diff --shortstat --dirstat: remove duplicate outputMårten Kongstad, Feb 28, 2015
  2. Johan HerlandFeb 28, 2015
  3. Junio C HamanoMar 1, 2015
  4. diff --shortstat --dirstat: remove duplicate outputMårten Kongstad, Mar 1, 2015
  5. Torsten BögershausenMar 1, 2015
  6. Michael J GruberMar 1, 2015
  7. Mårten KongstadMar 1, 2015
  8. Michael J GruberMar 1, 2015
  9. Mårten KongstadMar 1, 2015
  10. SZEDER GáborMar 2, 2015
  11. diff --shortstat --dirstat: remove duplicate outputMårten Kongstad, Mar 2, 2015
  12. Junio C HamanoMar 5, 2015
  13. Jeff KingMar 4, 2015

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.