]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: bypass install to os.DevNull entirely, test mayberemovefile(os.DevNull)
authorRuss Cox <rsc@golang.org>
Fri, 21 Oct 2016 13:21:06 +0000 (09:21 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 25 Oct 2016 13:22:02 +0000 (13:22 +0000)
Fixes #16811.

Change-Id: I7d018015f691838482ccf845d621209b96935ba4
Reviewed-on: https://go-review.googlesource.com/31657
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Quentin Smith <quentin@golang.org>
src/cmd/go/build.go
src/cmd/go/build_test.go [new file with mode: 0644]
src/cmd/go/go_test.go

index 4ff4a980fcf06447ac1d4233acc6f4e4e3f2c03d..cd4636e7a80e10a3f2215741e00ef7951a05fafe 100644 (file)
@@ -470,6 +470,11 @@ func runBuild(cmd *Command, args []string) {
                *buildO += exeSuffix
        }
 
+       // Special case -o /dev/null by not writing at all.
+       if *buildO == os.DevNull {
+               *buildO = ""
+       }
+
        // sanity check some often mis-used options
        switch buildContext.Compiler {
        case "gccgo":
diff --git a/src/cmd/go/build_test.go b/src/cmd/go/build_test.go
new file mode 100644 (file)
index 0000000..d95bd0b
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+       "os"
+       "testing"
+)
+
+func TestRemoveDevNull(t *testing.T) {
+       fi, err := os.Lstat(os.DevNull)
+       if err != nil {
+               t.Skip(err)
+       }
+       if fi.Mode().IsRegular() {
+               t.Errorf("Lstat(%s).Mode().IsRegular() = true; expected false", os.DevNull)
+       }
+       mayberemovefile(os.DevNull)
+       _, err = os.Lstat(os.DevNull)
+       if err != nil {
+               t.Errorf("mayberemovefile(%s) did remove it; oops", os.DevNull)
+       }
+}
index 7e92841082504a7e9805492a79aa222ea6879d39..40eb38f7143da65b510d4b8e0b8a3bba248b0c3f 100644 (file)
@@ -1334,9 +1334,6 @@ func TestInstallIntoGOPATH(t *testing.T) {
 
 // Issue 12407
 func TestBuildOutputToDevNull(t *testing.T) {
-       if runtime.GOOS == "plan9" {
-               t.Skip("skipping because /dev/null is a regular file on plan9")
-       }
        tg := testgo(t)
        defer tg.cleanup()
        tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))