blob: fcfacf5fc13ffb1f059201586177e8900f8ffc17 [file] [log] [blame]
Carl Mastrangelo3c786242015-12-02 14:46:50 -08001package http2interop
2
3import (
4 "runtime"
5 "strings"
6 "sync"
7 "testing"
8)
9
10// When a test is skipped or fails, runtime.Goexit() is called which destroys the callstack.
11// This means the name of the test case is lost, so we need to grab a copy of pc before.
12func Report(t testing.TB) func() {
13 pc, _, _, ok := runtime.Caller(1)
14 if !ok {
15 t.Fatal("Can't get caller info")
16 }
17 return func() {
18 fn := runtime.FuncForPC(pc)
19 fullName := fn.Name()
20 name := strings.Split(fullName, ".")[1]
21 allCaseInfos.lock.Lock()
22 defer allCaseInfos.lock.Unlock()
23 allCaseInfos.Cases = append(allCaseInfos.Cases, &caseInfo{
24 Name: name,
25 Passed: !t.Failed(),
26 Skipped: t.Skipped(),
27 })
28 }
29}
30
31type caseInfo struct {
32 Name string `json:"name"`
33 Passed bool `json:"passed"`
34 Skipped bool `json:"skipped"`
35}
36
37type caseInfos struct {
38 lock sync.Mutex
39 Cases []*caseInfo `json:"cases"`
40}
41
42var (
43 allCaseInfos = caseInfos{}
44)