{"thread":{"id":"36254","subject":"[PATCH v4] tests: use \"env\" to run commands with temporary env-var settings","startedAt":"2014-03-20T10:51:10Z","lastAt":"2014-03-20T19:25:48Z","messageCount":2,"participants":["David Tran","Junio C Hamano"],"isPatch":true,"patchVersion":4,"patchTotal":null},"messages":[{"id":"237194","messageId":"1395312670-1843-1-git-send-email-unsignedzero@gmail.com","threadId":"36254","inReplyTo":null,"subject":"[PATCH v4] tests: use \"env\" to run commands with temporary env-var settings","fromName":"David Tran","fromEmail":"unsignedzero@gmail.com","sentAt":"2014-03-20T10:51:10Z","receivedAt":"2014-03-20T10:51:10Z","isPatch":true,"sender":{"key":"unsignedzero@gmail.com","avatar":"https://avatars.githubusercontent.com/u/778125?v=4"},"body":"Ordinarily, we would say \"VAR=VAL command\" to execute a tested command with\nenvironment variable(s) set only for that command. This however does not work\nif 'command' is a shell function (most notably 'test_must_fail'); the result\nof the assignment is retained and affects later commands.\n\nTo avoid this, we assigned and exported the environment variables and run such\ntest(s) in a subshell like this,\n\n\t(\n\t\tVAR=VAL &&\n\t\texport VAR &&\n\t\ttest_must_fail git command to be tested\n\t)\n\nUsing the \"env\" utility, we should be able to say\n\n\ttest_must_fail git command to be tested\n\nwhich is much shorter and easier to read.\n\nSigned-off-by: David Tran <unsignedzero@gmail.com>\n\n---\n\nRevision update: v1[1] and v2[2] fixed broken &&-chains and removed subshells\nthat are no longer needed. v3[3] fixed typos and mistakes in the commit\nmessage itself.\n\n>>>Let's see if I replied correctly with send-email. Retrying this again.\n>>>How do I 'reply' to a thread using send-email?\n>>Look for --in-reply-to option in \"man git-send-email\".\n>Git prompts me for this but I don't know what to type. I tried typing just\n>the id, like 244379 and that didn't work. I guess I'll try\n>244379 <at> gmane.comp.version-control.git? Google didn't bring many results on\n>how to use it but many results of what it is and its goal.\nI see 'Followup' on the upper right. Should do the right job.\n\n>Much better. I didn't spot any errors in the patch this time around.\nGood.\n\n>One final note for future submissions: As a courtesy to reviewers,\n>explain (below the \"---\" line) what changed in the current version,\n>and provide a reference to the previous attempt, like this [1].\nAdded above.\n\n>Looks familiar ;-) but it seems the changes from the original you\n>took it from all look worsening, not improvements, to me.\nI learn more from rewriting than copying and pasting but I'll change most of it\nback then.\n\n>Seems to be well done.  Thanks.\nYou're welcome.\n\nI am David Tran a graduating CS/Math senior from Sonoma State University,\nUnited States. I would like to work with git for GSoC'14, specifically the line\noptions for git rebase --interactive [4][5]. I have used git for a few years and\nknow how destructive but important rebase is to git. I have created a few shell\nscripts here and there to make life using bash/zsh easier. I would like to\napply these skills and work with the best.\n\nGithub: unsignedzero\n\n[1]: http://thread.gmane.org/gmane.comp.version-control.git/244256\n[2]: http://thread.gmane.org/gmane.comp.version-control.git/244379\n[3]: http://thread.gmane.org/gmane.comp.version-control.git/244406\n\n[4]: http://thread.gmane.org/gmane.comp.version-control.git/243933/focus=243967\n[5]: http://thread.gmane.org/gmane.comp.version-control.git/242701\n\nSigned-off-by: David Tran <unsignedzero@gmail.com>\n---\n t/t1300-repo-config.sh        |   17 ++--------\n t/t1510-repo-setup.sh         |    4 +--\n t/t3200-branch.sh             |   12 +------\n t/t3301-notes.sh              |   22 +++---------\n t/t3404-rebase-interactive.sh |   69 ++++++++---------------------------------\n t/t3413-rebase-hook.sh        |    6 +---\n t/t4014-format-patch.sh       |   14 ++------\n t/t5305-include-tag.sh        |    4 +--\n t/t5602-clone-remote-exec.sh  |   13 ++------\n t/t5801-remote-helpers.sh     |    6 +--\n t/t6006-rev-list-format.sh    |    9 ++---\n t/t7006-pager.sh              |   18 ++---------\n 12 files changed, 42 insertions(+), 152 deletions(-)\n\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex c9c426c..3e3f77b 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -974,24 +974,15 @@ test_expect_success SYMLINKS 'symlinked configuration' '\n '\n\n test_expect_success 'nonexistent configuration' '\n-\t(\n-\t\tGIT_CONFIG=doesnotexist &&\n-\t\texport GIT_CONFIG &&\n-\t\ttest_must_fail git config --list &&\n-\t\ttest_must_fail git config test.xyzzy\n-\t)\n+\ttest_must_fail env GIT_CONFIG=doesnotexist git config --list &&\n+\ttest_must_fail env GIT_CONFIG=doesnotexist git config test.xyzzy\n '\n\n test_expect_success SYMLINKS 'symlink to nonexistent configuration' '\n \tln -s doesnotexist linktonada &&\n \tln -s linktonada linktolinktonada &&\n-\t(\n-\t\tGIT_CONFIG=linktonada &&\n-\t\texport GIT_CONFIG &&\n-\t\ttest_must_fail git config --list &&\n-\t\tGIT_CONFIG=linktolinktonada &&\n-\t\ttest_must_fail git config --list\n-\t)\n+\ttest_must_fail env GIT_CONFIG=linktonada git config --list &&\n+\ttest_must_fail env GIT_CONFIG=linktolinktonada git config --list\n '\n\n test_expect_success 'check split_cmdline return' \"\ndiff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh\nindex cf2ee78..e1b2a99 100755\n--- a/t/t1510-repo-setup.sh\n+++ b/t/t1510-repo-setup.sh\n@@ -777,9 +777,7 @@ test_expect_success '#30: core.worktree and core.bare conflict (gitfile version)\n \tsetup_repo 30 \"$here/30\" gitfile true &&\n \t(\n \t\tcd 30 &&\n-\t\tGIT_DIR=.git &&\n-\t\texport GIT_DIR &&\n-\t\ttest_must_fail git symbolic-ref HEAD 2>result\n+\t\ttest_must_fail env GIT_DIR=.git git symbolic-ref HEAD 2>result\n \t) &&\n \tgrep \"core.bare and core.worktree\" 30/result\n '\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex fcdb867..d45e95c 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -849,11 +849,7 @@ test_expect_success 'detect typo in branch name when using --edit-description' '\n \twrite_script editor <<-\\EOF &&\n \t\techo \"New contents\" >\"$1\"\n \tEOF\n-\t(\n-\t\tEDITOR=./editor &&\n-\t\texport EDITOR &&\n-\t\ttest_must_fail git branch --edit-description no-such-branch\n-\t)\n+\ttest_must_fail env EDITOR=./editor git branch --edit-description no-such-branch\n '\n\n test_expect_success 'refuse --edit-description on unborn branch for now' '\n@@ -861,11 +857,7 @@ test_expect_success 'refuse --edit-description on unborn branch for now' '\n \t\techo \"New contents\" >\"$1\"\n \tEOF\n \tgit checkout --orphan unborn &&\n-\t(\n-\t\tEDITOR=./editor &&\n-\t\texport EDITOR &&\n-\t\ttest_must_fail git branch --edit-description\n-\t)\n+\ttest_must_fail env EDITOR=./editor git branch --edit-description\n '\n\n test_expect_success '--merged catches invalid object names' '\ndiff --git a/t/t3301-notes.sh b/t/t3301-notes.sh\nindex 3bb79a4..cfd67ff 100755\n--- a/t/t3301-notes.sh\n+++ b/t/t3301-notes.sh\n@@ -17,7 +17,7 @@ GIT_EDITOR=./fake_editor.sh\n export GIT_EDITOR\n\n test_expect_success 'cannot annotate non-existing HEAD' '\n-\t(MSG=3 && export MSG && test_must_fail git notes add)\n+\ttest_must_fail env MSG=3 git notes add\n '\n\n test_expect_success setup '\n@@ -32,22 +32,16 @@ test_expect_success setup '\n '\n\n test_expect_success 'need valid notes ref' '\n-\t(MSG=1 GIT_NOTES_REF=/ && export MSG GIT_NOTES_REF &&\n-\t test_must_fail git notes add) &&\n-\t(MSG=2 GIT_NOTES_REF=/ && export MSG GIT_NOTES_REF &&\n-\t test_must_fail git notes show)\n+\ttest_must_fail env MSG=1 GIT_NOTES_REF=/ git notes show &&\n+\ttest_must_fail env MSG=2 GIT_NOTES_REF=/ git notes show\n '\n\n test_expect_success 'refusing to add notes in refs/heads/' '\n-\t(MSG=1 GIT_NOTES_REF=refs/heads/bogus &&\n-\t export MSG GIT_NOTES_REF &&\n-\t test_must_fail git notes add)\n+\ttest_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes add\n '\n\n test_expect_success 'refusing to edit notes in refs/remotes/' '\n-\t(MSG=1 GIT_NOTES_REF=refs/remotes/bogus &&\n-\t export MSG GIT_NOTES_REF &&\n-\t test_must_fail git notes edit)\n+\ttest_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes edit\n '\n\n # 1 indicates caught gracefully by die, 128 means git-show barked\n@@ -865,11 +859,7 @@ test_expect_success 'create note from non-existing note with \"git notes add -c\"\n \tgit add a10 &&\n \ttest_tick &&\n \tgit commit -m 10th &&\n-\t(\n-\t\tMSG=\"yet another note\" &&\n-\t\texport MSG &&\n-\t\ttest_must_fail git notes add -c deadbeef\n-\t) &&\n+\ttest_must_fail env MSG=\"yet another note\" git notes add -c deadbeef &&\n \ttest_must_fail git notes list HEAD\n '\n\ndiff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh\nindex 50e22b1..c0023a5 100755\n--- a/t/t3404-rebase-interactive.sh\n+++ b/t/t3404-rebase-interactive.sh\n@@ -102,12 +102,8 @@ test_expect_success 'rebase -i with the exec command runs from tree root' '\n\n test_expect_success 'rebase -i with the exec command checks tree cleanness' '\n \tgit checkout master &&\n-\t(\n \tset_fake_editor &&\n-\tFAKE_LINES=\"exec_echo_foo_>file1 1\" &&\n-\texport FAKE_LINES &&\n-\ttest_must_fail git rebase -i HEAD^\n-\t) &&\n+\ttest_must_fail env FAKE_LINES=\"exec_echo_foo_>file1 1\" git rebase -i HEAD^ &&\n \ttest_cmp_rev master^ HEAD &&\n \tgit reset --hard &&\n \tgit rebase --continue\n@@ -116,12 +112,9 @@ test_expect_success 'rebase -i with the exec command checks tree cleanness' '\n test_expect_success 'rebase -i with exec of inexistent command' '\n \tgit checkout master &&\n \ttest_when_finished \"git rebase --abort\" &&\n-\t(\n \tset_fake_editor &&\n-\tFAKE_LINES=\"exec_this-command-does-not-exist 1\" &&\n-\texport FAKE_LINES &&\n-\ttest_must_fail git rebase -i HEAD^ >actual 2>&1\n-\t) &&\n+\ttest_must_fail env FAKE_LINES=\"exec_this-command-does-not-exist 1\" \\\n+\tgit rebase -i HEAD^ >actual 2>&1 &&\n \t! grep \"Maybe git-rebase is broken\" actual\n '\n\n@@ -375,11 +368,7 @@ test_expect_success 'commit message used after conflict' '\n \tgit checkout -b conflict-fixup conflict-branch &&\n \tbase=$(git rev-parse HEAD~4) &&\n \tset_fake_editor &&\n-\t(\n-\t\tFAKE_LINES=\"1 fixup 3 fixup 4\" &&\n-\t\texport FAKE_LINES &&\n-\t\ttest_must_fail git rebase -i $base\n-\t) &&\n+\ttest_must_fail env FAKE_LINES=\"1 fixup 3 fixup 4\" git rebase -i $base &&\n \techo three > conflict &&\n \tgit add conflict &&\n \tFAKE_COMMIT_AMEND=\"ONCE\" EXPECT_HEADER_COUNT=2 \\\n@@ -394,11 +383,7 @@ test_expect_success 'commit message retained after conflict' '\n \tgit checkout -b conflict-squash conflict-branch &&\n \tbase=$(git rev-parse HEAD~4) &&\n \tset_fake_editor &&\n-\t(\n-\t\tFAKE_LINES=\"1 fixup 3 squash 4\" &&\n-\t\texport FAKE_LINES &&\n-\t\ttest_must_fail git rebase -i $base\n-\t) &&\n+\ttest_must_fail env FAKE_LINES=\"1 fixup 3 squash 4\" git rebase -i $base &&\n \techo three > conflict &&\n \tgit add conflict &&\n \tFAKE_COMMIT_AMEND=\"TWICE\" EXPECT_HEADER_COUNT=2 \\\n@@ -469,11 +454,7 @@ test_expect_success 'interrupted squash works as expected' '\n \tgit checkout -b interrupted-squash conflict-branch &&\n \tone=$(git rev-parse HEAD~3) &&\n \tset_fake_editor &&\n-\t(\n-\t\tFAKE_LINES=\"1 squash 3 2\" &&\n-\t\texport FAKE_LINES &&\n-\t\ttest_must_fail git rebase -i HEAD~3\n-\t) &&\n+\ttest_must_fail env FAKE_LINES=\"1 squash 3 2\" git rebase -i HEAD~3 &&\n \t(echo one; echo two; echo four) > conflict &&\n \tgit add conflict &&\n \ttest_must_fail git rebase --continue &&\n@@ -487,11 +468,7 @@ test_expect_success 'interrupted squash works as expected (case 2)' '\n \tgit checkout -b interrupted-squash2 conflict-branch &&\n \tone=$(git rev-parse HEAD~3) &&\n \tset_fake_editor &&\n-\t(\n-\t\tFAKE_LINES=\"3 squash 1 2\" &&\n-\t\texport FAKE_LINES &&\n-\t\ttest_must_fail git rebase -i HEAD~3\n-\t) &&\n+\ttest_must_fail env FAKE_LINES=\"3 squash 1 2\" git rebase -i HEAD~3 &&\n \t(echo one; echo four) > conflict &&\n \tgit add conflict &&\n \ttest_must_fail git rebase --continue &&\n@@ -528,11 +505,7 @@ test_expect_success 'aborted --continue does not squash commits after \"edit\"' '\n \tFAKE_LINES=\"edit 1\" git rebase -i HEAD^ &&\n \techo \"edited again\" > file7 &&\n \tgit add file7 &&\n-\t(\n-\t\tFAKE_COMMIT_MESSAGE=\" \" &&\n-\t\texport FAKE_COMMIT_MESSAGE &&\n-\t\ttest_must_fail git rebase --continue\n-\t) &&\n+\ttest_must_fail env FAKE_COMMIT_MESSAGE=\" \" git rebase --continue &&\n \ttest $old = $(git rev-parse HEAD) &&\n \tgit rebase --abort\n '\n@@ -547,11 +520,7 @@ test_expect_success 'auto-amend only edited commits after \"edit\"' '\n \techo \"and again\" > file7 &&\n \tgit add file7 &&\n \ttest_tick &&\n-\t(\n-\t\tFAKE_COMMIT_MESSAGE=\"and again\" &&\n-\t\texport FAKE_COMMIT_MESSAGE &&\n-\t\ttest_must_fail git rebase --continue\n-\t) &&\n+\ttest_must_fail env FAKE_COMMIT_MESSAGE=\"and again\" git rebase --continue &&\n \tgit rebase --abort\n '\n\n@@ -559,11 +528,7 @@ test_expect_success 'clean error after failed \"exec\"' '\n \ttest_tick &&\n \ttest_when_finished \"git rebase --abort || :\" &&\n \tset_fake_editor &&\n-\t(\n-\t\tFAKE_LINES=\"1 exec_false\" &&\n-\t\texport FAKE_LINES &&\n-\t\ttest_must_fail git rebase -i HEAD^\n-\t) &&\n+\ttest_must_fail env FAKE_LINES=\"1 exec_false\" git rebase -i HEAD^ &&\n \techo \"edited again\" > file7 &&\n \tgit add file7 &&\n \ttest_must_fail git rebase --continue 2>error &&\n@@ -947,12 +912,8 @@ test_expect_success 'rebase -i --root retain root commit author and message' '\n\n test_expect_success 'rebase -i --root temporary sentinel commit' '\n \tgit checkout B &&\n-\t(\n-\t\tset_fake_editor &&\n-\t\tFAKE_LINES=\"2\" &&\n-\t\texport FAKE_LINES &&\n-\t\ttest_must_fail git rebase -i --root\n-\t) &&\n+\tset_fake_editor &&\n+\ttest_must_fail env FAKE_LINES=\"2\" git rebase -i --root &&\n \tgit cat-file commit HEAD | grep \"^tree 4b825dc642cb\" &&\n \tgit rebase --abort\n '\n@@ -1042,11 +1003,7 @@ test_expect_success 'rebase -i error on commits with \\ in message' '\n \ttest_when_finished \"git rebase --abort; git reset --hard $current_head; rm -f error\" &&\n \ttest_commit TO-REMOVE will-conflict old-content &&\n \ttest_commit \"\\temp\" will-conflict new-content dummy &&\n-\t(\n-\tEDITOR=true &&\n-\texport EDITOR &&\n-\ttest_must_fail git rebase -i HEAD^ --onto HEAD^^ 2>error\n-\t) &&\n+\ttest_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error &&\n \ttest_expect_code 1 grep  \"\temp\" error\n '\n\ndiff --git a/t/t3413-rebase-hook.sh b/t/t3413-rebase-hook.sh\nindex 098b755..b6833e9 100755\n--- a/t/t3413-rebase-hook.sh\n+++ b/t/t3413-rebase-hook.sh\n@@ -118,11 +118,7 @@ test_expect_success 'pre-rebase hook stops rebase (1)' '\n test_expect_success 'pre-rebase hook stops rebase (2)' '\n \tgit checkout test &&\n \tgit reset --hard side &&\n-\t(\n-\t\tEDITOR=:\n-\t\texport EDITOR\n-\t\ttest_must_fail git rebase -i master\n-\t) &&\n+\ttest_must_fail env EDITOR=: git rebase -i master &&\n \ttest \"z$(git symbolic-ref HEAD)\" = zrefs/heads/test &&\n \ttest 0 = $(git rev-list HEAD...side | wc -l)\n '\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex 73194b2..9c80633 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -764,22 +764,14 @@ test_expect_success 'format-patch --signature=\"\" suppresses signatures' '\n\n test_expect_success TTY 'format-patch --stdout paginates' '\n \trm -f pager_used &&\n-\t(\n-\t\tGIT_PAGER=\"wc >pager_used\" &&\n-\t\texport GIT_PAGER &&\n-\t\ttest_terminal git format-patch --stdout --all\n-\t) &&\n+\ttest_terminal env GIT_PAGER=\"wc >pager_used\" git format-patch --stdout --all &&\n \ttest_path_is_file pager_used\n '\n\n  test_expect_success TTY 'format-patch --stdout pagination can be disabled' '\n \trm -f pager_used &&\n-\t(\n-\t\tGIT_PAGER=\"wc >pager_used\" &&\n-\t\texport GIT_PAGER &&\n-\t\ttest_terminal git --no-pager format-patch --stdout --all &&\n-\t\ttest_terminal git -c \"pager.format-patch=false\" format-patch --stdout --all\n-\t) &&\n+\ttest_terminal env GIT_PAGER=\"wc >pager_used\" git --no-pager format-patch --stdout --all &&\n+\ttest_terminal env GIT_PAGER=\"wc >pager_used\" git -c \"pager.format-patch=false\" format-patch --stdout --all &&\n \ttest_path_is_missing pager_used &&\n \ttest_path_is_missing .git/pager_used\n '\ndiff --git a/t/t5305-include-tag.sh b/t/t5305-include-tag.sh\nindex b061864..21517c7 100755\n--- a/t/t5305-include-tag.sh\n+++ b/t/t5305-include-tag.sh\n@@ -45,9 +45,7 @@ test_expect_success 'unpack objects' '\n test_expect_success 'check unpacked result (have commit, no tag)' '\n \tgit rev-list --objects $commit >list.expect &&\n \t(\n-\t\tGIT_DIR=clone.git &&\n-\t\texport GIT_DIR &&\n-\t\ttest_must_fail git cat-file -e $tag &&\n+\t\ttest_must_fail env GIT_DIR=clone.git git cat-file -e $tag &&\n \t\tgit rev-list --objects $commit\n \t) >list.actual &&\n \ttest_cmp list.expect list.actual\ndiff --git a/t/t5602-clone-remote-exec.sh b/t/t5602-clone-remote-exec.sh\nindex 3f353d9..cbcceab 100755\n--- a/t/t5602-clone-remote-exec.sh\n+++ b/t/t5602-clone-remote-exec.sh\n@@ -12,21 +12,14 @@ test_expect_success setup '\n '\n\n test_expect_success 'clone calls git upload-pack unqualified with no -u option' '\n-\t(\n-\t\tGIT_SSH=./not_ssh &&\n-\t\texport GIT_SSH &&\n-\t\ttest_must_fail git clone localhost:/path/to/repo junk\n-\t) &&\n+\ttest_must_fail env GIT_SSH=./not_ssh git clone localhost:/path/to/repo junk &&\n \techo \"localhost git-upload-pack '\\''/path/to/repo'\\''\" >expected &&\n \ttest_cmp expected not_ssh_output\n '\n\n test_expect_success 'clone calls specified git upload-pack with -u option' '\n-\t(\n-\t\tGIT_SSH=./not_ssh &&\n-\t\texport GIT_SSH &&\n-\t\ttest_must_fail git clone -u ./something/bin/git-upload-pack localhost:/path/to/repo junk\n-\t) &&\n+\ttest_must_fail env GIT_SSH=./not_ssh \\\n+\t\tgit clone -u ./something/bin/git-upload-pack localhost:/path/to/repo junk &&\n \techo \"localhost ./something/bin/git-upload-pack '\\''/path/to/repo'\\''\" >expected &&\n \ttest_cmp expected not_ssh_output\n '\ndiff --git a/t/t5801-remote-helpers.sh b/t/t5801-remote-helpers.sh\nindex 613f69a..ca19838 100755\n--- a/t/t5801-remote-helpers.sh\n+++ b/t/t5801-remote-helpers.sh\n@@ -218,10 +218,8 @@ test_expect_success 'proper failure checks for fetching' '\n '\n\n test_expect_success 'proper failure checks for pushing' '\n-\t(GIT_REMOTE_TESTGIT_FAILURE=1 &&\n-\texport GIT_REMOTE_TESTGIT_FAILURE &&\n-\tcd local &&\n-\ttest_must_fail git push --all\n+\t(cd local &&\n+\ttest_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all\n \t)\n '\n\ndiff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh\nindex 9874403..9d9d9de 100755\n--- a/t/t6006-rev-list-format.sh\n+++ b/t/t6006-rev-list-format.sh\n@@ -190,12 +190,9 @@ test_expect_success '%C(auto) respects --no-color' '\n '\n\n test_expect_success TTY '%C(auto) respects --color=auto (stdout is tty)' '\n-\t(\n-\t\tTERM=vt100 && export TERM &&\n-\t\ttest_terminal \\\n-\t\t\tgit log --format=$AUTO_COLOR -1 --color=auto >actual &&\n-\t\thas_color actual\n-\t)\n+\ttest_terminal env TERM=vt100 \\\n+\t\tgit log --format=$AUTO_COLOR -1 --color=auto >actual &&\n+\thas_color actual\n '\n\n test_expect_success '%C(auto) respects --color=auto (stdout not tty)' '\ndiff --git a/t/t7006-pager.sh b/t/t7006-pager.sh\nindex b9365b4..da958a8 100755\n--- a/t/t7006-pager.sh\n+++ b/t/t7006-pager.sh\n@@ -146,11 +146,7 @@ test_expect_success 'no color when stdout is a regular file' '\n test_expect_success TTY 'color when writing to a pager' '\n \trm -f paginated.out &&\n \ttest_config color.ui auto &&\n-\t(\n-\t\tTERM=vt100 &&\n-\t\texport TERM &&\n-\t\ttest_terminal git log\n-\t) &&\n+\ttest_terminal env TERM=vt100 git log &&\n \tcolorful paginated.out\n '\n\n@@ -158,11 +154,7 @@ test_expect_success TTY 'colors are suppressed by color.pager' '\n \trm -f paginated.out &&\n \ttest_config color.ui auto &&\n \ttest_config color.pager false &&\n-\t(\n-\t\tTERM=vt100 &&\n-\t\texport TERM &&\n-\t\ttest_terminal git log\n-\t) &&\n+\ttest_terminal env TERM=vt100 git log &&\n \t! colorful paginated.out\n '\n\n@@ -181,11 +173,7 @@ test_expect_success 'color when writing to a file intended for a pager' '\n test_expect_success TTY 'colors are sent to pager for external commands' '\n \ttest_config alias.externallog \"!git log\" &&\n \ttest_config color.ui auto &&\n-\t(\n-\t\tTERM=vt100 &&\n-\t\texport TERM &&\n-\t\ttest_terminal git -p externallog\n-\t) &&\n+\ttest_terminal env TERM=vt100 git -p externallog &&\n \tcolorful paginated.out\n '\n\n--\n1.7.9\n"},{"id":"237197","messageId":"xmqqd2hgy8n7.fsf@gitster.dls.corp.google.com","threadId":"36254","inReplyTo":"1395312670-1843-1-git-send-email-unsignedzero@gmail.com","subject":"Re: [PATCH v4] tests: use \"env\" to run commands with temporary env-var settings","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-03-20T19:25:48Z","receivedAt":"2014-03-20T19:25:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Tran <unsignedzero@gmail.com> writes:\n\n> Ordinarily, we would say \"VAR=VAL command\" to execute a tested command with\n> environment variable(s) set only for that command. This however does not work\n> if 'command' is a shell function (most notably 'test_must_fail'); the result\n> of the assignment is retained and affects later commands.\n>\n> To avoid this, we assigned and exported the environment variables and run such\n> test(s) in a subshell like this,\n>\n> \t(\n> \t\tVAR=VAL &&\n> \t\texport VAR &&\n> \t\ttest_must_fail git command to be tested\n> \t)\n>\n> Using the \"env\" utility, we should be able to say\n>\n> \ttest_must_fail git command to be tested\n>\n> which is much shorter and easier to read.\n>\n> Signed-off-by: David Tran <unsignedzero@gmail.com>\n>\n> ---\n> ...\n>>Looks familiar ;-) but it seems the changes from the original you\n>>took it from all look worsening, not improvements, to me.\n> I learn more from rewriting than copying and pasting but I'll change most of it\n> back then.\n\nSigh.  Your edits again butchered the correctness.\n\nRe-read your \"this is a new and better way to write test_must_fail\"\nexample above, and compare it with what was queued on 'pu'.\n\nI think we are hitting the point of diminishing or negative returns\nat this point.  Let's keep 512477b1 (tests: use \"env\" to run\ncommands with temporary env-var settings, 2014-03-18) and go forward\nwith it.\n\nThanks.\n"}]}