]> Cypherpunks repositories - gostls13.git/commitdiff
testing: say what was the timeout if it fires
authorDmitriy Vyukov <dvyukov@google.com>
Thu, 1 Aug 2013 13:24:24 +0000 (17:24 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Thu, 1 Aug 2013 13:24:24 +0000 (17:24 +0400)
It looks reasonable here and may be useful.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/12252043

src/pkg/testing/testing.go

index 330f3bdb8066611f7453027524e8a167473051f3..85e751048e21ee4109f73df0443d3e1725d66a28 100644 (file)
@@ -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))