diff options
author | Caleb Spare <cespare@gmail.com> | 2019-05-08 13:38:14 -0700 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2019-05-10 18:10:48 +0000 |
commit | 49a1a01bb106f0e65a5147be5eb5f8dd60323e39 (patch) | |
tree | ad9ac4c81129221c86a0d642379cdb90963910ca /src/cmd/go/internal/test/test.go | |
parent | 5833aa507bd25df20b2aecf9e2334dccfa2dac76 (diff) | |
download | go-49a1a01bb106f0e65a5147be5eb5f8dd60323e39.tar.gz go-49a1a01bb106f0e65a5147be5eb5f8dd60323e39.zip |
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>
Diffstat (limited to 'src/cmd/go/internal/test/test.go')
-rw-r--r-- | src/cmd/go/internal/test/test.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go index 9b9bbce0dd..98a8c8756c 100644 --- a/src/cmd/go/internal/test/test.go +++ b/src/cmd/go/internal/test/test.go @@ -835,7 +835,7 @@ func builderTest(b *work.Builder, p *load.Package) (buildAction, runAction, prin if !cfg.BuildN { // writeTestmain writes _testmain.go, // using the test description gathered in t. - if err := ioutil.WriteFile(testDir+"_testmain.go", *pmain.Internal.TestmainGo, 0666); err != nil { + if err := ioutil.WriteFile(testDir+"_testmain.go", pmain.Internal.TestmainGo, 0666); err != nil { return nil, nil, nil, err } } |