From ac3efc83e6747c3e7e56250774332cec5d2862f4 Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Tue, 22 Mar 2022 16:38:13 -0400 Subject: [PATCH] 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 --- src/cmd/link/link_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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") -- 2.50.0