]> Cypherpunks repositories - gostls13.git/commitdiff
testing: exit with error if testing.Short is called before flag.Parse
authorIan Lance Taylor <iant@golang.org>
Mon, 2 Jul 2018 17:36:49 +0000 (10:36 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 20 Aug 2018 21:51:11 +0000 (21:51 +0000)
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>
src/testing/testing.go

index a552b363617c62bc17db461a618408a8a43d9ada..179987b699aafc1ee0939627a5625d0aae8f21a9 100644 (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
 }