Skip to content

Commit bcc1857

Browse files
committed
[stdlib] Enable Set validation test on non-Darwin platforms
1 parent bd024bd commit bcc1857

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

validation-test/stdlib/Set.swift

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,32 @@
22
// RUN: mkdir -p %t
33
//
44
// RUN: %S/../../utils/gyb %s -o %t/main.swift
5-
// RUN: %target-clang -fobjc-arc %S/Inputs/SlurpFastEnumeration/SlurpFastEnumeration.m -c -o %t/SlurpFastEnumeration.o
6-
// RUN: %S/../../utils/line-directive %t/main.swift -- %target-build-swift %S/Inputs/DictionaryKeyValueTypes.swift %S/Inputs/DictionaryKeyValueTypesObjC.swift %t/main.swift -I %S/Inputs/SlurpFastEnumeration/ -Xlinker %t/SlurpFastEnumeration.o -o %t/Set -Xfrontend -disable-access-control
5+
// RUN: if [ %target-runtime == "objc" ]; then \
6+
// RUN: %target-clang -fobjc-arc %S/Inputs/SlurpFastEnumeration/SlurpFastEnumeration.m -c -o %t/SlurpFastEnumeration.o; \
7+
// RUN: %S/../../utils/line-directive %t/main.swift -- %target-build-swift %S/Inputs/DictionaryKeyValueTypes.swift %S/Inputs/DictionaryKeyValueTypesObjC.swift %t/main.swift -I %S/Inputs/SlurpFastEnumeration/ -Xlinker %t/SlurpFastEnumeration.o -o %t/Set -Xfrontend -disable-access-control; \
8+
// RUN: else \
9+
// RUN: %S/../../utils/line-directive %t/main.swift -- %target-build-swift %S/Inputs/DictionaryKeyValueTypes.swift %t/main.swift -o %t/Set -Xfrontend -disable-access-control -Xfrontend -disable-objc-attr-requires-foundation-module; \
10+
// RUN: fi
711
//
812
// RUN: %S/../../utils/line-directive %t/main.swift -- %target-run %t/Set
913
// REQUIRES: executable_test
1014

11-
// XFAIL: linux
12-
1315
import StdlibUnittest
1416
import StdlibCollectionUnittest
1517

1618
// For rand32
1719
import SwiftPrivate
20+
#if _runtime(_ObjC)
1821
import Foundation
22+
#else
23+
// for random, srandom
24+
import Glibc
25+
#endif
1926

2027
// For experimental Set operators
2128
import SwiftExperimental
2229

30+
2331
// Check that the generic parameter is called 'Element'.
2432
protocol TestProtocol1 {}
2533

@@ -50,12 +58,16 @@ var SetTestSuite = TestSuite("Set")
5058

5159
SetTestSuite.setUp {
5260
resetLeaksOfDictionaryKeysValues()
61+
#if _runtime(_ObjC)
5362
resetLeaksOfObjCDictionaryKeysValues()
63+
#endif
5464
}
5565

5666
SetTestSuite.tearDown {
5767
expectNoLeaksOfDictionaryKeysValues()
68+
#if _runtime(_ObjC)
5869
expectNoLeaksOfObjCDictionaryKeysValues()
70+
#endif
5971
}
6072

