diff options
author | Brandon Bennett <bbennett@fb.com> | 2017-04-20 10:26:10 -0600 |
---|---|---|
committer | Marcel van Lohuizen <mpvl@golang.org> | 2017-04-26 15:53:32 +0000 |
commit | ba8ff87dbeb87813a4604e36adb609b1e8fcb7be (patch) | |
tree | 515161a914c3b7a841bd095a1ed9300470466a65 /src/testing | |
parent | 6e2c4bc012f8cc262db25d3fee414c5231fea03a (diff) | |
download | go-git-ba8ff87dbeb87813a4604e36adb609b1e8fcb7be.tar.gz |
testing: add argument to list tests, benchmarks, and examples
Some large testing/build systems require some form of test discovery before
running tests. This usually allows for analytics, history, and stats on a per
tests basis. Typically these systems are meant used in multi-language
environments and the original source code is not known or available.
This adds a -test.list option which takes a regular expression as an
argument. Any tests, benchmarks, or examples that match that regular
expression will be printed, one per line, to stdout and then the program
will exit.
Since subtests are named/discovered at run time this will only show
top-level tests names and is a known limitation.
Fixes #17209
Change-Id: I7e607f5f4f084d623a1cae88a1f70e7d92b7f13e
Reviewed-on: https://go-review.googlesource.com/41195
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/testing.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go index 99e9af43b6..aa620f42b8 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -252,6 +252,7 @@ var ( chatty = flag.Bool("test.v", false, "verbose: print additional output") count = flag.Uint("test.count", 1, "run tests and benchmarks `n` times") coverProfile = flag.String("test.coverprofile", "", "write a coverage profile to `file`") + matchList = flag.String("test.list", "", "list tests, examples, and benchmarch maching `regexp` then exit") match = flag.String("test.run", "", "run only tests and examples matching `regexp`") memProfile = flag.String("test.memprofile", "", "write a memory profile to `file`") memProfileRate = flag.Int("test.memprofilerate", 0, "set memory profiling `rate` (see runtime.MemProfileRate)") @@ -907,6 +908,11 @@ func (m *M) Run() int { flag.Parse() } + if len(*matchList) != 0 { + listTests(m.deps.MatchString, m.tests, m.benchmarks, m.examples) + return 0 + } + parseCpuList() m.before() @@ -946,6 +952,29 @@ func (t *T) report() { } } +func listTests(matchString func(pat, str string) (bool, error), tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) { + if _, err := matchString(*matchList, "non-empty"); err != nil { + fmt.Fprintf(os.Stderr, "testing: invalid regexp in -test.list (%q): %s\n", *matchList, err) + os.Exit(1) + } + + for _, test := range tests { + if ok, _ := matchString(*matchList, test.Name); ok { + fmt.Println(test.Name) + } + } + for _, bench := range benchmarks { + if ok, _ := matchString(*matchList, bench.Name); ok { + fmt.Println(bench.Name) + } + } + for _, example := range examples { + if ok, _ := matchString(*matchList, example.Name); ok && example.Output != "" { + fmt.Println(example.Name) + } + } +} + // An internal function but exported because it is cross-package; part of the implementation // of the "go test" command. func RunTests(matchString func(pat, str string) (bool, error), tests []InternalTest) (ok bool) { |