]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: show examples with empty output in go test -list
authorSeiji Takahashi <timaki.st@gmail.com>
Sun, 30 Jul 2017 12:00:09 +0000 (21:00 +0900)
committerIan Lance Taylor <iant@golang.org>
Wed, 2 Aug 2017 14:30:08 +0000 (14:30 +0000)
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>

src/cmd/go/go_test.go
src/cmd/go/testdata/src/testlist/bench_test.go [new file with mode: 0644]
src/cmd/go/testdata/src/testlist/example_test.go [new file with mode: 0644]
src/cmd/go/testdata/src/testlist/test_test.go [new file with mode: 0644]
src/testing/testing.go

index e706e27bdf366305c814f755c31b579fd47e1b50..7d80d965ae6dc1ffd41a590a537f6fb4b177d75b 100644 (file)
@@ -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 (file)
index 0000000..22f147b
--- /dev/null
@@ -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 (file)
index 0000000..0298dfd
--- /dev/null
@@ -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 (file)
index 0000000..bdc09f2
--- /dev/null
@@ -0,0 +1,10 @@
+package testlist
+
+import (
+       "fmt"
+       "testing"
+)
+
+func TestSimple(t *testing.T) {
+       _ = fmt.Sprint("Test simple")
+}
index 3d1c0c694741dbe4d7c394c86a8fa1d428aa5a9c..11af926c80f8e9b69cc893c8317358c5057355bd 100644 (file)
@@ -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)
                }
        }