Skip to content

Commit 6f1e632

Browse files
authored
Merge pull request #24497 from lorentey/stdlib-version-checks-alt-5.1
[5.1][test] Add availability guards for tests checking behavioral changes in 5.1
2 parents 28e5982 + af6bc37 commit 6f1e632

File tree

9 files changed

+103
-67
lines changed

9 files changed

+103
-67
lines changed

test/stdlib/Inputs/CommonArrayTests.gyb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,11 @@ ${Suite}.test("${ArrayType}/init(unsafeUninitializedCapacity:...:)/validCount")
572572
}
573573

574574
${Suite}.test("${ArrayType}/init(unsafeUninitializedCapacity:...:)/reassignBuffer") {
575+
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else {
576+
// When back-deployed to 5.0, this coding error does not get detected.
577+
return
578+
}
579+
575580
expectCrashLater()
576581
let otherBuffer = UnsafeMutableBufferPointer<Int>.allocate(capacity: 1)
577582
let array = ${ArrayType}<Int>(unsafeUninitializedCapacity: 10) { buffer, _ in

test/stdlib/StringBridge.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ StringBridgeTests.test("Tagged NSString") {
7777

7878
func returnOne<T>(_ t: T) -> Int { return 1 }
7979
StringBridgeTests.test("Character from NSString") {
80+
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else { return }
81+
8082
// NOTE: Using hard-coded literals to directly construct NSStrings
8183
let ns1 = "A" as NSString
8284
let ns2 = "A\u{301}" as NSString

test/stdlib/TestAffineTransform.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ class TestAffineTransform : TestAffineTransformSuper {
316316
}
317317

318318
func test_hashing() {
319+
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else { return }
320+
319321
// the transforms are made up and the values don't matter
320322
let a = AffineTransform(m11: 1.0, m12: 2.5, m21: 66.2, m22: 40.2, tX: -5.5, tY: 3.7)
321323
let b = AffineTransform(m11: -55.66, m12: 22.7, m21: 1.5, m22: 0.0, tX: -22, tY: -33)

test/stdlib/TestDateInterval.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class TestDateInterval : TestDateIntervalSuper {
6666
}
6767

6868
func test_hashing() {
69-
guard #available(iOS 10.10, OSX 10.12, tvOS 10.0, watchOS 3.0, *) else { return }
69+
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else { return }
7070

7171
let start1a = dateWithString("2019-04-04 17:09:23 -0700")
7272
let start1b = dateWithString("2019-04-04 17:09:23 -0700")

test/stdlib/TestIndexPath.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ class TestIndexPath: TestIndexPathSuper {
222222
}
223223

224224
func testHashing() {
225+
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else { return }
225226
let samples: [IndexPath] = [
226227
[],
227228
[1],

test/stdlib/TestMeasurement.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class TestMeasurement : TestMeasurementSuper {
155155
}
156156

157157
func testHashing() {
158+
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else { return }
158159
let lengths: [[Measurement<UnitLength>]] = [
159160
[
160161
Measurement(value: 5, unit: UnitLength.kilometers),

test/stdlib/TestUUID.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class TestUUID : TestUUIDSuper {
8585
}
8686

8787
func test_hash() {
88+
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else { return }
8889
let values: [UUID] = [
8990
// This list takes a UUID and tweaks every byte while
9091
// leaving the version/variant intact.

validation-test/stdlib/Dictionary.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3004,7 +3004,9 @@ DictionaryTestSuite.test("BridgedFromObjC.Verbatim.RemoveAll") {
30043004
}
30053005

30063006
DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.RemoveAll") {
3007-
do {
3007+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
3008+
// Identity of empty dictionaries changed in
3009+
// https://github.com/apple/swift/pull/22527
30083010
var d = getBridgedNonverbatimDictionary([:])
30093011
assert(isNativeDictionary(d))
30103012
assert(d.count == 0)
@@ -3088,7 +3090,6 @@ DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.RemoveAll") {
30883090
}
30893091
}
30903092

3091-
30923093
DictionaryTestSuite.test("BridgedFromObjC.Verbatim.Count") {
30933094
let d = getBridgedVerbatimDictionary()
30943095
let identity1 = d._rawIdentifier()
@@ -3298,6 +3299,12 @@ DictionaryTestSuite.test("BridgedFromObjC.Verbatim.EqualityTest_Empty") {
32983299
}
32993300

33003301
DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.EqualityTest_Empty") {
3302+
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else {
3303+
// Identity of empty dictionaries changed in
3304+
// https://github.com/apple/swift/pull/22527
3305+
return
3306+
}
3307+
33013308
let d1 = getBridgedNonverbatimEquatableDictionary([:])
33023309
let identity1 = d1._rawIdentifier()
33033310
assert(isNativeDictionary(d1))
@@ -3320,7 +3327,6 @@ DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.EqualityTest_Empty") {
33203327
assert(identity2 != d2._rawIdentifier())
33213328
}
33223329

3323-
33243330
DictionaryTestSuite.test("BridgedFromObjC.Verbatim.EqualityTest_Small") {
33253331
func helper(_ nd1: Dictionary<Int, Int>, _ nd2: Dictionary<Int, Int>, _ expectedEq: Bool) {
33263332
let d1 = getBridgedVerbatimEquatableDictionary(nd1)

validation-test/stdlib/Set.swift

Lines changed: 81 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,8 @@ SetTestSuite.test("BridgedFromObjC.Verbatim.RemoveAll") {
19831983
}
19841984

19851985
SetTestSuite.test("BridgedFromObjC.Nonverbatim.RemoveAll") {
1986-
do {
1986+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
1987+
// Identity of empty sets changed in https://github.com/apple/swift/pull/22527
19871988
var s = getBridgedNonverbatimSet([])
19881989
expectTrue(isNativeSet(s))
19891990
expectEqual(0, s.count)
@@ -2174,6 +2175,10 @@ SetTestSuite.test("BridgedFromObjC.Verbatim.EqualityTest_Empty") {
21742175
}
21752176

21762177
SetTestSuite.test("BridgedFromObjC.Nonverbatim.EqualityTest_Empty") {
2178+
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else {
2179+
// Identity of empty sets changed in https://github.com/apple/swift/pull/22527
2180+
return
2181+
}
21772182
let s1 = getBridgedNonverbatimSet([])
21782183
let identity1 = s1._rawIdentifier()
21792184
expectTrue(isNativeSet(s1))
@@ -4617,45 +4622,49 @@ SetTestSuite.test("IndexValidation.RemoveAt.AfterGrow") {
46174622
}
46184623

46194624
#if _runtime(_ObjC)
4620-
SetTestSuite.test("ForcedNonverbatimBridge.Trap.String")
4625+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
4626+
// https://github.com/apple/swift/pull/23174
4627+
SetTestSuite.test("ForcedNonverbatimBridge.Trap.String")
46214628
.skip(.custom(
4622-
{ _isFastAssertConfiguration() },
4623-
reason: "this trap is not guaranteed to happen in -Ounchecked"))
4629+
{ _isFastAssertConfiguration() },
4630+
reason: "this trap is not guaranteed to happen in -Ounchecked"))
46244631
.crashOutputMatches("Could not cast value of type")
46254632
.code {
4633+
let s1: NSSet = [
4634+
"Gordon" as NSString,
4635+
"William" as NSString,
4636+
"Katherine" as NSString,
4637+
"Lynn" as NSString,
4638+
"Brian" as NSString,
4639+
1756 as NSNumber]
46264640

4627-
let s1: NSSet = [
4628-
"Gordon" as NSString,
4629-
"William" as NSString,
4630-
"Katherine" as NSString,
4631-
"Lynn" as NSString,
4632-
"Brian" as NSString,
4633-
1756 as NSNumber]
4634-
4635-
expectCrashLater()
4636-
_ = s1 as! Set<String>
4641+
expectCrashLater()
4642+
_ = s1 as! Set<String>
4643+
}
46374644
}
46384645
#endif
46394646

46404647
#if _runtime(_ObjC)
4641-
SetTestSuite.test("ForcedNonverbatimBridge.Trap.Int")
4648+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
4649+
// https://github.com/apple/swift/pull/23174
4650+
SetTestSuite.test("ForcedNonverbatimBridge.Trap.Int")
46424651
.skip(.custom(
46434652
{ _isFastAssertConfiguration() },
46444653
reason: "this trap is not guaranteed to happen in -Ounchecked"))
46454654
.crashOutputMatches("Could not cast value of type")
46464655
.code {
4656+
let s1: NSSet = [
4657+
4 as NSNumber,
4658+
8 as NSNumber,
4659+
15 as NSNumber,
4660+
16 as NSNumber,
4661+
23 as NSNumber,
4662+
42 as NSNumber,
4663+
"John" as NSString]
46474664

4648-
let s1: NSSet = [
4649-
4 as NSNumber,
4650-
8 as NSNumber,
4651-
15 as NSNumber,
4652-
16 as NSNumber,
4653-
23 as NSNumber,
4654-
42 as NSNumber,
4655-
"John" as NSString]
4656-
4657-
expectCrashLater()
4658-
_ = s1 as! Set<Int>
4665+
expectCrashLater()
4666+
_ = s1 as! Set<Int>
4667+
}
46594668
}
46604669
#endif
46614670

@@ -4768,61 +4777,70 @@ SetTestSuite.test("ForcedVerbatimDowncast.Trap.Int")
47684777
#endif
47694778

47704779
#if _runtime(_ObjC)
4771-
SetTestSuite.test("ForcedBridgingNonverbatimDowncast.Trap.String")
4780+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
4781+
// https://github.com/apple/swift/pull/23174
4782+
SetTestSuite.test("ForcedBridgingNonverbatimDowncast.Trap.String")
47724783
.skip(.custom(
47734784
{ _isFastAssertConfiguration() },
47744785
reason: "this trap is not guaranteed to happen in -Ounchecked"))
47754786
.crashOutputMatches("Could not cast value of type")
47764787
.code {
4777-
let s1: Set<NSObject> = [
4778-
"Gordon" as NSString,
4779-
"William" as NSString,
4780-
"Katherine" as NSString,
4781-
"Lynn" as NSString,
4782-
"Brian" as NSString,
4783-
1756 as NSNumber]
4784-
expectCrashLater()
4785-
// Nonverbatim downcasts are greedy and they trap immediately.
4786-
let s2 = s1 as! Set<String>
4787-
_ = s2.contains("Gordon")
4788+
let s1: Set<NSObject> = [
4789+
"Gordon" as NSString,
4790+
"William" as NSString,
4791+
"Katherine" as NSString,
4792+
"Lynn" as NSString,
4793+
"Brian" as NSString,
4794+
1756 as NSNumber]
4795+
expectCrashLater()
4796+
// Nonverbatim downcasts are greedy and they trap immediately.
4797+
let s2 = s1 as! Set<String>
4798+
_ = s2.contains("Gordon")
4799+
}
47884800
}
47894801
#endif
47904802

47914803
#if _runtime(_ObjC)
4792-
SetTestSuite.test("ForcedBridgingNonverbatimDowncast.Trap.Int")
4804+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
4805+
// https://github.com/apple/swift/pull/23174
4806+
SetTestSuite.test("ForcedBridgingNonverbatimDowncast.Trap.Int")
47934807
.skip(.custom(
47944808
{ _isFastAssertConfiguration() },
47954809
reason: "this trap is not guaranteed to happen in -Ounchecked"))
47964810
.crashOutputMatches("Could not cast value of type")
47974811
.code {
4798-
let s1: Set<NSObject> = [
4799-
4 as NSNumber,
4800-
8 as NSNumber,
4801-
15 as NSNumber,
4802-
16 as NSNumber,
4803-
23 as NSNumber,
4804-
42 as NSNumber,
4805-
"John" as NSString]
4806-
expectCrashLater()
4807-
// Nonverbatim downcasts are greedy and they trap immediately.
4808-
let s2 = s1 as! Set<Int>
4809-
_ = s2.contains(23)
4812+
let s1: Set<NSObject> = [
4813+
4 as NSNumber,
4814+
8 as NSNumber,
4815+
15 as NSNumber,
4816+
16 as NSNumber,
4817+
23 as NSNumber,
4818+
42 as NSNumber,
4819+
"John" as NSString]
4820+
expectCrashLater()
4821+
// Nonverbatim downcasts are greedy and they trap immediately.
4822+
let s2 = s1 as! Set<Int>
4823+
_ = s2.contains(23)
4824+
}
48104825
}
48114826
#endif
48124827

48134828
#if _runtime(_ObjC)
4814-
SetTestSuite.test("Upcast.StringEqualityMismatch") {
4815-
// Upcasting from NSString to String keys changes their concept of equality,
4816-
// resulting in two equal keys, one of which should be discarded by the
4817-
// downcast. (Along with its associated value.)
4818-
// rdar://problem/35995647
4819-
let s: Set<NSString> = [
4820-
"cafe\u{301}",
4821-
"café"
4822-
]
4823-
expectEqual(s.count, 2)
4824-
let s2 = s as Set<String>
4825-
expectEqual(s2.count, 1)
4829+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
4830+
// https://github.com/apple/swift/pull/23683
4831+
SetTestSuite.test("Upcast.StringEqualityMismatch") {
4832+
// Upcasting from NSString to String keys changes their concept of equality,
4833+
// resulting in two equal keys, one of which should be discarded by the
4834+
// downcast. (Along with its associated value.)
4835+
// rdar://problem/35995647
4836+
let s: Set<NSString> = [
4837+
"cafe\u{301}",
4838+
"café"
4839+
]
4840+
expectEqual(s.count, 2)
4841+
let s2 = s as Set<String>
4842+
expectEqual(s2.count, 1)
4843+
}
48264844
}
48274845
#endif
48284846

0 commit comments

Comments
 (0)