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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
package spec_test
import (
"math/rand"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/internal/spec"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo/internal/codelocation"
"github.com/onsi/ginkgo/internal/containernode"
"github.com/onsi/ginkgo/internal/leafnodes"
"github.com/onsi/ginkgo/types"
)
var _ = Describe("Specs", func() {
var specs *Specs
newSpec := func(text string, flag types.FlagType) *Spec {
subject := leafnodes.NewItNode(text, func() {}, flag, codelocation.New(0), 0, nil, 0)
return New(subject, []*containernode.ContainerNode{}, false)
}
newMeasureSpec := func(text string, flag types.FlagType) *Spec {
subject := leafnodes.NewMeasureNode(text, func(Benchmarker) {}, flag, codelocation.New(0), 0, nil, 0)
return New(subject, []*containernode.ContainerNode{}, false)
}
newSpecs := func(args ...interface{}) *Specs {
specs := []*Spec{}
for index := 0; index < len(args)-1; index += 2 {
specs = append(specs, newSpec(args[index].(string), args[index+1].(types.FlagType)))
}
return NewSpecs(specs)
}
specTexts := func(specs *Specs) []string {
texts := []string{}
for _, spec := range specs.Specs() {
texts = append(texts, spec.ConcatenatedString())
}
return texts
}
willRunTexts := func(specs *Specs) []string {
texts := []string{}
for _, spec := range specs.Specs() {
if !(spec.Skipped() || spec.Pending()) {
texts = append(texts, spec.ConcatenatedString())
}
}
return texts
}
skippedTexts := func(specs *Specs) []string {
texts := []string{}
for _, spec := range specs.Specs() {
if spec.Skipped() {
texts = append(texts, spec.ConcatenatedString())
}
}
return texts
}
pendingTexts := func(specs *Specs) []string {
texts := []string{}
for _, spec := range specs.Specs() {
if spec.Pending() {
texts = append(texts, spec.ConcatenatedString())
}
}
return texts
}
Describe("Shuffling specs", func() {
It("should shuffle the specs using the passed in randomizer", func() {
specs17 := newSpecs("C", noneFlag, "A", noneFlag, "B", noneFlag)
specs17.Shuffle(rand.New(rand.NewSource(17)))
texts17 := specTexts(specs17)
specs17Again := newSpecs("C", noneFlag, "A", noneFlag, "B", noneFlag)
specs17Again.Shuffle(rand.New(rand.NewSource(17)))
texts17Again := specTexts(specs17Again)
specs15 := newSpecs("C", noneFlag, "A", noneFlag, "B", noneFlag)
specs15.Shuffle(rand.New(rand.NewSource(15)))
texts15 := specTexts(specs15)
specsUnshuffled := newSpecs("C", noneFlag, "A", noneFlag, "B", noneFlag)
textsUnshuffled := specTexts(specsUnshuffled)
Ω(textsUnshuffled).Should(Equal([]string{"C", "A", "B"}))
Ω(texts17).Should(Equal(texts17Again))
Ω(texts17).ShouldNot(Equal(texts15))
Ω(texts17).ShouldNot(Equal(textsUnshuffled))
Ω(texts15).ShouldNot(Equal(textsUnshuffled))
Ω(texts17).Should(HaveLen(3))
Ω(texts17).Should(ContainElement("A"))
Ω(texts17).Should(ContainElement("B"))
Ω(texts17).Should(ContainElement("C"))
Ω(texts15).Should(HaveLen(3))
Ω(texts15).Should(ContainElement("A"))
Ω(texts15).Should(ContainElement("B"))
Ω(texts15).Should(ContainElement("C"))
})
})
Describe("with no programmatic focus", func() {
BeforeEach(func() {
specs = newSpecs("A1", noneFlag, "A2", noneFlag, "B1", noneFlag, "B2", pendingFlag)
specs.ApplyFocus("", "", "")
})
It("should not report as having programmatic specs", func() {
Ω(specs.HasProgrammaticFocus()).Should(BeFalse())
})
})
Describe("Applying focus/skip", func() {
var description, focusString, skipString string
BeforeEach(func() {
description, focusString, skipString = "", "", ""
})
JustBeforeEach(func() {
specs = newSpecs("A1", focusedFlag, "A2", noneFlag, "B1", focusedFlag, "B2", pendingFlag)
specs.ApplyFocus(description, focusString, skipString)
})
Context("with neither a focus string nor a skip string", func() {
It("should apply the programmatic focus", func() {
Ω(willRunTexts(specs)).Should(Equal([]string{"A1", "B1"}))
Ω(skippedTexts(specs)).Should(Equal([]string{"A2", "B2"}))
Ω(pendingTexts(specs)).Should(BeEmpty())
})
It("should report as having programmatic specs", func() {
Ω(specs.HasProgrammaticFocus()).Should(BeTrue())
})
})
Context("with a focus regexp", func() {
BeforeEach(func() {
focusString = "A"
})
It("should override the programmatic focus", func() {
Ω(willRunTexts(specs)).Should(Equal([]string{"A1", "A2"}))
Ω(skippedTexts(specs)).Should(Equal([]string{"B1", "B2"}))
Ω(pendingTexts(specs)).Should(BeEmpty())
})
It("should not report as having programmatic specs", func() {
Ω(specs.HasProgrammaticFocus()).Should(BeFalse())
})
})
Context("with a focus regexp", func() {
BeforeEach(func() {
focusString = "B"
})
It("should not override any pendings", func() {
Ω(willRunTexts(specs)).Should(Equal([]string{"B1"}))
Ω(skippedTexts(specs)).Should(Equal([]string{"A1", "A2"}))
Ω(pendingTexts(specs)).Should(Equal([]string{"B2"}))
})
})
Context("with a description", func() {
BeforeEach(func() {
description = "C"
focusString = "C"
})
It("should include the description in the focus determination", func() {
Ω(willRunTexts(specs)).Should(Equal([]string{"A1", "A2", "B1"}))
Ω(skippedTexts(specs)).Should(BeEmpty())
Ω(pendingTexts(specs)).Should(Equal([]string{"B2"}))
})
})
Context("with a description", func() {
BeforeEach(func() {
description = "C"
skipString = "C"
})
It("should include the description in the focus determination", func() {
Ω(willRunTexts(specs)).Should(BeEmpty())
Ω(skippedTexts(specs)).Should(Equal([]string{"A1", "A2", "B1", "B2"}))
Ω(pendingTexts(specs)).Should(BeEmpty())
})
})
Context("with a skip regexp", func() {
BeforeEach(func() {
skipString = "A"
})
It("should override the programmatic focus", func() {
Ω(willRunTexts(specs)).Should(Equal([]string{"B1"}))
Ω(skippedTexts(specs)).Should(Equal([]string{"A1", "A2"}))
Ω(pendingTexts(specs)).Should(Equal([]string{"B2"}))
})
It("should not report as having programmatic specs", func() {
Ω(specs.HasProgrammaticFocus()).Should(BeFalse())
})
})
Context("with both a focus and a skip regexp", func() {
BeforeEach(func() {
focusString = "1"
skipString = "B"
})
It("should AND the two", func() {
Ω(willRunTexts(specs)).Should(Equal([]string{"A1"}))
Ω(skippedTexts(specs)).Should(Equal([]string{"A2", "B1", "B2"}))
Ω(pendingTexts(specs)).Should(BeEmpty())
})
It("should not report as having programmatic specs", func() {
Ω(specs.HasProgrammaticFocus()).Should(BeFalse())
})
})
})
Describe("With a focused spec within a pending context and a pending spec within a focused context", func() {
BeforeEach(func() {
pendingInFocused := New(
leafnodes.NewItNode("PendingInFocused", func() {}, pendingFlag, codelocation.New(0), 0, nil, 0),
[]*containernode.ContainerNode{
containernode.New("", focusedFlag, codelocation.New(0)),
}, false)
focusedInPending := New(
leafnodes.NewItNode("FocusedInPending", func() {}, focusedFlag, codelocation.New(0), 0, nil, 0),
[]*containernode.ContainerNode{
containernode.New("", pendingFlag, codelocation.New(0)),
}, false)
specs = NewSpecs([]*Spec{
newSpec("A", noneFlag),
newSpec("B", noneFlag),
pendingInFocused,
focusedInPending,
})
specs.ApplyFocus("", "", "")
})
It("should not have a programmatic focus and should run all tests", func() {
Ω(willRunTexts(specs)).Should(Equal([]string{"A", "B"}))
Ω(skippedTexts(specs)).Should(BeEmpty())
Ω(pendingTexts(specs)).Should(ConsistOf(ContainSubstring("PendingInFocused"), ContainSubstring("FocusedInPending")))
})
})
Describe("skipping measurements", func() {
BeforeEach(func() {
specs = NewSpecs([]*Spec{
newSpec("A", noneFlag),
newSpec("B", noneFlag),
newSpec("C", pendingFlag),
newMeasureSpec("measurementA", noneFlag),
newMeasureSpec("measurementB", pendingFlag),
})
})
It("should skip measurements", func() {
Ω(willRunTexts(specs)).Should(Equal([]string{"A", "B", "measurementA"}))
Ω(skippedTexts(specs)).Should(BeEmpty())
Ω(pendingTexts(specs)).Should(Equal([]string{"C", "measurementB"}))
specs.SkipMeasurements()
Ω(willRunTexts(specs)).Should(Equal([]string{"A", "B"}))
Ω(skippedTexts(specs)).Should(Equal([]string{"measurementA", "measurementB"}))
Ω(pendingTexts(specs)).Should(Equal([]string{"C"}))
})
})
})
|