Commit 48989d51 authored by Bryan C. Mills's avatar Bryan C. Mills

cmd/go: convert DevNull tests to script tests

I'm hoping to eliminate testdata/src/go-cmd-test, so porting over
tests that assume its existence.

Updates #28387
Updates #30316

Change-Id: I20bae780a4eb87cc19cc1e8531b84ab4a8a3c255
Reviewed-on: https://go-review.googlesource.com/c/go/+/207608
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: default avatarJay Conrod <jayconrod@google.com>
parent 9665be3a
...@@ -1380,44 +1380,6 @@ func TestInstallIntoGOPATH(t *testing.T) { ...@@ -1380,44 +1380,6 @@ func TestInstallIntoGOPATH(t *testing.T) {
tg.wantExecutable("testdata/bin/go-cmd-test"+exeSuffix, "go install go-cmd-test did not write to testdata/bin/go-cmd-test") 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) { func TestPackageMainTestImportsArchiveNotBinary(t *testing.T) {
tooSlow(t) tooSlow(t)
tg := testgo(t) tg := testgo(t)
......
env GO111MODULE=off env GO111MODULE=off
# go test -c -o NUL # Issue 28035: go test -c -o NUL should work.
# should work (see golang.org/issue/28035). # Issue 28549: go test -c -o /dev/null should not overwrite /dev/null when run as root.
cd x cd x
cmp $devnull $WORK/empty.txt
go test -o=$devnull -c go test -o=$devnull -c
! exists x.test$GOEXE ! 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 -- -- x/x_test.go --
package x_test package x_test
...@@ -13,3 +20,7 @@ import ( ...@@ -13,3 +20,7 @@ import (
) )
func TestNUL(t *testing.T) { func TestNUL(t *testing.T) {
} }
-- y/y.go --
package y
func main() {}
-- $WORK/empty.txt --
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment