testing: exit with error if testing.Short is called before flag.Parse

Change-Id: I2fa547d1074ef0931196066678fadd7250a1148d
Reviewed-on: https://go-review.googlesource.com/121936
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Ian Lance Taylor 2018-07-02 10:36:49 -07:00 committed by Brad Fitzpatrick
parent d05f31a3c5
commit c9b018918d

View file

@ -316,6 +316,13 @@ type common struct {
// Short reports whether the -test.short flag is set.
func Short() bool {
// Catch code that calls this from TestMain without first
// calling flag.Parse. This shouldn't really be a panic
if !flag.Parsed() {
fmt.Fprintf(os.Stderr, "testing: testing.Short called before flag.Parse\n")
os.Exit(2)
}
return *short
}