Skip to content

Commit d6a6315

Browse files
authored
Merge pull request #24496 from lorentey/stdlib-version-checks-alt
[test] Add availability guards for tests checking behavioral changes in 5.1
2 parents 4fac0b3 + 211aae1 commit d6a6315

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))
@@ -4649,45 +4654,49 @@ SetTestSuite.test("IndexValidation.RemoveAt.AfterGrow") {
46494654
}
46504655

46514656
#if _runtime(_ObjC)
4652-
SetTestSuite.test("ForcedNonverbatimBridge.Trap.String")
4657+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
4658+
// https://github.com/apple/swift/pull/23174
4659+
SetTestSuite.test("ForcedNonverbatimBridge.Trap.String")
46534660
.skip(.custom(
4654-
{ _isFastAssertConfiguration() },
4655-
reason: "this trap is not guaranteed to happen in -Ounchecked"))
4661+
{ _isFastAssertConfiguration() },
4662+
reason: "this trap is not guaranteed to happen in -Ounchecked"))
46564663
.crashOutputMatches("Could not cast value of type")
46574664
.code {
4665+
let s1: NSSet = [
4666+
"Gordon" as NSString,
4667+
"William" as NSString,
4668+
"Katherine" as NSString,
4669+
"Lynn" as NSString,
4670+
"Brian" as NSString,
4671+
1756 as NSNumber]
46584672

4659-
let s1: NSSet = [
4660-
"Gordon" as NSString,
4661-
"William" as NSString,
4662-
"Katherine" as NSString,
4663-
"Lynn" as NSString,
4664-
"Brian" as NSString,
4665-
1756 as NSNumber]
4666-
4667-
expectCrashLater()
4668-
_ = s1 as! Set<String>
4673+
expectCrashLater()
4674+
_ = s1 as! Set<String>
4675+
}
46694676
}
46704677
#endif
46714678

46724679
#if _runtime(_ObjC)
4673-
SetTestSuite.test("ForcedNonverbatimBridge.Trap.Int")
4680+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
4681+
// https://github.com/apple/swift/pull/23174
4682+
SetTestSuite.test("ForcedNonverbatimBridge.Trap.Int")
46744683
.skip(.custom(
46754684
{ _isFastAssertConfiguration() },
46764685
reason: "this trap is not guaranteed to happen in -Ounchecked"))
46774686
.crashOutputMatches("Could not cast value of type")
46784687
.code {
4688+
let s1: NSSet = [
4689+
4 as NSNumber,
4690+
8 as NSNumber,
4691+
15 as NSNumber,
4692+
16 as NSNumber,
4693+
23 as NSNumber,
4694+
42 as NSNumber,
4695+
"John" as NSString]
46794696

4680-
let s1: NSSet = [
4681-
4 as NSNumber,
4682-
8 as NSNumber,
4683-
15 as NSNumber,
4684-
16 as NSNumber,
4685-
23 as NSNumber,
4686-
42 as NSNumber,
4687-
"John" as NSString]
4688-
4689-
expectCrashLater()
4690-
_ = s1 as! Set<Int>
4697+
expectCrashLater()
4698+
_ = s1 as! Set<Int>
4699+
}
46914700
}
46924701
#endif
46934702

@@ -4800,61 +4809,70 @@ SetTestSuite.test("ForcedVerbatimDowncast.Trap.Int")
48004809
#endif
48014810

