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

Re: [PATCH v2] tests: set temp variables using 'env' in test function instead of subshell

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Mar 18, 2014, 20:52 UTC
Message-ID
<CAPig+cS5UDxvCGRm4d840tOfG6pwjHbARuyAWOR+D_Aht79Gzw@mail.gmail.com>
In-Reply-To
<1395144518-2489-1-git-send-email-unsignedzero@gmail.com>
On Tue, Mar 18, 2014 at 8:08 AM, David Tran <unsignedzero@gmail.com> wrote:
Show 13 quoted lines
> Originally, the code used subshells instead of FOO=BAR command because
> the variable would otherwise leak into the surrounding context of the POSIX
> shell when 'command' is a shell function. The subshell was used to hold the
> context for the test. Using 'env' in the test function sets the temp variables
> without leaking, removing the need of a subshell.
>
> Signed-off-by: David Tran <unsignedzero@gmail.com>
> ---
>> Oh, really ;-)?
> Missed that.
>
>> Thanks.  Getting closer, I think.
> Slowly but surely.
Getting better. See below.
Show 15 quoted lines
> Signed-off-by: David Tran <unsignedzero@gmail.com>
> ---
> diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
> index 50e22b1..4c7364a 100755
> --- a/t/t3404-rebase-interactive.sh
> +++ b/t/t3404-rebase-interactive.sh
> @@ -104,9 +104,7 @@ test_expect_success 'rebase -i with the exec command checks tree cleanness' '
>         git checkout master &&
>         (
>         set_fake_editor &&
> -       FAKE_LINES="exec_echo_foo_>file1 1" &&
> -       export FAKE_LINES &&
> -       test_must_fail git rebase -i HEAD^
> +       test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" git rebase -i HEAD^
>         ) &&

In a previous review, I asked if this subshell could be dropped or if it was required for set_fake_editor. I didn't quite understand your response, so I tested it myself, and found that the subshell can be eliminated safely without breaking this or later tests.

Show 12 quoted lines
>         test_cmp_rev master^ HEAD &&
>         git reset --hard &&
> @@ -118,9 +116,8 @@ test_expect_success 'rebase -i with exec of inexistent command' '
>         test_when_finished "git rebase --abort" &&
>         (
>         set_fake_editor &&
> -       FAKE_LINES="exec_this-command-does-not-exist 1" &&
> -       export FAKE_LINES &&
> -       test_must_fail git rebase -i HEAD^ >actual 2>&1
> +       test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \
> +       git rebase -i HEAD^ >actual 2>&1
>         ) &&
Ditto for this subshell.
Show 12 quoted lines
>         ! grep "Maybe git-rebase is broken" actual
>  '
> @@ -528,11 +509,7 @@ test_expect_success 'aborted --continue does not squash commits after "edit"' '
>         FAKE_LINES="edit 1" git rebase -i HEAD^ &&
>         echo "edited again" > file7 &&
>         git add file7 &&
> -       (
> -               FAKE_COMMIT_MESSAGE=" " &&
> -               export FAKE_COMMIT_MESSAGE &&
> -               test_must_fail git rebase --continue
> -       ) &&
> +       test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue
Broken &&-chain.
>         test $old = $(git rev-parse HEAD) &&
>         git rebase --abort
>  '
Previous: Eric Sunshine
Message 28 of 28 in “tests: set temp variables using 'env' in test function instead of subshell”
  1. tests: set temp variables using 'env' in test function instead of subshellDavid Tran, Mar 18, 2014
  2. Junio C HamanoMar 18, 2014
  3. Jeff KingMar 18, 2014
  4. Junio C HamanoMar 18, 2014
  5. Jeff KingMar 18, 2014
  6. Junio C HamanoMar 19, 2014
  7. 0/12 GIT_CONFIG in the test suiteJeff King, Mar 20, 2014
  8. 01/12 t/Makefile: stop setting GIT_CONFIGJeff King, Mar 20, 2014
  9. 02/12 t/test-lib: drop redundant unset of GIT_CONFIGJeff King, Mar 20, 2014
  10. 03/12 t: drop useless sane_unset GIT_* callsJeff King, Mar 20, 2014
  11. Junio C HamanoMar 21, 2014
  12. Jeff KingMar 24, 2014
  13. Junio C HamanoMar 24, 2014
  14. Junio C HamanoMar 25, 2014
  15. 04/12 t: stop using GIT_CONFIG to cross repo boundariesJeff King, Mar 20, 2014
  16. Junio C HamanoMar 21, 2014
  17. Jeff KingMar 24, 2014
  18. 05/12 t: prefer "git config --file" to GIT_CONFIG with test_must_failJeff King, Mar 20, 2014
  19. 06/12 t: prefer "git config --file" to GIT_CONFIGJeff King, Mar 20, 2014
  20. 07/12 t0001: make symlink reinit test more carefulJeff King, Mar 20, 2014
  21. 08/12 t0001: use test_path_is_*Jeff King, Mar 20, 2014
  22. 09/12 t0001: use test_config_globalJeff King, Mar 20, 2014
  23. 10/12 t0001: use test_must_failJeff King, Mar 20, 2014
  24. 11/12 t0001: drop useless subshellsJeff King, Mar 20, 2014
  25. Eric SunshineMar 21, 2014
  26. 12/12 t0001: drop subshells just for "cd"Jeff King, Mar 20, 2014
  27. Eric SunshineMar 18, 2014
  28. Eric SunshineMar 18, 2014

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.