mirror of https://github.com/golang/go.git
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: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
9665be3a48
commit
48989d519c
|
|
@ -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")
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
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 --
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
env GO111MODULE=off
|
||||
|
||||
# go test -c -o NUL
|
||||
# should work (see golang.org/issue/28035).
|
||||
cd x
|
||||
go test -o=$devnull -c
|
||||
! exists x.test$GOEXE
|
||||
|
||||
-- x/x_test.go --
|
||||
package x_test
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
func TestNUL(t *testing.T) {
|
||||
}
|
||||
Loading…
Reference in New Issue