]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add test for tests with no tests
authorRuss Cox <rsc@golang.org>
Mon, 9 Jul 2018 14:46:28 +0000 (10:46 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 10 Jul 2018 03:00:05 +0000 (03:00 +0000)
CL 122518 rolled back an earlier CL that made "go test"
start running test binaries for packages with no *_test.go files.
Add a test as another roadblock to reintroducing that behavior
in the future.

For #26462.

Change-Id: I898103064efee8d6ae65bcf74f4dffc830eae7e9
Reviewed-on: https://go-review.googlesource.com/122595
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/go_test.go
src/cmd/go/testdata/src/testnorun/p.go [new file with mode: 0644]

index 2434f0f5f255a946881a89fc52e0c8ed3c400f35..889a6d5df1aa5195912c1b43cfe4c22cae31618b 100644 (file)
@@ -6452,6 +6452,16 @@ func TestCDAndGOPATHAreDifferent(t *testing.T) {
        }
 }
 
+// Issue 26242.
+func TestGoTestWithoutTests(t *testing.T) {
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.parallel()
+       tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
+       tg.run("test", "testnorun")
+       tg.grepStdout(`testnorun\t\[no test files\]`, "do not want test to run")
+}
+
 // Issue 25579.
 func TestGoBuildDashODevNull(t *testing.T) {
        tg := testgo(t)
diff --git a/src/cmd/go/testdata/src/testnorun/p.go b/src/cmd/go/testdata/src/testnorun/p.go
new file mode 100644 (file)
index 0000000..71a9a56
--- /dev/null
@@ -0,0 +1,5 @@
+package p
+
+func init() {
+       panic("go test must not link and run test binaries without tests")
+}