48024811
#if _runtime(_ObjC)
4803-
SetTestSuite.test("ForcedBridgingNonverbatimDowncast.Trap.String")
4812+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
4813+
// https://github.com/apple/swift/pull/23174
4814+
SetTestSuite.test("ForcedBridgingNonverbatimDowncast.Trap.String")
48044815
.skip(.custom(
48054816
{ _isFastAssertConfiguration() },
48064817
reason: "this trap is not guaranteed to happen in -Ounchecked"))
48074818
.crashOutputMatches("Could not cast value of type")
48084819
.code {
4809-
let s1: Set<NSObject> = [
4810-
"Gordon" as NSString,
4811-
"William" as NSString,
4812-
"Katherine" as NSString,
4813-
"Lynn" as NSString,
4814-
"Brian" as NSString,
4815-
1756 as NSNumber]
4816-
expectCrashLater()
4817-
// Nonverbatim downcasts are greedy and they trap immediately.
4818-
let s2 = s1 as! Set<String>
4819-
_ = s2.contains("Gordon")
4820+
let s1: Set<NSObject> = [
4821+
"Gordon" as NSString,
4822+
"William" as NSString,
4823+
"Katherine" as NSString,
4824+
"Lynn" as NSString,
4825+
"Brian" as NSString,
4826+
1756 as NSNumber]
4827+
expectCrashLater()
4828+
// Nonverbatim downcasts are greedy and they trap immediately.
4829+
let s2 = s1 as! Set<String>
4830+
_ = s2.contains("Gordon")
4831+
}
48204832
}
48214833
#endif
48224834

48234835
#if _runtime(_ObjC)
4824-
SetTestSuite.test("ForcedBridgingNonverbatimDowncast.Trap.Int")
4836+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
4837+
// https://github.com/apple/swift/pull/23174
4838+
SetTestSuite.test("ForcedBridgingNonverbatimDowncast.Trap.Int")
48254839
.skip(.custom(
48264840
{ _isFastAssertConfiguration() },
48274841
reason: "this trap is not guaranteed to happen in -Ounchecked"))
48284842
.crashOutputMatches("Could not cast value of type")
48294843
.code {
4830-
let s1: Set<NSObject> = [
4831-
4 as NSNumber,
4832-
8 as NSNumber,
4833-
15 as NSNumber,
4834-
16 as NSNumber,
4835-
23 as NSNumber,
4836-
42 as NSNumber,
4837-
"John" as NSString]
4838-
expectCrashLater()
4839-
// Nonverbatim downcasts are greedy and they trap immediately.
4840-
let s2 = s1 as! Set<Int>
4841-
_ = s2.contains(23)
4844+
let s1: Set<NSObject> = [
4845+
4 as NSNumber,
4846+
8 as NSNumber,
4847+
15 as NSNumber,
4848+
16 as NSNumber,
4849+
23 as NSNumber,
4850+
42 as NSNumber,
4851+
"John" as NSString]
4852+
expectCrashLater()
4853+
// Nonverbatim downcasts are greedy and they trap immediately.
4854+
let s2 = s1 as! Set<Int>
4855+
_ = s2.contains(23)
4856+
}
48424857
}
48434858
#endif
48444859

48454860
#if _runtime(_ObjC)
4846-
SetTestSuite.test("Upcast.StringEqualityMismatch") {
4847-
// Upcasting from NSString to String keys changes their concept of equality,
4848-
// resulting in two equal keys, one of which should be discarded by the
4849-
// downcast. (Along with its associated value.)
4850-
// rdar://problem/35995647
4851-
let s: Set<NSString> = [
4852-
"cafe\u{301}",
4853-
"café"
4854-
]
4855-
expectEqual(s.count, 2)
4856-
let s2 = s as Set<String>
4857-
expectEqual(s2.count, 1)
4861+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
4862+
// https://github.com/apple/swift/pull/23683
4863+
SetTestSuite.test("Upcast.StringEqualityMismatch") {
4864+
// Upcasting from NSString to String keys changes their concept of equality,
4865+
// resulting in two equal keys, one of which should be discarded by the
4866+
// downcast. (Along with its associated value.)
4867+
// rdar://problem/35995647
4868+
let s: Set<NSString> = [
4869+
"cafe\u{301}",
4870+
"café"
4871+
]
4872+
expectEqual(s.count, 2)
4873+
let s2 = s as Set<String>
4874+
expectEqual(s2.count, 1)
4875+
}
48584876
}
48594877
#endif
48604878

0 commit comments

Comments
 (0)