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

Re: [GSoC][PATCH v4] test: avoid pipes in git related commands for test

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Mar 25, 2018, 08:37 UTC
Message-ID
<CAPig+cS3GjYo+5C_W6WqzK3RP=W+918E6Cz=FSvHky6EWCEZPA@mail.gmail.com>
In-Reply-To
<20180323150150.31186-1-predatoramigo@gmail.com>
On Fri, Mar 23, 2018 at 11:01 AM, Pratik Karki <predatoramigo@gmail.com> wrote:
> I hope this follow-on patch[1] is ready for merge.

This iteration appears to address review comments from the last few rounds, however, see below for a few new ones...

Show 16 quoted lines
> Avoid using pipes downstream of Git commands since the exit codes
> of commands upstream of pipes get swallowed, thus potentially
> hiding failure of those commands. Instead, capture Git command
> output to a file and apply the downstream command(s) to that file.
>
> Signed-off-by: Pratik Karki <predatoramigo@gmail.com>
> ---
> diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
> @@ -840,8 +840,8 @@ test_expect_success C_LOCALE_OUTPUT 'fetch aligned output' '
>         test_commit looooooooooooong-tag &&
>         (
>                 cd full-output &&
> -               git -c fetch.output=full fetch origin 2>&1 | \
> -                       grep -e "->" | cut -c 22- >../actual
> +               git -c fetch.output=full fetch origin >actual2 2>&1 &&
> +               grep -e "->" actual2 | cut -c 22- >../actual

The file "actual2" is clearly distinct from the file "../actual", so inventing a name ("actual2") isn't particularly helping; you could just as easily also name it "actual" without hurting comprehension. (Not necessarily worth a re-roll.)

Show 9 quoted lines
>         ) &&
> @@ -855,8 +855,8 @@ test_expect_success C_LOCALE_OUTPUT 'fetch compact output' '
>         test_commit extraaa &&
>         (
>                 cd compact &&
> -               git -c fetch.output=compact fetch origin 2>&1 | \
> -                       grep -e "->" | cut -c 22- >../actual
> +               git -c fetch.output=compact fetch origin >actual2 2>&1 &&
> +               grep -e "->" actual2 | cut -c 22- >../actual
Same comment.
Show 13 quoted lines
>         ) &&
> diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh
> @@ -74,11 +74,12 @@ test_expect_success 'iso-8859-1' '
>         git commit -s -m den file &&
> -       git fast-export wer^..wer |
> -               sed "s/wer/i18n/" |
> +       git fast-export wer^..wer >actual &&
> +       sed "s/wer/i18n/" actual |
>                 (cd new &&
>                  git fast-import &&
> -                git cat-file commit i18n | grep "Áéí óú")
> +                git cat-file commit i18n >actual &&
> +                grep "Áéí óú" actual)

It was a bit surprising to see a new "actual" file created inside the subshell even as 'sed' is processing a file named "actual" outside the subshell, and, as a reader, I was concerned about bad interaction between the operations. However, the file in the subshell is really "new/actual", thus is distinct from the other "actual", so it's okay.

This is one of those cases, however, in which it might make sense to give the files different names to make the code easier to grok, so future readers don't stumble over this as well. For instance, the outer file could be named "iso8859-1.fi" (or something), and the file in the subshell can remain "actual". Not itself worth a re-roll, but probably a good idea.

(This differs in couple ways from my comment above about t5510 tests naming files "actual2" and "../actual". In that case, it was quite clear that, within the cd'd subshell, file "../actual" was distinct from the file created within the cd'd directory, so no confusion. Moreover, those files were not being accessed at the same time, whereas in this t9350 test, the 'sed' is reading from the a file at the same time as 'git cat-file' is outputting to a similarly named file, which is potentially confusing and requires extra brain cycles to sort out.)

Show 12 quoted lines
>  '
> @@ -87,18 +88,16 @@ test_expect_success 'import/export-marks' '
>         test_line_count = 3 tmp-marks &&
> -       test $(
> -               git fast-export --import-marks=tmp-marks\
> -               --export-marks=tmp-marks HEAD |
> -               grep ^commit |
> +       git fast-export --import-marks=tmp-marks \
> +               --export-marks=tmp-marks HEAD >actual &&
> +       test $(grep ^commit actual |
>                 wc -l) \
>         -eq 0 &&

Since the git-fast-export invocation has been pulled out of the $(...), the entire 'test' expression is now short enough to fit easily on one line. Making such a change would improve readability considering how hard it is to read split over three lines like that (with inconsistent indentation, moreover):

    test $(grep ^commit actual | wc -l) -eq 0 &&
Show 11 quoted lines
>         echo change > file &&
>         git commit -m "last commit" file &&
> -       test $(
> -               git fast-export --import-marks=tmp-marks \
> -               --export-marks=tmp-marks HEAD |
> -               grep ^commit\  |
> +       git fast-export --import-marks=tmp-marks \
> +               --export-marks=tmp-marks HEAD >actual &&
> +       test $(grep ^commit\  actual |
>                 wc -l) \
>         -eq 1 &&
Same comment.
Show 7 quoted lines
>         test_line_count = 4 tmp-marks
> @@ -500,13 +501,13 @@ test_expect_success 'refs are updated even if no commits need to be exported' '
>         git fast-export --import-marks=tmp-marks \
>                 --export-marks=tmp-marks master > /dev/null &&
>         git fast-export --import-marks=tmp-marks \
> -               --export-marks=tmp-marks master > actual &&
> +               --export-marks=tmp-marks master >actual &&

This change is unrelated to the purpose of this patch, thus is noise which distracts reviewers from real changes. Fixing style problems in code you're touching is fine (and usually recommended), however, this code is outside the scope of what the patch should be touching (there is no piping output of a git command here). Moreover, it doesn't make sense to fix only "> actual" but not "> /dev/null" just above it. Consequently, this change should be dropped from the patch.

>         test_cmp expected actual
>  '
Previous: Pratik KarkiNext: Pratik Karki
Message 13 of 16 in “test: avoid pipes in git related commands for test suite”
  1. Pratik KarkiMar 13, 2018
  2. Eric SunshineMar 14, 2018
  3. Ævar Arnfjörð BjarmasonMar 14, 2018
  4. Eric SunshineMar 14, 2018
  5. Junio C HamanoMar 15, 2018
  6. [GSoC][PATCH] test: avoid pipes in git related commands for test suitePratik Karki, Mar 19, 2018
  7. Eric SunshineMar 21, 2018
  8. [GSoC][PATCH v3] test: avoid pipes in git related commands for testPratik Karki, Mar 21, 2018
  9. Junio C HamanoMar 21, 2018
  10. Eric SunshineMar 21, 2018
  11. Eric SunshineMar 21, 2018
  12. [GSoC][PATCH v4] test: avoid pipes in git related commands for testPratik Karki, Mar 23, 2018
  13. Eric SunshineMar 25, 2018
  14. [GSoC][PATCH v5] test: avoid pipes in git related commands for testPratik Karki, Mar 27, 2018
  15. Eric SunshineMar 30, 2018
  16. Junio C HamanoMar 30, 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.