Commit edf8539f authored by Bryan C. Mills's avatar Bryan C. Mills

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 <bcmills@google.com>
Reviewed-by: default avatarJay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 88d719f8
......@@ -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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment