1
0
mirror of https://github.com/golang/go synced 2024-11-23 14:00:03 -07:00

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: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Bryan C. Mills 2019-03-12 14:41:09 -04:00
parent a083648165
commit 49448badb6

View File

@ -32,10 +32,6 @@ func main() {
`
func objdumpOutput(t *testing.T) []byte {
cwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
tmpdir, err := ioutil.TempDir("", "19518")
if err != nil {
t.Fatal(err)
@ -63,15 +59,13 @@ func objdumpOutput(t *testing.T) []byte {
if err != nil {
t.Fatal(err)
}
err = os.Chdir(tmpdir)
if err != nil {
t.Fatal(err)
}
cmd := exec.Command(
testenv.GoToolPath(t), "build", "-o",
filepath.Join(tmpdir, "output"))
cmd.Env = append(os.Environ(), "GOARCH=amd64", "GOOS=linux")
cmd.Dir = tmpdir
out, err := cmd.CombinedOutput()
if err != nil {
@ -81,14 +75,12 @@ func objdumpOutput(t *testing.T) []byte {
testenv.GoToolPath(t), "tool", "objdump", "-s", "testASM",
filepath.Join(tmpdir, "output"))
cmd2.Env = cmd.Env
cmd2.Dir = tmpdir
objout, err := cmd2.CombinedOutput()
if err != nil {
t.Fatalf("error %s output %s", err, objout)
}
err = os.Chdir(cwd)
if err != nil {
t.Fatal(err)
}
return objout
}