aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.go
diff options
context:
space:
mode:
authorDaniel Martí <mvdan@mvdan.cc>2020-05-08 14:14:15 +0100
committerDaniel Martí <mvdan@mvdan.cc>2020-05-08 21:21:40 +0000
commit7cfa7d69259590319524c3715df4a39b39924bc3 (patch)
tree3e7636d582d6c8706e9d4ebe8e0caa91795d12fb /src/testing/testing.go
parent60368c2477d2517d7d4d83412eba5420fdb81a2b (diff)
downloadgo-7cfa7d69259590319524c3715df4a39b39924bc3.tar.gz
go-7cfa7d69259590319524c3715df4a39b39924bc3.zip
testing: tests and benchmarks can assume flag.Parsed
testing.M.Run has this bit of code: if !flag.Parsed() { flag.Parse() } It makes sense, and it's common knowledge for many Go developers that test flags are automatically parsed by the time tests and benchmarks are run. However, the docs didn't clarify that. The previous wording only mentioned that flag.Parse isn't run before TestMain, which doesn't necessarily mean that it's run afterwards. Fixes #38952. Change-Id: I85f7a9dce637a23c5cb9abc485d47415c1a1ca27 Reviewed-on: https://go-review.googlesource.com/c/go/+/232806 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/testing/testing.go')
-rw-r--r--src/testing/testing.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 90c15a2cff..216e46ee81 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -219,9 +219,12 @@
// directly. TestMain runs in the main goroutine and can do whatever setup
// and teardown is necessary around a call to m.Run. m.Run will return an exit
// code that may be passed to os.Exit. If TestMain returns, the test wrapper
-// will pass the result of m.Run to os.Exit itself. When TestMain is called,
-// flag.Parse has not been run. If TestMain depends on command-line flags,
-// including those of the testing package, it should call flag.Parse explicitly.
+// will pass the result of m.Run to os.Exit itself.
+//
+// When TestMain is called, flag.Parse has not been run. If TestMain depends on
+// command-line flags, including those of the testing package, it should call
+// flag.Parse explicitly. Command line flags are always parsed by the time test
+// or benchmark functions run.
//
// A simple implementation of TestMain is:
//