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"))
+}
--- /dev/null
+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")
+}
}
}
for _, example := range examples {
- if ok, _ := matchString(*matchList, example.Name); ok && example.Output != "" {
+ if ok, _ := matchString(*matchList, example.Name); ok {
fmt.Println(example.Name)
}
}