aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeiji Takahashi <timaki.st@gmail.com>2017-07-30 21:00:09 +0900
committerIan Lance Taylor <iant@golang.org>2017-08-02 14:30:08 +0000
commit6f08c935a9474a300d34e7a476628c2667142474 (patch)
treed99dabcfca35948a5ba9a2b4e14e0ade9cbda2a5
parentf20944de78012a257d1e66b8209e2990a14673a7 (diff)
downloadgo-6f08c935a9474a300d34e7a476628c2667142474.tar.gz
go-6f08c935a9474a300d34e7a476628c2667142474.zip
cmd/go: show examples with empty output in go test -list
Fixes #21205 Change-Id: I81b001eb42cbf2a5d5b7b82eb63548b22f501be5 Reviewed-on: https://go-review.googlesource.com/52110 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
-rw-r--r--src/cmd/go/go_test.go17
-rw-r--r--src/cmd/go/testdata/src/testlist/bench_test.go14
-rw-r--r--src/cmd/go/testdata/src/testlist/example_test.go21
-rw-r--r--src/cmd/go/testdata/src/testlist/test_test.go10
-rw-r--r--src/testing/testing.go2
5 files changed, 63 insertions, 1 deletions
diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go
index e706e27bdf..7d80d965ae 100644
--- a/src/cmd/go/go_test.go
+++ b/src/cmd/go/go_test.go
@@ -4314,3 +4314,20 @@ func TestTestRegexps(t *testing.T) {
t.Errorf("reduced output:<<<\n%s>>> want:<<<\n%s>>>", have, want)
}
}
+
+func TestListTests(t *testing.T) {
+ var tg *testgoData
+ testWith := func(listName, expected string) func(*testing.T) {
+ return func(t *testing.T) {
+ tg = testgo(t)
+ defer tg.cleanup()
+ tg.run("test", "./testdata/src/testlist/...", fmt.Sprintf("-list=%s", listName))
+ tg.grepStdout(expected, fmt.Sprintf("-test.list=%s returned %q, expected %s", listName, tg.getStdout(), expected))
+ }
+ }
+
+ t.Run("Test", testWith("Test", "TestSimple"))
+ t.Run("Bench", testWith("Benchmark", "BenchmarkSimple"))
+ t.Run("Example1", testWith("Example", "ExampleSimple"))
+ t.Run("Example2", testWith("Example", "ExampleWithEmptyOutput"))
+}
diff --git a/src/cmd/go/testdata/src/testlist/bench_test.go b/src/cmd/go/testdata/src/testlist/bench_test.go
new file mode 100644
index 0000000000..22f147b633
--- /dev/null
+++ b/src/cmd/go/testdata/src/testlist/bench_test.go
@@ -0,0 +1,14 @@
+package testlist
+
+import (
+ "fmt"
+ "testing"
+)
+
+func BenchmarkSimplefunc(b *testing.B) {
+ b.StopTimer()
+ b.StartTimer()
+ for i := 0; i < b.N; i++ {
+ _ = fmt.Sprint("Test for bench")
+ }
+}
diff --git a/src/cmd/go/testdata/src/testlist/example_test.go b/src/cmd/go/testdata/src/testlist/example_test.go
new file mode 100644
index 0000000000..0298dfde81
--- /dev/null
+++ b/src/cmd/go/testdata/src/testlist/example_test.go
@@ -0,0 +1,21 @@
+package testlist
+
+import (
+ "fmt"
+)
+
+func ExampleSimple() {
+ fmt.Println("Test with Output.")
+
+ // Output: Test with Output.
+}
+
+func ExampleWithEmptyOutput() {
+ fmt.Println("")
+
+ // Output:
+}
+
+func ExampleNoOutput() {
+ _ = fmt.Sprint("Test with no output")
+}
diff --git a/src/cmd/go/testdata/src/testlist/test_test.go b/src/cmd/go/testdata/src/testlist/test_test.go
new file mode 100644
index 0000000000..bdc09f27c5
--- /dev/null
+++ b/src/cmd/go/testdata/src/testlist/test_test.go
@@ -0,0 +1,10 @@
+package testlist
+
+import (
+ "fmt"
+ "testing"
+)
+
+func TestSimple(t *testing.T) {
+ _ = fmt.Sprint("Test simple")
+}
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 3d1c0c6947..11af926c80 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -970,7 +970,7 @@ func listTests(matchString func(pat, str string) (bool, error), tests []Internal
}
}
for _, example := range examples {
- if ok, _ := matchString(*matchList, example.Name); ok && example.Output != "" {
+ if ok, _ := matchString(*matchList, example.Name); ok {
fmt.Println(example.Name)
}
}