]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: write output in temp dir in TestUnlinkableObj
authorCherry Mui <cherryyz@google.com>
Tue, 22 Mar 2022 20:38:13 +0000 (16:38 -0400)
committerCherry Mui <cherryyz@google.com>
Tue, 22 Mar 2022 21:04:24 +0000 (21:04 +0000)
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 <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/link/link_test.go

index 41da9276067d4b994392cb7214c43e9f08afab27..2eefc5c8e7d1b0a260c8ea02a06cebb2605f2e4e 100644 (file)
@@ -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")