From: Dmitriy Vyukov Date: Thu, 1 Aug 2013 13:24:24 +0000 (+0400) Subject: testing: say what was the timeout if it fires X-Git-Tag: go1.2rc2~838 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=bd0a14fe4090ae2deb5dfe004ff5413ac259dc35;p=gostls13.git testing: say what was the timeout if it fires It looks reasonable here and may be useful. R=golang-dev, r CC=golang-dev https://golang.org/cl/12252043 --- diff --git a/src/pkg/testing/testing.go b/src/pkg/testing/testing.go index 330f3bdb80..85e751048e 100644 --- a/src/pkg/testing/testing.go +++ b/src/pkg/testing/testing.go @@ -371,12 +371,12 @@ func Main(matchString func(pat, str string) (bool, error), tests []InternalTest, haveExamples = len(examples) > 0 testOk := RunTests(matchString, tests) exampleOk := RunExamples(matchString, examples) + stopAlarm() if !testOk || !exampleOk { fmt.Println("FAIL") os.Exit(1) } fmt.Println("PASS") - stopAlarm() RunBenchmarks(matchString, benchmarks) after() } @@ -561,7 +561,9 @@ var timer *time.Timer // startAlarm starts an alarm if requested. func startAlarm() { if *timeout > 0 { - timer = time.AfterFunc(*timeout, alarm) + timer = time.AfterFunc(*timeout, func() { + panic(fmt.Sprintf("test timed out after %v", *timeout)) + }) } } @@ -572,11 +574,6 @@ func stopAlarm() { } } -// alarm is called if the timeout expires. -func alarm() { - panic("test timed out") -} - func parseCpuList() { if len(*cpuListStr) == 0 { cpuList = append(cpuList, runtime.GOMAXPROCS(-1))