go/src/testing
Caleb Spare fbc6a97222 testing: delay flag registration; move to an Init function
Any code that imports the testing package forces the testing flags to be
defined, even in non-test binaries. People work around this today by
defining a copy of the testing.TB interface just to avoid importing
testing.

Fix this by moving flag registration into a new function, testing.Init.
Delay calling Init until the testing binary begins to run, in
testing.MainStart.

Init is exported for cases where users need the testing flags to be
defined outside of a "go test" context. In particular, this may be
needed where testing.Benchmark is called outside of a test.

Fixes #21051

Change-Id: Ib7e02459e693c26ae1ba71bbae7d455a91118ee3
Reviewed-on: https://go-review.googlesource.com/c/go/+/173722
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-29 19:54:30 +00:00
..
internal/testdeps runtime/pprof: introduce "allocs" profile 2018-04-24 16:11:41 +00:00
iotest testing/iotest: fix NewReadLogger documentation typo 2017-10-19 15:59:21 +00:00
quick testing/quick: simplify explanation of -quickchecks flag 2019-04-18 21:21:21 +00:00
allocs.go
allocs_test.go
benchmark.go testing: delay flag registration; move to an Init function 2019-04-29 19:54:30 +00:00
benchmark_test.go testing: fix fractional ns/op printing 2019-03-22 21:19:22 +00:00
cover.go testing/cover: improve message when a package has no statements 2019-03-13 04:11:58 +00:00
example.go testing: enable examples on js/wasm with non os.Pipe runExample 2019-03-11 18:59:53 +00:00
export_test.go testing: stop rounding b.N 2019-03-20 21:19:16 +00:00
helper_test.go testing: allow marking subtest and subbenchmark functions as Helpers 2018-05-14 17:59:59 +00:00
helperfuncs_test.go testing: allow marking subtest and subbenchmark functions as Helpers 2018-05-14 17:59:59 +00:00
match.go testing: fix typo mistake 2018-04-27 13:29:12 +00:00
match_test.go testing: harmonize handling of prefix-matched benchmarks 2017-06-20 14:19:05 +00:00
run_example.go testing: enable examples on js/wasm with non os.Pipe runExample 2019-03-11 18:59:53 +00:00
run_example_js.go testing: enable examples on js/wasm with non os.Pipe runExample 2019-03-11 18:59:53 +00:00
sub_test.go testing: delay flag registration; move to an Init function 2019-04-29 19:54:30 +00:00
testing.go testing: delay flag registration; move to an Init function 2019-04-29 19:54:30 +00:00
testing_test.go