Skip to content

Commit 93dfc16

Browse files
author
Dave Abrahams
committed
[stdlib] More reliably avoid running duplicate tests
Removing the “checksAdded” parameter from collection unit tests and simply sharing a global variable is a better way to go. We don't use threads at that level, so there's no thread safety issue, and we already committed to globals when we introduced the logging wrappers.
1 parent 0c0bcbb commit 93dfc16

File tree

129 files changed

+30
-389
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+30
-389
lines changed

stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift.gyb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import StdlibUnittest
1414

15+
internal var checksAdded: Set<String> = []
16+
1517
public struct SubscriptRangeTest {
1618
public let expected: [OpaqueValue<Int>]
1719
public let collection: [OpaqueValue<Int>]
@@ -479,7 +481,6 @@ internal func _product<C1 : Collection, C2 : Collection>(
479481
extractValueFromEquatable:
480482
((CollectionWithEquatableElement.Iterator.Element) -> MinimalEquatableValue),
481483

482-
checksAdded: Box<Set<String>> = Box([]),
483484
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
484485
outOfBoundsIndexOffset: Int = 1,
485486
outOfBoundsSubscriptOffset: Int = 1,
@@ -498,10 +499,10 @@ extension TestSuite {
498499
>(${testParams} = false) {
499500
var testNamePrefix = testNamePrefix
500501

501-
if checksAdded.value.contains(#function) {
502+
if checksAdded.contains(#function) {
502503
return
503504
}
504-
checksAdded.value.insert(#function)
505+
checksAdded.insert(#function)
505506

506507
addSequenceTests(
507508
testNamePrefix,
@@ -511,7 +512,6 @@ extension TestSuite {
511512
makeSequenceOfEquatable: makeCollectionOfEquatable,
512513
wrapValueIntoEquatable: wrapValueIntoEquatable,
513514
extractValueFromEquatable: extractValueFromEquatable,
514-
checksAdded: checksAdded,
515515
resiliencyChecks: resiliencyChecks)
516516

517517
func makeWrappedCollection(_ elements: [OpaqueValue<Int>]) -> C {
@@ -1164,10 +1164,10 @@ extension TestSuite {
11641164
${testConstraints('BidirectionalCollection')}
11651165
>(${testParams} = true) {
11661166
var testNamePrefix = testNamePrefix
1167-
if checksAdded.value.contains(#function) {
1167+
if checksAdded.contains(#function) {
11681168
return
11691169
}
1170-
checksAdded.value.insert(#function)
1170+
checksAdded.insert(#function)
11711171

11721172
addCollectionTests(${forwardTestArgs})
11731173

@@ -1477,10 +1477,10 @@ extension TestSuite {
14771477
>(${testParams} = true) {
14781478
var testNamePrefix = testNamePrefix
14791479

1480-
if checksAdded.value.contains(#function) {
1480+
if checksAdded.contains(#function) {
14811481
return
14821482
}
1483-
checksAdded.value.insert(#function)
1483+
checksAdded.insert(#function)
14841484

14851485
addBidirectionalCollectionTests(${forwardTestArgs})
14861486

@@ -1526,10 +1526,10 @@ extension TestSuite {
15261526
func addCommonTests<
15271527
${testConstraints(collectionForTraversal(Traversal))}
15281528
>(${testParams}) {
1529-
if checksAdded.value.contains(#function) {
1529+
if checksAdded.contains(#function) {
15301530
return
15311531
}
1532-
checksAdded.value.insert(#function)
1532+
checksAdded.insert(#function)
15331533

15341534
func toCollection(_ r: CountableRange<Int>) -> C {
15351535
return makeCollection(r.map { wrapValue(OpaqueValue($0)) })

stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ extension TestSuite {
102102
wrapValueIntoComparable: (MinimalComparableValue) -> CollectionWithComparableElement.Iterator.Element,
103103
extractValueFromComparable: ((CollectionWithComparableElement.Iterator.Element) -> MinimalComparableValue),
104104

105-
checksAdded: Box<Set<String>> = Box([]),
106105
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
107106
outOfBoundsIndexOffset: Int = 1,
108107
outOfBoundsSubscriptOffset: Int = 1,
@@ -112,10 +111,10 @@ extension TestSuite {
112111
) {
113112
var testNamePrefix = testNamePrefix
114113

115-
if checksAdded.value.contains(#function) {
114+
if checksAdded.contains(#function) {
116115
return
117116
}
118-
checksAdded.value.insert(#function)
117+
checksAdded.insert(#function)
119118

120119
addCollectionTests(
121120
testNamePrefix,
@@ -125,7 +124,6 @@ extension TestSuite {
125124
makeCollectionOfEquatable: makeCollectionOfEquatable,
126125
wrapValueIntoEquatable: wrapValueIntoEquatable,
127126
extractValueFromEquatable: extractValueFromEquatable,
128-
checksAdded: checksAdded,
129127
resiliencyChecks: resiliencyChecks,
130128
outOfBoundsIndexOffset: outOfBoundsIndexOffset,
131129
outOfBoundsSubscriptOffset: outOfBoundsSubscriptOffset,
@@ -614,7 +612,6 @@ self.test("\(testNamePrefix).sorted/${'Predicate' if predicate else 'WhereElemen
614612
wrapValueIntoComparable: (MinimalComparableValue) -> CollectionWithComparableElement.Iterator.Element,
615613
extractValueFromComparable: ((CollectionWithComparableElement.Iterator.Element) -> MinimalComparableValue),
616614

617-
checksAdded: Box<Set<String>> = Box([]),
618615
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
619616
outOfBoundsIndexOffset: Int = 1,
620617
outOfBoundsSubscriptOffset: Int = 1,
@@ -623,10 +620,10 @@ self.test("\(testNamePrefix).sorted/${'Predicate' if predicate else 'WhereElemen
623620
) {
624621
var testNamePrefix = testNamePrefix
625622

626-
if checksAdded.value.contains(#function) {
623+
if checksAdded.contains(#function) {
627624
return
628625
}
629-
checksAdded.value.insert(#function)
626+
checksAdded.insert(#function)
630627

631628
addMutableCollectionTests(
632629
testNamePrefix,
@@ -639,7 +636,6 @@ self.test("\(testNamePrefix).sorted/${'Predicate' if predicate else 'WhereElemen
639636
makeCollectionOfComparable: makeCollectionOfComparable,
640637
wrapValueIntoComparable: wrapValueIntoComparable,
641638
extractValueFromComparable: extractValueFromComparable,
642-
checksAdded: checksAdded,
643639
resiliencyChecks: resiliencyChecks,
644640
outOfBoundsIndexOffset: outOfBoundsIndexOffset,
645641
outOfBoundsSubscriptOffset: outOfBoundsSubscriptOffset,
@@ -657,7 +653,6 @@ self.test("\(testNamePrefix).sorted/${'Predicate' if predicate else 'WhereElemen
657653
makeCollectionOfEquatable: makeCollectionOfEquatable,
658654
wrapValueIntoEquatable: wrapValueIntoEquatable,
659655
extractValueFromEquatable: extractValueFromEquatable,
660-
checksAdded: checksAdded,
661656
resiliencyChecks: resiliencyChecks,
662657
outOfBoundsIndexOffset: outOfBoundsIndexOffset,
663658
outOfBoundsSubscriptOffset: outOfBoundsSubscriptOffset)
@@ -725,7 +720,6 @@ if resiliencyChecks.subscriptOnOutOfBoundsIndicesBehavior != .none {
725720
wrapValueIntoComparable: (MinimalComparableValue) -> CollectionWithComparableElement.Iterator.Element,
726721
extractValueFromComparable: ((CollectionWithComparableElement.Iterator.Element) -> MinimalComparableValue),
727722

728-
checksAdded: Box<Set<String>> = Box([]),
729723
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
730724
outOfBoundsIndexOffset: Int = 1,
731725
outOfBoundsSubscriptOffset: Int = 1,
@@ -734,10 +728,10 @@ if resiliencyChecks.subscriptOnOutOfBoundsIndicesBehavior != .none {
734728
) {
735729
var testNamePrefix = testNamePrefix
736730

737-
if checksAdded.value.contains(#function) {
731+
if checksAdded.contains(#function) {
738732
return
739733
}
740-
checksAdded.value.insert(#function)
734+
checksAdded.insert(#function)
741735

742736
addMutableBidirectionalCollectionTests(
743737
testNamePrefix,
@@ -750,7 +744,6 @@ if resiliencyChecks.subscriptOnOutOfBoundsIndicesBehavior != .none {
750744
makeCollectionOfComparable: makeCollectionOfComparable,
751745
wrapValueIntoComparable: wrapValueIntoComparable,
752746
extractValueFromComparable: extractValueFromComparable,
753-
checksAdded: checksAdded,
754747
resiliencyChecks: resiliencyChecks,
755748
outOfBoundsIndexOffset: outOfBoundsIndexOffset,
756749
outOfBoundsSubscriptOffset: outOfBoundsSubscriptOffset,
@@ -766,7 +759,6 @@ if resiliencyChecks.subscriptOnOutOfBoundsIndicesBehavior != .none {
766759
makeCollectionOfEquatable: makeCollectionOfEquatable,
767760
wrapValueIntoEquatable: wrapValueIntoEquatable,
768761
extractValueFromEquatable: extractValueFromEquatable,
769-
checksAdded: checksAdded,
770762
resiliencyChecks: resiliencyChecks,
771763
outOfBoundsIndexOffset: outOfBoundsIndexOffset,
772764
outOfBoundsSubscriptOffset: outOfBoundsSubscriptOffset)

stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableCollectionType.swift

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -442,17 +442,16 @@ extension TestSuite {
442442
wrapValueIntoEquatable: (MinimalEquatableValue) -> CollectionWithEquatableElement.Iterator.Element,
443443
extractValueFromEquatable: ((CollectionWithEquatableElement.Iterator.Element) -> MinimalEquatableValue),
444444

445-
checksAdded: Box<Set<String>> = Box([]),
446445
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
447446
outOfBoundsIndexOffset: Int = 1,
448447
collectionIsBidirectional: Bool = false
449448
) {
450449
var testNamePrefix = testNamePrefix
451450

452-
if checksAdded.value.contains(#function) {
451+
if checksAdded.contains(#function) {
453452
return
454453
}
455-
checksAdded.value.insert(#function)
454+
checksAdded.insert(#function)
456455

457456
addCollectionTests(
458457
testNamePrefix,
@@ -462,7 +461,6 @@ extension TestSuite {
462461
makeCollectionOfEquatable: makeCollectionOfEquatable,
463462
wrapValueIntoEquatable: wrapValueIntoEquatable,
464463
extractValueFromEquatable: extractValueFromEquatable,
465-
checksAdded: checksAdded,
466464
resiliencyChecks: resiliencyChecks,
467465
outOfBoundsIndexOffset: outOfBoundsIndexOffset,
468466
collectionIsBidirectional: collectionIsBidirectional
@@ -1171,16 +1169,15 @@ self.test("\(testNamePrefix).OperatorPlus") {
11711169
wrapValueIntoEquatable: (MinimalEquatableValue) -> CollectionWithEquatableElement.Iterator.Element,
11721170
extractValueFromEquatable: ((CollectionWithEquatableElement.Iterator.Element) -> MinimalEquatableValue),
11731171

1174-
checksAdded: Box<Set<String>> = Box([]),
11751172
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
11761173
outOfBoundsIndexOffset: Int = 1
11771174
) {
11781175
var testNamePrefix = testNamePrefix
11791176

1180-
if checksAdded.value.contains(#function) {
1177+
if checksAdded.contains(#function) {
11811178
return
11821179
}
1183-
checksAdded.value.insert(#function)
1180+
checksAdded.insert(#function)
11841181

11851182
addRangeReplaceableCollectionTests(
11861183
testNamePrefix,
@@ -1190,7 +1187,6 @@ self.test("\(testNamePrefix).OperatorPlus") {
11901187
makeCollectionOfEquatable: makeCollectionOfEquatable,
11911188
wrapValueIntoEquatable: wrapValueIntoEquatable,
11921189
extractValueFromEquatable: extractValueFromEquatable,
1193-
checksAdded: checksAdded,
11941190
resiliencyChecks: resiliencyChecks,
11951191
outOfBoundsIndexOffset: outOfBoundsIndexOffset,
11961192
collectionIsBidirectional: true
@@ -1204,7 +1200,6 @@ self.test("\(testNamePrefix).OperatorPlus") {
12041200
makeCollectionOfEquatable: makeCollectionOfEquatable,
12051201
wrapValueIntoEquatable: wrapValueIntoEquatable,
12061202
extractValueFromEquatable: extractValueFromEquatable,
1207-
checksAdded: checksAdded,
12081203
resiliencyChecks: resiliencyChecks,
12091204
outOfBoundsIndexOffset: outOfBoundsIndexOffset)
12101205

@@ -1302,16 +1297,15 @@ self.test("\(testNamePrefix).removeLast(n: Int)/whereIndexIsBidirectional/remove
13021297
wrapValueIntoEquatable: (MinimalEquatableValue) -> CollectionWithEquatableElement.Iterator.Element,
13031298
extractValueFromEquatable: ((CollectionWithEquatableElement.Iterator.Element) -> MinimalEquatableValue),
13041299

1305-
checksAdded: Box<Set<String>> = Box([]),
13061300
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
13071301
outOfBoundsIndexOffset: Int = 1
13081302
) {
13091303
var testNamePrefix = testNamePrefix
13101304

1311-
if checksAdded.value.contains(#function) {
1305+
if checksAdded.contains(#function) {
13121306
return
13131307
}
1314-
checksAdded.value.insert(#function)
1308+
checksAdded.insert(#function)
13151309

13161310
addRangeReplaceableBidirectionalCollectionTests(
13171311
testNamePrefix,
@@ -1321,7 +1315,6 @@ self.test("\(testNamePrefix).removeLast(n: Int)/whereIndexIsBidirectional/remove
13211315
makeCollectionOfEquatable: makeCollectionOfEquatable,
13221316
wrapValueIntoEquatable: wrapValueIntoEquatable,
13231317
extractValueFromEquatable: extractValueFromEquatable,
1324-
checksAdded: checksAdded,
13251318
resiliencyChecks: resiliencyChecks,
13261319
outOfBoundsIndexOffset: outOfBoundsIndexOffset)
13271320

@@ -1333,7 +1326,6 @@ self.test("\(testNamePrefix).removeLast(n: Int)/whereIndexIsBidirectional/remove
13331326
makeCollectionOfEquatable: makeCollectionOfEquatable,
13341327
wrapValueIntoEquatable: wrapValueIntoEquatable,
13351328
extractValueFromEquatable: extractValueFromEquatable,
1336-
checksAdded: checksAdded,
13371329
resiliencyChecks: resiliencyChecks,
13381330
outOfBoundsIndexOffset: outOfBoundsIndexOffset)
13391331

stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableSliceType.swift

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,17 @@ extension TestSuite {
3636
wrapValueIntoEquatable: (MinimalEquatableValue) -> CollectionWithEquatableElement.Iterator.Element,
3737
extractValueFromEquatable: ((CollectionWithEquatableElement.Iterator.Element) -> MinimalEquatableValue),
3838

39-
checksAdded: Box<Set<String>> = Box([]),
4039
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
4140
outOfBoundsIndexOffset: Int = 1,
4241
collectionIsBidirectional: Bool = false
4342
) {
4443
var testNamePrefix = testNamePrefix
4544

4645
// Don't run the same tests twice.
47-
if checksAdded.value.contains(#function) {
46+
if checksAdded.contains(#function) {
4847
return
4948
}
50-
checksAdded.value.insert(#function)
49+
checksAdded.insert(#function)
5150

5251
addRangeReplaceableCollectionTests(
5352
testNamePrefix,
@@ -57,7 +56,6 @@ extension TestSuite {
5756
makeCollectionOfEquatable: makeCollectionOfEquatable,
5857
wrapValueIntoEquatable: wrapValueIntoEquatable,
5958
extractValueFromEquatable: extractValueFromEquatable,
60-
checksAdded: checksAdded,
6159
resiliencyChecks: resiliencyChecks,
6260
outOfBoundsIndexOffset: outOfBoundsIndexOffset,
6361
collectionIsBidirectional: collectionIsBidirectional
@@ -173,17 +171,16 @@ extension TestSuite {
173171
wrapValueIntoEquatable: (MinimalEquatableValue) -> CollectionWithEquatableElement.Iterator.Element,
174172
extractValueFromEquatable: ((CollectionWithEquatableElement.Iterator.Element) -> MinimalEquatableValue),
175173

176-
checksAdded: Box<Set<String>> = Box([]),
177174
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
178175
outOfBoundsIndexOffset: Int = 1
179176
) {
180177
var testNamePrefix = testNamePrefix
181178

182179
// Don't run the same tests twice.
183-
if checksAdded.value.contains(#function) {
180+
if checksAdded.contains(#function) {
184181
return
185182
}
186-
checksAdded.value.insert(#function)
183+
checksAdded.insert(#function)
187184

188185
addRangeReplaceableSliceTests(
189186
testNamePrefix,
@@ -193,7 +190,6 @@ extension TestSuite {
193190
makeCollectionOfEquatable: makeCollectionOfEquatable,
194191
wrapValueIntoEquatable: wrapValueIntoEquatable,
195192
extractValueFromEquatable: extractValueFromEquatable,
196-
checksAdded: checksAdded,
197193
resiliencyChecks: resiliencyChecks,
198194
outOfBoundsIndexOffset: outOfBoundsIndexOffset,
199195
collectionIsBidirectional: true
@@ -207,7 +203,6 @@ extension TestSuite {
207203
makeCollectionOfEquatable: makeCollectionOfEquatable,
208204
wrapValueIntoEquatable: wrapValueIntoEquatable,
209205
extractValueFromEquatable: extractValueFromEquatable,
210-
checksAdded: checksAdded,
211206
resiliencyChecks: resiliencyChecks,
212207
outOfBoundsIndexOffset: outOfBoundsIndexOffset)
213208

@@ -323,17 +318,16 @@ extension TestSuite {
323318
wrapValueIntoEquatable: (MinimalEquatableValue) -> CollectionWithEquatableElement.Iterator.Element,
324319
extractValueFromEquatable: ((CollectionWithEquatableElement.Iterator.Element) -> MinimalEquatableValue),
325320

326-
checksAdded: Box<Set<String>> = Box([]),
327321
resiliencyChecks: CollectionMisuseResiliencyChecks = .all,
328322
outOfBoundsIndexOffset: Int = 1
329323
) {
330324
var testNamePrefix = testNamePrefix
331325

332326
// Don't run the same tests twice.
333-
if checksAdded.value.contains(#function) {
327+
if checksAdded.contains(#function) {
334328
return
335329
}
336-
checksAdded.value.insert(#function)
330+
checksAdded.insert(#function)
337331

338332
addRangeReplaceableBidirectionalSliceTests(
339333
testNamePrefix,
@@ -343,7 +337,6 @@ extension TestSuite {
343337
makeCollectionOfEquatable: makeCollectionOfEquatable,
344338
wrapValueIntoEquatable: wrapValueIntoEquatable,
345339
extractValueFromEquatable: extractValueFromEquatable,
346-
checksAdded: checksAdded,
347340
resiliencyChecks: resiliencyChecks,
348341
outOfBoundsIndexOffset: outOfBoundsIndexOffset)
349342

@@ -355,7 +348,6 @@ extension TestSuite {
355348
makeCollectionOfEquatable: makeCollectionOfEquatable,
356349
wrapValueIntoEquatable: wrapValueIntoEquatable,
357350
extractValueFromEquatable: extractValueFromEquatable,
358-
checksAdded: checksAdded,
359351
resiliencyChecks: resiliencyChecks,
360352
outOfBoundsIndexOffset: outOfBoundsIndexOffset)
361353

stdlib/private/StdlibCollectionUnittest/CheckSequenceType.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,15 +1463,14 @@ extension TestSuite {
14631463
wrapValueIntoEquatable: (MinimalEquatableValue) -> SequenceWithEquatableElement.Iterator.Element,
14641464
extractValueFromEquatable: ((SequenceWithEquatableElement.Iterator.Element) -> MinimalEquatableValue),
14651465

1466-
checksAdded: Box<Set<String>> = Box([]),
14671466
resiliencyChecks: CollectionMisuseResiliencyChecks = .all
14681467
) {
14691468
var testNamePrefix = testNamePrefix
14701469

1471-
if checksAdded.value.contains(#function) {
1470+
if checksAdded.contains(#function) {
14721471
return
14731472
}
1474-
checksAdded.value.insert(#function)
1473+
checksAdded.insert(#function)
14751474

14761475
func makeWrappedSequence(_ elements: [OpaqueValue<Int>]) -> S {
14771476
return makeSequence(elements.map(wrapValue))

0 commit comments

Comments
 (0)