]> Cypherpunks repositories - gostls13.git/commit
testing: only call flag.Parse if it has not been called before
authorAlberto Bertogli <albertito@blitiri.com.ar>
Fri, 6 Nov 2015 01:40:56 +0000 (01:40 +0000)
committerRuss Cox <rsc@golang.org>
Thu, 12 Nov 2015 19:48:06 +0000 (19:48 +0000)
commitab196aeff21bedd7acd0e38d74e77989255f1d3f
tree3d3e1e5e1f776a53499a649e5a7e0a1a74e4f6b8
parenta9ca2137aa3ebcf9cf094b20cf30cf50ba577892
testing: only call flag.Parse if it has not been called before

Calling flag.Parse twice can be problematic if other goroutines called
flag.Parsed in between: the race detector complains due to the
write after read from a different goroutine.

This can happen if TestMain calls flag.Parse and launches goroutines
that call flag.Parsed, for example if it initializes a server which
checks flags.

This patch makes testing.M.Run only parse the flags if they have not
been parsed already.

Change-Id: Id9f8c31c5f90614e3f34c63d1a32cf7e9055d68e
Reviewed-on: https://go-review.googlesource.com/16739
Reviewed-by: Russ Cox <rsc@golang.org>
src/testing/testing.go