-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/vcs: avoid using os.Environ in a test helper
As reported by GODEBUG=gocachehash=1, this caused every single env var set in the current environment to be part of the test cache key: $ grep testInput before | wc -l 284 $ grep testInput after | wc -l 39 Signed-off-by: Daniel Martí <[email protected]> Change-Id: I9e8f87bbe60fda9b3d37817a4c24c8ace24a9018 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201442 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Roger Peppe <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
- Loading branch information
Showing
3 changed files
with
18 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,9 +38,9 @@ func TestCommits(t *testing.T) { | |
t.Logf("commit:\n%s", commit) | ||
|
||
dir := t.TempDir() | ||
vcs.InitTestEnv(t) | ||
mustRunCmd(t, dir, "git", "init") | ||
mustRunCmd(t, dir, "git", | ||
env := vcs.TestEnv() | ||
mustRunCmd(t, dir, env, "git", "init") | ||
mustRunCmd(t, dir, env, "git", | ||
"-c", "[email protected]", | ||
"-c", "user.name=cueckoo", | ||
"commit", "--allow-empty", "-m", string(commit), | ||
|
@@ -71,9 +71,10 @@ func TestCommits(t *testing.T) { | |
} | ||
} | ||
|
||
func mustRunCmd(t *testing.T, dir string, exe string, args ...string) { | ||
func mustRunCmd(t *testing.T, dir string, env []string, exe string, args ...string) { | ||
cmd := exec.Command(exe, args...) | ||
cmd.Dir = dir | ||
cmd.Env = env | ||
data, err := cmd.CombinedOutput() | ||
qt.Assert(t, qt.IsNil(err), qt.Commentf("output: %q", data)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,8 +51,8 @@ func TestGit(t *testing.T) { | |
_, err = New("git", subdir) | ||
qt.Assert(t, qt.ErrorMatches(err, `git VCS not found in any parent of ".+"`)) | ||
|
||
InitTestEnv(t) | ||
mustRunCmd(t, dir, "git", "init") | ||
env := TestEnv() | ||
mustRunCmd(t, dir, env, "git", "init") | ||
v, err := New("git", subdir) | ||
qt.Assert(t, qt.IsNil(err)) | ||
|
||
|
@@ -63,13 +63,13 @@ func TestGit(t *testing.T) { | |
qt.Assert(t, qt.IsNil(err)) | ||
qt.Assert(t, qt.IsTrue(statusuncommitted.Uncommitted)) | ||
|
||
mustRunCmd(t, dir, "git", "add", ".") | ||
mustRunCmd(t, dir, env, "git", "add", ".") | ||
statusuncommitted, err = v.Status(ctx, subdir) | ||
qt.Assert(t, qt.IsNil(err)) | ||
qt.Assert(t, qt.IsTrue(statusuncommitted.Uncommitted)) | ||
|
||
commitTime := time.Now().Truncate(time.Second) | ||
mustRunCmd(t, dir, "git", | ||
mustRunCmd(t, dir, env, "git", | ||
"-c", "[email protected]", | ||
"-c", "user.name=cueckoo", | ||
"commit", "-m", "something", | ||
|
@@ -186,9 +186,10 @@ func TestGit(t *testing.T) { | |
qt.Assert(t, qt.IsTrue(statusmissing.Uncommitted)) | ||
} | ||
|
||
func mustRunCmd(t *testing.T, dir string, exe string, args ...string) { | ||
func mustRunCmd(t *testing.T, dir string, env []string, exe string, args ...string) { | ||
c := exec.Command(exe, args...) | ||
c.Dir = dir | ||
c.Env = env | ||
data, err := c.CombinedOutput() | ||
qt.Assert(t, qt.IsNil(err), qt.Commentf("output: %q", data)) | ||
} | ||
|