From edf8539fad89c22a7846196ae2f8920a480c1230 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 6 Mar 2019 13:34:47 -0500 Subject: [PATCH] cmd/go: run the 'go build' command in TestACL in the temp directory Otherwise, when the 'cmd' module is added the test will run as if in module 'cmd'. While we're here, remove an unnecessary os.Chdir in TestAbsolutePath: we can instead set the Dir on the 'go build' command instead. Then we can run the tests in this file in parallel with everything else. Updates #30228 Change-Id: I13ecd7ec93bc1041010daec14d76bac10e0c89be Reviewed-on: https://go-review.googlesource.com/c/go/+/165744 Run-TryBot: Bryan C. Mills Reviewed-by: Jay Conrod TryBot-Result: Gobot Gobot --- src/cmd/go/go_windows_test.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/cmd/go/go_windows_test.go b/src/cmd/go/go_windows_test.go index 99af3d43dc..a8cfffea79 100644 --- a/src/cmd/go/go_windows_test.go +++ b/src/cmd/go/go_windows_test.go @@ -16,6 +16,8 @@ import ( ) func TestAbsolutePath(t *testing.T) { + t.Parallel() + tmp, err := ioutil.TempDir("", "TestAbsolutePath") if err != nil { t.Fatal(err) @@ -33,21 +35,11 @@ func TestAbsolutePath(t *testing.T) { t.Fatal(err) } - wd, err := os.Getwd() - if err != nil { - t.Fatal(err) - } - defer os.Chdir(wd) - - // Chdir so current directory and a.go reside on the same drive. - err = os.Chdir(dir) - if err != nil { - t.Fatal(err) - } - noVolume := file[len(filepath.VolumeName(file)):] wrongPath := filepath.Join(dir, noVolume) - output, err := exec.Command(testenv.GoToolPath(t), "build", noVolume).CombinedOutput() + cmd := exec.Command(testenv.GoToolPath(t), "build", noVolume) + cmd.Dir = dir + output, err := cmd.CombinedOutput() if err == nil { t.Fatal("build should fail") } @@ -79,6 +71,8 @@ func runGetACL(t *testing.T, path string) string { // has discretionary access control list (DACL) set as if the file // was created in the destination directory. func TestACL(t *testing.T) { + t.Parallel() + tmpdir, err := ioutil.TempDir("", "TestACL") if err != nil { t.Fatal(err) @@ -102,11 +96,16 @@ func TestACL(t *testing.T) { src := filepath.Join(tmpdir, "main.go") err = ioutil.WriteFile(src, []byte("package main; func main() { }\n"), 0644) + if err == nil { + err = ioutil.WriteFile(filepath.Join(tmpdir, "go.mod"), []byte("module TestACL\n"), 0644) + } if err != nil { t.Fatal(err) } + exe := filepath.Join(tmpdir, "main.exe") cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", exe, src) + cmd.Dir = tmpdir cmd.Env = append(os.Environ(), "TMP="+newtmpdir, "TEMP="+newtmpdir,