mirror of https://github.com/golang/go.git
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>
This commit is contained in:
parent
f20944de78
commit
6f08c935a9
|
|
@ -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"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
@ -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")
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package testlist
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSimple(t *testing.T) {
|
||||
_ = fmt.Sprint("Test simple")
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue