From: Cherry Mui Date: Tue, 22 Mar 2022 20:38:13 +0000 (-0400) Subject: cmd/link: write output in temp dir in TestUnlinkableObj X-Git-Tag: go1.19beta1~956 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ac3efc83e6747c3e7e56250774332cec5d2862f4;p=gostls13.git cmd/link: write output in temp dir in TestUnlinkableObj For unlinkable object the link will fail, but it opens the output file in writable mode first then delete it on failure. This fails if the current directory is not writable. Write to the temporary directory instead. Change-Id: Iefd73b5cc8efdc0f11b12edc0920169a8ad3f37c Reviewed-on: https://go-review.googlesource.com/c/go/+/394755 Trust: Cherry Mui Run-TryBot: Cherry Mui Reviewed-by: Matthew Dempsky TryBot-Result: Gopher Robot --- diff --git a/src/cmd/link/link_test.go b/src/cmd/link/link_test.go index 41da927606..2eefc5c8e7 100644 --- a/src/cmd/link/link_test.go +++ b/src/cmd/link/link_test.go @@ -1069,6 +1069,7 @@ func TestUnlinkableObj(t *testing.T) { src := filepath.Join(tmpdir, "x.go") obj := filepath.Join(tmpdir, "x.o") + exe := filepath.Join(tmpdir, "x.exe") err := ioutil.WriteFile(src, []byte("package main\nfunc main() {}\n"), 0666) if err != nil { t.Fatalf("failed to write source file: %v", err) @@ -1078,7 +1079,7 @@ func TestUnlinkableObj(t *testing.T) { if err != nil { t.Fatalf("compile failed: %v. output:\n%s", err, out) } - cmd = exec.Command(testenv.GoToolPath(t), "tool", "link", obj) + cmd = exec.Command(testenv.GoToolPath(t), "tool", "link", "-o", exe, obj) out, err = cmd.CombinedOutput() if err == nil { t.Fatalf("link did not fail")