Skip to content

Commit 2eca0b1

Browse files
mauri870gopherbot
authored andcommitted
testing: enforce -skip in example tests
The go test flag -skip had no effect in example tests. Fixes #61482 Change-Id: I28dfddb88fef3fead2a3c74f9cb63a674a768231 GitHub-Last-Rev: e8c3c34 GitHub-Pull-Request: #61491 Reviewed-on: https://go-review.googlesource.com/c/go/+/511837 Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Bryan Mills <[email protected]>
1 parent e713d6f commit 2eca0b1

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/cmd/go/testdata/script/test_skip.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ stdout RUN.*Test2/3
1313
go test -v -skip 2/3 skip_test.go
1414
stdout RUN.*Test1
1515
stdout RUN.*Test2
16+
stdout RUN.*ExampleTest1
1617
! stdout Test2/3
1718

1819
go test -v -skip 2/4 skip_test.go
1920
stdout RUN.*Test1
2021
stdout RUN.*Test2
2122
stdout RUN.*Test2/3
23+
stdout RUN.*ExampleTest1
2224

25+
go test -v -skip Example skip_test.go
26+
stdout RUN.*Test1
27+
stdout RUN.*Test2
28+
stdout RUN.*Test2/3
2329

2430
-- skip_test.go --
2531
package skip_test
@@ -32,3 +38,7 @@ func Test1(t *testing.T) {
3238
func Test2(t *testing.T) {
3339
t.Run("3", func(t *testing.T) {})
3440
}
41+
42+
func ExampleTest1() {
43+
// Output:
44+
}

src/testing/example.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package testing
66

77
import (
88
"fmt"
9-
"os"
109
"sort"
1110
"strings"
1211
"time"
@@ -29,14 +28,11 @@ func RunExamples(matchString func(pat, str string) (bool, error), examples []Int
2928
func runExamples(matchString func(pat, str string) (bool, error), examples []InternalExample) (ran, ok bool) {
3029
ok = true
3130

32-
var eg InternalExample
31+
m := newMatcher(matchString, *match, "-test.run", *skip)
3332

33+
var eg InternalExample
3434
for _, eg = range examples {
35-
matched, err := matchString(*match, eg.Name)
36-
if err != nil {
37-
fmt.Fprintf(os.Stderr, "testing: invalid regexp for -test.run: %s\n", err)
38-
os.Exit(1)
39-
}
35+
_, matched, _ := m.fullName(nil, eg.Name)
4036
if !matched {
4137
continue
4238
}

0 commit comments

Comments
 (0)