tg.wantExecutable("testdata/bin/go-cmd-test"+exeSuffix, "go install go-cmd-test did not write to testdata/bin/go-cmd-test")
}
-// Issue 12407
-func TestBuildOutputToDevNull(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- fi1, err1 := os.Lstat(os.DevNull)
- tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
- tg.run("build", "-o", os.DevNull, "go-cmd-test")
- fi2, err2 := os.Lstat(os.DevNull)
- if err1 == nil {
- if err2 != nil {
- t.Errorf("second stat of /dev/null failed: %v", err2)
- } else if !os.SameFile(fi1, fi2) {
- t.Errorf("/dev/null changed: now %v was %v", fi1, fi2)
- }
- }
-}
-
-// Issue 28549.
-func TestTestOutputToDevNull(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- fi1, err1 := os.Lstat(os.DevNull)
- tg.makeTempdir()
- tg.setenv("GOPATH", tg.path("."))
- tg.tempFile("src/p/p.go", "package p\n")
- tg.tempFile("src/p/p_test.go", "package p\nimport \"testing\"\nfunc TestX(t *testing.T) {}\n")
- tg.run("test", "-o", os.DevNull, "-c", "p")
- tg.mustNotExist("p.test")
- fi2, err2 := os.Lstat(os.DevNull)
- if err1 == nil {
- if err2 != nil {
- t.Errorf("second stat of /dev/null failed: %v", err2)
- } else if !os.SameFile(fi1, fi2) {
- t.Errorf("/dev/null changed: now %v was %v", fi1, fi2)
- }
- }
-}
-
func TestPackageMainTestImportsArchiveNotBinary(t *testing.T) {
tooSlow(t)
tg := testgo(t)
--- /dev/null
+env GO111MODULE=off
+
+# Issue 28035: go test -c -o NUL should work.
+# Issue 28549: go test -c -o /dev/null should not overwrite /dev/null when run as root.
+cd x
+cmp $devnull $WORK/empty.txt
+go test -o=$devnull -c
+! exists x.test$GOEXE
+cmp $devnull $WORK/empty.txt
+
+# Issue 12407: go build -o /dev/null should succeed.
+cd ..
+go build -o $devnull y
+cmp $devnull $WORK/empty.txt
+
+-- x/x_test.go --
+package x_test
+import (
+ "testing"
+)
+func TestNUL(t *testing.T) {
+}
+-- y/y.go --
+package y
+func main() {}
+-- $WORK/empty.txt --