-
Notifications
You must be signed in to change notification settings - Fork 10
/
spike_test.go
67 lines (60 loc) · 1.37 KB
/
spike_test.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
56
57
58
59
60
61
62
63
64
65
66
67
package testcase_test
import (
"os"
"testing"
)
func Spike(tb testing.TB) {
if _, ok := os.LookupEnv(`SPIKE`); !ok {
tb.Skip()
}
}
// This spike meant to help manually verify the grouping mechanism of *testing.T
// > SPIKE=TRUE go testCase -run TestRunGroup -v
func TestRunGroup(t *testing.T) {
Spike(t)
t.Run(`single`, func(t *testing.T) {
t.Run(`foo`, func(t *testing.T) {
t.Run(`bar`, func(t *testing.T) {
t.Log(`foo-bar`)
})
t.Run(`baz`, func(t *testing.T) {
t.Log(`foo-baz`)
})
})
})
t.Run(`split`, func(t *testing.T) {
t.Run(`foo`, func(t *testing.T) {
t.Run(`bar`, func(t *testing.T) {
t.Log(`foo-bar`)
})
})
t.Run(`foo`, func(t *testing.T) {
t.Run(`baz`, func(t *testing.T) {
t.Log(`foo-baz`)
})
})
})
t.Run(`single+split with lambda`, func(t *testing.T) {
var eventually []func()
t.Run(`foo`, func(t *testing.T) {
eventually = append(eventually, func() {
t.Run(`bar`, func(t *testing.T) {
t.Log(`foo-bar`)
})
})
eventually = append(eventually, func() {
t.Run(`baz`, func(t *testing.T) {
t.Log(`foo-baz`)
})
})
// this will run list of them, because we are still within the `testing#T.Run` scope
for _, e := range eventually {
e()
}
})
// this will not run the testCase since foo `testing#T.Run` scope is closed
for _, e := range eventually {
e()
}
})
}