Commit 49448bad authored by Bryan C. Mills's avatar Bryan C. Mills

cmd/internal/obj/x86: avoid os.Chdir in issue19518_test.go

Chdir leaves the test in the wrong working directory if objdumpOutput
calls t.Fatalf (or panics), and it isn't necessary here anyway. Set
the Dir field on the commands instead.

Change-Id: I9f0eb0d4f8d15043f1e13472126ca1a1ce4b7cb3
Reviewed-on: https://go-review.googlesource.com/c/go/+/167081
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: default avatarJay Conrod <jayconrod@google.com>
parent a0836481
...@@ -32,10 +32,6 @@ func main() { ...@@ -32,10 +32,6 @@ func main() {
` `
func objdumpOutput(t *testing.T) []byte { func objdumpOutput(t *testing.T) []byte {
cwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
tmpdir, err := ioutil.TempDir("", "19518") tmpdir, err := ioutil.TempDir("", "19518")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
...@@ -63,15 +59,13 @@ func objdumpOutput(t *testing.T) []byte { ...@@ -63,15 +59,13 @@ func objdumpOutput(t *testing.T) []byte {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = os.Chdir(tmpdir)
if err != nil {
t.Fatal(err)
}
cmd := exec.Command( cmd := exec.Command(
testenv.GoToolPath(t), "build", "-o", testenv.GoToolPath(t), "build", "-o",
filepath.Join(tmpdir, "output")) filepath.Join(tmpdir, "output"))
cmd.Env = append(os.Environ(), "GOARCH=amd64", "GOOS=linux") cmd.Env = append(os.Environ(), "GOARCH=amd64", "GOOS=linux")
cmd.Dir = tmpdir
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
...@@ -81,14 +75,12 @@ func objdumpOutput(t *testing.T) []byte { ...@@ -81,14 +75,12 @@ func objdumpOutput(t *testing.T) []byte {
testenv.GoToolPath(t), "tool", "objdump", "-s", "testASM", testenv.GoToolPath(t), "tool", "objdump", "-s", "testASM",
filepath.Join(tmpdir, "output")) filepath.Join(tmpdir, "output"))
cmd2.Env = cmd.Env cmd2.Env = cmd.Env
cmd2.Dir = tmpdir
objout, err := cmd2.CombinedOutput() objout, err := cmd2.CombinedOutput()
if err != nil { if err != nil {
t.Fatalf("error %s output %s", err, objout) t.Fatalf("error %s output %s", err, objout)
} }
err = os.Chdir(cwd)
if err != nil {
t.Fatal(err)
}
return objout return objout
} }
......
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