6173
func getCOWFastSet(_ members: [Int] = [1010, 2020, 3030]) -> Set<Int> {
@@ -106,6 +118,12 @@ func pickRandom<T>(_ a: [T]) -> T {
106118
return a[uniformRandom(a.count)]
107119
}
108120

121+
func equalsUnordered(_ lhs: Set<Int>, _ rhs: Set<Int>) -> Bool {
122+
return lhs.sorted().elementsEqual(rhs.sorted()) {
123+
$0 == $1
124+
}
125+
}
126+
109127
func isNativeSet<T : Hashable>(_ s: Set<T>) -> Bool {
110128
switch s._variantStorage {
111129
case .native:
@@ -115,6 +133,7 @@ func isNativeSet<T : Hashable>(_ s: Set<T>) -> Bool {
115133
}
116134
}
117135

136+
#if _runtime(_ObjC)
118137
func isNativeNSSet(_ s: NSSet) -> Bool {
119138
let className: NSString = NSStringFromClass(s.dynamicType) as NSString
120139
return className.range(of: "NativeSetStorage").length > 0
@@ -135,17 +154,10 @@ func getBridgedEmptyNSSet() -> NSSet {
135154
return bridged
136155
}
137156

138-
139157
func isCocoaSet<T : Hashable>(_ s: Set<T>) -> Bool {
140158
return !isNativeSet(s)
141159
}
142160

143-
func equalsUnordered(_ lhs: Set<Int>, _ rhs: Set<Int>) -> Bool {
144-
return lhs.sorted().elementsEqual(rhs.sorted()) {
145-
$0 == $1
146-
}
147-
}
148-
149161
/// Get an NSSet of TestObjCKeyTy values
150162
func getAsNSSet(_ members: [Int] = [1010, 2020, 3030]) -> NSSet {
151163
let nsArray = NSMutableArray()
@@ -295,6 +307,7 @@ func getBridgedNSSet_MemberTypesCustomBridged() -> NSSet {
295307

296308
return bridged
297309
}
310+
#endif // _runtime(_ObjC)
298311

299312
SetTestSuite.test("AssociatedTypes") {
300313
typealias Collection = Set<MinimalHashableValue>
@@ -1167,6 +1180,7 @@ SetTestSuite.test("deleteChainCollisionRandomized") {
11671180
}
11681181
}
11691182

1183+
#if _runtime(_ObjC)
11701184
@objc
11711185
class CustomImmutableNSSet : NSSet {
11721186
init(_privateInit: ()) {
@@ -2679,6 +2693,7 @@ SetTestSuite.test("SetBridgeFromObjectiveCConditional") {
26792693
expectTrue(false)
26802694
}
26812695
}
2696+
#endif // _runtime(_ObjC)
26822697

26832698
// Public API
26842699

@@ -2933,6 +2948,7 @@ SetTestSuite.test("Equatable.Native.Native") {
29332948
checkEquatable(false, s1, s2)
29342949
}
29352950

2951+
#if _runtime(_ObjC)
29362952
SetTestSuite.test("Equatable.Native.BridgedVerbatim") {
29372953
let s1 = getNativeBridgedVerbatimSet()
29382954
let bvs1 = getBridgedVerbatimSet()
@@ -2964,6 +2980,7 @@ SetTestSuite.test("Equatable.BridgedNonverbatim.BridgedNonverbatim") {
29642980
checkEquatable(false, bnvs1, bnvsEmpty)
29652981
checkEquatable(false, bnvs2, bnvsEmpty)
29662982
}
2983+
#endif // _runtime(_ObjC)
29672984

29682985
SetTestSuite.test("isDisjointWith.Set.Set") {
29692986
let s1 = Set([1010, 2020, 3030, 4040, 5050, 6060])
@@ -3478,6 +3495,15 @@ SetTestSuite.test("first") {
34783495
expectEmpty(emptySet.first)
34793496
}
34803497

3498+
SetTestSuite.test("isEmpty") {
3499+
let s1 = Set([1010, 2020, 3030])
3500+
expectFalse(s1.isEmpty)
3501+
3502+
let emptySet = Set<Int>()
3503+
expectTrue(emptySet.isEmpty)
3504+
}
3505+
3506+
#if _runtime(_ObjC)
34813507
@objc
34823508
class MockSetWithCustomCount : NSSet {
34833509
init(count: Int) {
@@ -3536,14 +3562,6 @@ func callGenericIsEmpty<C : Collection>(_ collection: C) -> Bool {
35363562
return collection.isEmpty
35373563
}
35383564

3539-
SetTestSuite.test("isEmpty") {
3540-
let s1 = Set([1010, 2020, 3030])
3541-
expectFalse(s1.isEmpty)
3542-
3543-
let emptySet = Set<Int>()
3544-
expectTrue(emptySet.isEmpty)
3545-
}
3546-
35473565
SetTestSuite.test("isEmpty/ImplementationIsCustomized") {
35483566
do {
35493567
var d = getMockSetWithCustomCount(count: 0)
@@ -3571,6 +3589,7 @@ SetTestSuite.test("isEmpty/ImplementationIsCustomized") {
35713589
expectEqual(1, MockSetWithCustomCount.timesCountWasCalled)
35723590
}
35733591
}
3592+
#endif // _runtime(_ObjC)
35743593

35753594
SetTestSuite.test("count") {
35763595
let s1 = Set([1010, 2020, 3030])

0 commit comments

Comments
 (0)