diff options
author | Russ Cox <rsc@golang.org> | 2017-07-17 11:12:20 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2017-07-17 15:46:53 +0000 |
commit | 5ac16c6c76fc76f04844c92a6c54aeb97093e053 (patch) | |
tree | 8d89171c873c49bd67ffda28f69de0e8c48ecf69 | |
parent | 4522efb7f1e9bb7242c9f82076d3db5461f8647b (diff) | |
download | go-5ac16c6c76fc76f04844c92a6c54aeb97093e053.tar.gz go-5ac16c6c76fc76f04844c92a6c54aeb97093e053.zip |
strconv: fix initialization of atofRandomTests
The init func was using testing.Short, but that's not available
until after flag parsing. Found by CL 49251.
Change-Id: Ia7b871043375260873fa2c7e81e1d43c1c83d33f
Reviewed-on: https://go-review.googlesource.com/49253
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r-- | src/strconv/atof_test.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/strconv/atof_test.go b/src/strconv/atof_test.go index 0a89c3e0bf..f6c64789cb 100644 --- a/src/strconv/atof_test.go +++ b/src/strconv/atof_test.go @@ -10,6 +10,7 @@ import ( "reflect" . "strconv" "strings" + "sync" "testing" "time" ) @@ -213,12 +214,17 @@ type atofSimpleTest struct { } var ( + atofOnce sync.Once atofRandomTests []atofSimpleTest benchmarksRandomBits [1024]string benchmarksRandomNormal [1024]string ) -func init() { +func initAtof() { + atofOnce.Do(initAtof1) +} + +func initAtof1() { // The atof routines return NumErrors wrapping // the error and the string. Convert the table above. for i := range atoftests { @@ -261,6 +267,7 @@ func init() { } func testAtof(t *testing.T, opt bool) { + initAtof() oldopt := SetOptimize(opt) for i := 0; i < len(atoftests); i++ { test := &atoftests[i] @@ -306,6 +313,7 @@ func TestAtof(t *testing.T) { testAtof(t, true) } func TestAtofSlow(t *testing.T) { testAtof(t, false) } func TestAtofRandom(t *testing.T) { + initAtof() for _, test := range atofRandomTests { x, _ := ParseFloat(test.s, 64) switch { |