From c9b018918d461da758e448ac370c2df8c6f77ab3 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 2 Jul 2018 10:36:49 -0700 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/testing/testing.go | 7 +++++++ 1 file changed, 7 insertions(+) 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 } -- 2.50.0