diff options
| author | Alex Brainman <alex.brainman@gmail.com> | 2014-05-12 09:26:05 +1000 |
|---|---|---|
| committer | Alex Brainman <alex.brainman@gmail.com> | 2014-05-12 09:26:05 +1000 |
| commit | 2a7ab1616f861087c6da320f7de360949868384a (patch) | |
| tree | fb580bb35e1e2f6ff840a86b0b3b76ff5a3d01f3 /src/cmd/nm | |
| parent | 82ca3087439399737f66395a568ba9f5642b295b (diff) | |
| download | go-2a7ab1616f861087c6da320f7de360949868384a.tar.xz | |
cmd/nm: do not write to GOROOT testdata directories during TestNM
LGTM=bradfitz
R=bradfitz, 0intro
CC=golang-codereviews
https://golang.org/cl/95280043
Diffstat (limited to 'src/cmd/nm')
| -rw-r--r-- | src/cmd/nm/nm_test.go | 17 |
1 files changed, 12 insertions, 5 deletions
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)) |
