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

Re: [PATCH 1/2] t9400-git-cvsserver-server: don't rely on the output of 'test_cmp'

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Mar 8, 2018, 21:49 UTC
Message-ID
<CAM0VKjmKcFVOLA-fFnSm=tVapa5qgUoU3Sa7RjSrqoHp5qXZiw@mail.gmail.com>
In-Reply-To
<CAPig+cTtV2unsixsMCWytdJMiYYytgdvbavfENhBrwvXq_79Bw@mail.gmail.com>
On Thu, Mar 8, 2018 at 7:51 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
> On Thu, Mar 8, 2018 at 7:38 AM, SZEDER Gábor <szeder.dev@gmail.com> wrote:
Show 18 quoted lines
>> Unroll that for loop, so we can check the files' contents the usual
>> way and rely on 'test_cmp's exit code failing the && chain.  Extract
>> updating a file via CVS and verifying its contents using 'test_cmp'
>> into a helper function requiring the file's name as parameter to avoid
>> much of the repetition resulting from unrolling the loop.
>
> An alternative approach used elsewhere in the test suite[1] would be
> simply to 'exit' if test_cmp fails:
>
>     for i in merge no-lf empty really-empty; do
>         GIT_CONFIG="$git_config" cvs update -p "$i" >$i.out
>         test_cmp $i.out ../$i || exit 1
>     done &&
>
> (And, like the existing patch, this removes the need for capturing
> test_cmp's output into a "failures" file.)
>
> [1]: For example, the "setup" test of t2204-add-ignored.sh.
But 't/README' sayeth:
    Don't:
     - exit() within a <script> part.

And it's right: 'exit' terminates the shell process it's invoked in, i.e. the whole test script (well, unless it's invoked in a subshell) without executing the remaining tests and the usual housekeeping and reporting.

Consider the following test script:
  -- >8 --
#!/bin/sh
test_description='exit 1?'
. ./test-lib.sh
test_expect_success 'exit 1' '
        exit 1
'
test_expect_success 'second test' '
        true
'
test_done
  -- >8 --
It's output:
  $ ./t9999-exit.sh
  FATAL: Unexpected exit with code 1
  $ sed -e 's/exit 1/false/' -i t9999-exit.sh
  $ ./t9999-exit.sh not ok 1 - false
  #
  #             false
  #
  ok 2 - second test
  # failed 1 among 2 test(s)
  1..2
Previous: Eric SunshineNext: Eric Sunshine
Message 5 of 14 in “Make cvs tests pass with '-x' tracing and /bin/sh”
  1. 0/2 Make cvs tests pass with '-x' tracing and /bin/shSZEDER Gábor, Mar 8, 2018
  2. 2/2 t9402-git-cvsserver-refs: don't check the stderr of a subshellSZEDER Gábor, Mar 8, 2018
  3. 1/2 t9400-git-cvsserver-server: don't rely on the output of 'test_cmp'SZEDER Gábor, Mar 8, 2018
  4. Eric SunshineMar 8, 2018
  5. SZEDER GáborMar 8, 2018
  6. Eric SunshineMar 8, 2018
  7. Eric SunshineMar 8, 2018
  8. SZEDER GáborMar 8, 2018
  9. 1/2 t9400-git-cvsserver-server: don't rely on the output of 'test_cmp'SZEDER Gábor, Mar 8, 2018
  10. Junio C HamanoMar 8, 2018
  11. SZEDER GáborMar 8, 2018
  12. Junio C HamanoMar 8, 2018
  13. SZEDER GáborMar 9, 2018
  14. Jeff KingMar 13, 2018

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.