]> Cypherpunks repositories - gostls13.git/commit
cmd/go: move automatic testing.Init call into generated test code
authorCaleb Spare <cespare@gmail.com>
Wed, 8 May 2019 20:38:14 +0000 (13:38 -0700)
committerBryan C. Mills <bcmills@google.com>
Fri, 10 May 2019 18:10:48 +0000 (18:10 +0000)
commit49a1a01bb106f0e65a5147be5eb5f8dd60323e39
treead9ac4c81129221c86a0d642379cdb90963910ca
parent5833aa507bd25df20b2aecf9e2334dccfa2dac76
cmd/go: move automatic testing.Init call into generated test code

In CL 173722, we moved the flag registration in the testing package into
an Init function. In order to avoid needing changes to user code, we
called Init automatically as part of testing.MainStart.

However, that isn't early enough if flag.Parse is called before the
tests run, as part of package initialization.

Fix this by injecting a bit of code to call testing.Init into test
packages. This runs before any other initialization code in the user's
test package, so testing.Init will be called before any user code can
call flag.Parse.

Fixes #31859

Change-Id: Ib42cd8d3819150c49a3cecf7eef2472319d0c7e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/176098
Run-TryBot: Caleb Spare <cespare@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/go_test.go
src/cmd/go/internal/list/list.go
src/cmd/go/internal/load/pkg.go
src/cmd/go/internal/load/test.go
src/cmd/go/internal/test/test.go
src/cmd/go/internal/work/exec.go
src/cmd/go/testdata/flag_test.go
src/cmd/go/testdata/script/test_init.txt [new file with mode: 0644]
src/cmd/go/testdata/standalone_testmain_flag_test.go [deleted file]
src/testing/testing.go