aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2018-07-02 10:36:49 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2018-08-20 21:51:11 +0000
commitc9b018918d461da758e448ac370c2df8c6f77ab3 (patch)
tree8afcad8bb7090e1dc0ce4d7e0ab63f7e3006ad6f /src/testing/testing.go
parentd05f31a3c5677467525241d4bacdb287f485d370 (diff)
downloadgo-c9b018918d461da758e448ac370c2df8c6f77ab3.tar.xz
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>
Diffstat (limited to 'src/testing/testing.go')
-rw-r--r--src/testing/testing.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go
index a552b36361..179987b699 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -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
}