-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (47 loc) · 843 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package testingc
import (
"testing"
)
type M struct {
m *testing.M
C
}
func (m *M) checkFailed() {
m.smu.Lock()
status := m.status
m.smu.Unlock()
if status&failed == failed {
m.FailNow()
}
}
func (m *M) Run() (code int) {
m.checkFailed()
return m.m.Run()
}
func (m *M) Name() string {
return "testingc.Main"
}
func Main(m *testing.M, fn func(m *M)) {
c := &M{
m: m,
C: C{
panicOnFail: true,
},
}
done := make(chan struct{})
go func() {
defer func() {
defer func() {
// If Main returns before the runtime detects a panic which is
// not recovered, Main will not fail.
// To wait for the goroutine that may cause a panic to exit first,
// schedule the close of `done` in another new gorountine.
go close(done)
}()
c.teardown(false)
c.checkFailed()
}()
fn(c)
}()
<-done
}