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

From: Jeff King <[email-masked]>
Date: Wed, 4 Mar 2015 04:07:35 -0500

On Mon, Mar 02, 2015 at 02:00:09AM +0100, SZEDER Gábor wrote:

> 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