pkgArgs []string
pkgs []*load.Package
+ testHelp bool // -help option passed to test via -args
+
testKillTimeout = 100 * 365 * 24 * time.Hour // backup alarm; defaults to about a century if no timeout is set
testCacheExpire time.Time // ignore cached test results before this time
// testShowPass reports whether the output for a passing test should be shown.
func testShowPass() bool {
- return testV || (testList != "")
+ return testV || (testList != "") || testHelp
}
var defaultVetFlags = []string{
injectedFlags = append(injectedFlags, "-test.outputdir="+testOutputDir)
}
+ // If the user is explicitly passing -help or -h, show output
+ // of the test binary so that the help output is displayed
+ // even though the test will exit with success.
+ // This loop is imperfect: it will do the wrong thing for a case
+ // like -args -test.outputdir -help. Such cases are probably rare,
+ // and getting this wrong doesn't do too much harm.
+helpLoop:
+ for _, arg := range explicitArgs {
+ switch arg {
+ case "--":
+ break helpLoop
+ case "-h", "-help", "--help":
+ testHelp = true
+ break helpLoop
+ }
+ }
+
// Ensure that -race and -covermode are compatible.
if testCoverMode == "" {
testCoverMode = "set"
stderr '^usage: go test .*$'
stderr '^Run ''go help test'' and ''go help testflag'' for details.$'
+# Passing -help to the test binary should show flag help.
+go test ./x -args -help
+stdout 'usage_message'
+
# -covermode, -coverpkg, and -coverprofile should imply -cover
go test -covermode=set ./x
stdout '\s+coverage:\s+'
"testing"
)
+var _ = flag.String("usage_message", "", "dummy flag to check usage message")
+
func TestLogTimeout(t *testing.T) {
t.Log(flag.Lookup("test.timeout").Value)
}