Skip to content

Commit a3faa80

Browse files
committed
cmd/go: bypass install to os.DevNull entirely, test mayberemovefile(os.DevNull)
Fixes #16811. Change-Id: I7d018015f691838482ccf845d621209b96935ba4 Reviewed-on: https://go-review.googlesource.com/31657 Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Quentin Smith <[email protected]>
1 parent 3ef07c4 commit a3faa80

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/cmd/go/build.go

+5
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,11 @@ func runBuild(cmd *Command, args []string) {
470470
*buildO += exeSuffix
471471
}
472472

473+
// Special case -o /dev/null by not writing at all.
474+
if *buildO == os.DevNull {
475+
*buildO = ""
476+
}
477+
473478
// sanity check some often mis-used options
474479
switch buildContext.Compiler {
475480
case "gccgo":

src/cmd/go/build_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2016 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"os"
9+
"testing"
10+
)
11+
12+
func TestRemoveDevNull(t *testing.T) {
13+
fi, err := os.Lstat(os.DevNull)
14+
if err != nil {
15+
t.Skip(err)
16+
}
17+
if fi.Mode().IsRegular() {
18+
t.Errorf("Lstat(%s).Mode().IsRegular() = true; expected false", os.DevNull)
19+
}
20+
mayberemovefile(os.DevNull)
21+
_, err = os.Lstat(os.DevNull)
22+
if err != nil {
23+
t.Errorf("mayberemovefile(%s) did remove it; oops", os.DevNull)
24+
}
25+
}

src/cmd/go/go_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -1334,9 +1334,6 @@ func TestInstallIntoGOPATH(t *testing.T) {
13341334

13351335
// Issue 12407
13361336
func TestBuildOutputToDevNull(t *testing.T) {
1337-
if runtime.GOOS == "plan9" {
1338-
t.Skip("skipping because /dev/null is a regular file on plan9")
1339-
}
13401337
tg := testgo(t)
13411338
defer tg.cleanup()
13421339
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))

0 commit comments

Comments
 (0)