From: Alex Brainman Date: Sun, 11 May 2014 23:26:05 +0000 (+1000) Subject: cmd/nm: do not write to GOROOT testdata directories during TestNM X-Git-Tag: go1.3beta2~100 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2a7ab1616f861087c6da320f7de360949868384a;p=gostls13.git cmd/nm: do not write to GOROOT testdata directories during TestNM LGTM=bradfitz R=bradfitz, 0intro CC=golang-codereviews https://golang.org/cl/95280043 --- diff --git a/src/cmd/nm/nm_test.go b/src/cmd/nm/nm_test.go index 829c844b49..eab0732794 100644 --- a/src/cmd/nm/nm_test.go +++ b/src/cmd/nm/nm_test.go @@ -8,6 +8,7 @@ import ( "bufio" "bytes" "fmt" + "io/ioutil" "os" "os/exec" "path/filepath" @@ -54,11 +55,17 @@ func checkSymbols(t *testing.T, nmoutput []byte) { } func TestNM(t *testing.T) { - out, err := exec.Command("go", "build", "-o", "testnm.exe", "cmd/nm").CombinedOutput() + tmpDir, err := ioutil.TempDir("", "TestNM") if err != nil { - t.Fatalf("go build -o testnm.exe cmd/nm: %v\n%s", err, string(out)) + t.Fatal("TempDir failed: ", err) + } + defer os.RemoveAll(tmpDir) + + testnmpath := filepath.Join(tmpDir, "testnm.exe") + out, err := exec.Command("go", "build", "-o", testnmpath, "cmd/nm").CombinedOutput() + if err != nil { + t.Fatalf("go build -o %v cmd/nm: %v\n%s", testnmpath, err, string(out)) } - defer os.Remove("testnm.exe") testfiles := []string{ "elf/testdata/gcc-386-freebsd-exec", @@ -72,14 +79,14 @@ func TestNM(t *testing.T) { } for _, f := range testfiles { exepath := filepath.Join(runtime.GOROOT(), "src", "pkg", "debug", f) - cmd := exec.Command("./testnm.exe", exepath) + cmd := exec.Command(testnmpath, exepath) out, err := cmd.CombinedOutput() if err != nil { t.Fatalf("go tool nm %v: %v\n%s", exepath, err, string(out)) } } - cmd := exec.Command("./testnm.exe", os.Args[0]) + cmd := exec.Command(testnmpath, os.Args[0]) out, err = cmd.CombinedOutput() if err != nil { t.Fatalf("go tool nm %v: %v\n%s", os.Args[0], err, string(out))