Skip to content

testing: enforce -skip in example tests #61491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/cmd/go/testdata/script/test_skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ stdout RUN.*Test2/3
go test -v -skip 2/3 skip_test.go
stdout RUN.*Test1
stdout RUN.*Test2
stdout RUN.*ExampleTest1
! stdout Test2/3

go test -v -skip 2/4 skip_test.go
stdout RUN.*Test1
stdout RUN.*Test2
stdout RUN.*Test2/3
stdout RUN.*ExampleTest1

go test -v -skip Example skip_test.go
stdout RUN.*Test1
stdout RUN.*Test2
stdout RUN.*Test2/3

-- skip_test.go --
package skip_test
Expand All @@ -32,3 +38,7 @@ func Test1(t *testing.T) {
func Test2(t *testing.T) {
t.Run("3", func(t *testing.T) {})
}

func ExampleTest1() {
// Output:
}
10 changes: 3 additions & 7 deletions src/testing/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package testing

import (
"fmt"
"os"
"sort"
"strings"
"time"
Expand All @@ -29,14 +28,11 @@ func RunExamples(matchString func(pat, str string) (bool, error), examples []Int
func runExamples(matchString func(pat, str string) (bool, error), examples []InternalExample) (ran, ok bool) {
ok = true

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

var eg InternalExample
for _, eg = range examples {
matched, err := matchString(*match, eg.Name)
if err != nil {
fmt.Fprintf(os.Stderr, "testing: invalid regexp for -test.run: %s\n", err)
os.Exit(1)
}
_, matched, _ := m.fullName(nil, eg.Name)
if !matched {
continue
}
Expand Down