-
Notifications
You must be signed in to change notification settings - Fork 0
/
cogol_test.go
130 lines (99 loc) · 2.06 KB
/
cogol_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package cogol
import (
"sync"
"testing"
)
func TestStuff(t *testing.T) {
cgl := Init(t)
mu := &sync.Mutex{}
public := 0
g := cgl.Group("test runability")
{
g.TODO("todo 1")
g.TODO("todo 2")
g.T("Should be 2 todos in group", func(c *Context) {
mu.Lock()
public++
mu.Unlock()
c.Expect(len(g.todo)).ToBe(2)
})
g.T("Should be 3 tests in group", func(c *Context) {
mu.Lock()
public++
mu.Unlock()
c.Expect(len(g.children)).ToBe(3)
})
g.T("Running public 3rd time", func(c *Context) {
mu.Lock()
public++
mu.Unlock()
})
}
g2 := cgl.Group("Second")
{
g2.T("In cgl should be 2 groups", func(c *Context) {
c.Expect(len(cgl.children)).ToBe(2)
})
}
cgl.Process()
// All tests should be run
if public != 3 {
t.Fail()
}
}
func Test2(t *testing.T) {
cgl := Init(t)
mu := &sync.Mutex{}
public := 0
g := cgl.Group("Before and after each testing")
{
g.BeforeEach(func(c *Context) {
mu.Lock()
public++
mu.Unlock()
})
g.T("run 1", func(c *Context) {})
g.T("run 2", func(c *Context) {})
g.T("BeforeEach should be ran 3 times", func(c *Context) {})
}
g2 := cgl.Group("Testing persistence")
{
old := "old"
// Old BeforeEach
g2.BeforeEach(func(c *Context) {
c.Storage().Set(old, 727)
})
// Overriding BeforeEach
g2.BeforeEach(func(c *Context) {
c.Storage().Set(old, 4444)
})
g2.T("Should be overridden with 4444", func(c *Context) {
c.Expect(c.Storage().Get(old)).ToBe(4444)
})
}
cgl.Process()
if public != 3 {
t.Fail()
}
}
func TestContext_Kill(t *testing.T) {
faket := &testing.T{}
cgl := Init(faket)
g := cgl.Group("Context kill testing")
{
g.T("Context.Kill should fail the test immediately", func(c *Context) {
c.Kill("If it failed, then the test is passing")
})
g.T("ctx.Kill() calls after the first one should be ignored", func(c *Context) {
c.Kill("If it failed, then the test is passing")
c.Kill("Should not appear")
})
g.AfterEach(func(c *Context) {
c.Kill("Should not appear")
})
}
cgl.Process()
if !faket.Failed() {
t.Fail()
}
}