]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: run the 'go build' command in TestACL in the temp directory
authorBryan C. Mills <bcmills@google.com>
Wed, 6 Mar 2019 18:34:47 +0000 (13:34 -0500)
committerBryan C. Mills <bcmills@google.com>
Wed, 6 Mar 2019 21:05:50 +0000 (21:05 +0000)
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 <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/go_windows_test.go

index 99af3d43dccb431a2828a4f086454e3656b910f6..a8cfffea793a17dabdba8c1fe42a90222021ba96 100644 (file)
@@ -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,