Skip to content

[test] Add availability guards for tests checking behavioral changes in 5.1 #24496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions test/stdlib/Inputs/CommonArrayTests.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ ${Suite}.test("${ArrayType}/init(unsafeUninitializedCapacity:...:)/validCount")
}

${Suite}.test("${ArrayType}/init(unsafeUninitializedCapacity:...:)/reassignBuffer") {
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else {
// When back-deployed to 5.0, this coding error does not get detected.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's… odd. Did I add that check in something that's now part of the ABI? LGTM in any case, thx @lorentey!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buffer reassign check wasn't in 5.0's underscored initializer, so code using the new public initializer won't get this check when it's deployed on macOS 10.14.2 / iOS 12.2 etc. I don't think this is a problem; the missing check won't break any working code.

Our ABI back deployment tests detected this change in behavior between the 5.0 and 5.1 stdlibs; the availability guard I added here acknowledges that this was an expected change.

return
}

expectCrashLater()
let otherBuffer = UnsafeMutableBufferPointer<Int>.allocate(capacity: 1)
let array = ${ArrayType}<Int>(unsafeUninitializedCapacity: 10) { buffer, _ in
Expand Down
2 changes: 2 additions & 0 deletions test/stdlib/StringBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ StringBridgeTests.test("Tagged NSString") {

func returnOne<T>(_ t: T) -> Int { return 1 }
StringBridgeTests.test("Character from NSString") {
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else { return }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// NOTE: Using hard-coded literals to directly construct NSStrings
let ns1 = "A" as NSString
let ns2 = "A\u{301}" as NSString
Expand Down
2 changes: 2 additions & 0 deletions test/stdlib/TestAffineTransform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ class TestAffineTransform : TestAffineTransformSuper {
}

func test_hashing() {
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else { return }

// the transforms are made up and the values don't matter
let a = AffineTransform(m11: 1.0, m12: 2.5, m21: 66.2, m22: 40.2, tX: -5.5, tY: 3.7)
let b = AffineTransform(m11: -55.66, m12: 22.7, m21: 1.5, m22: 0.0, tX: -22, tY: -33)
Expand Down
2 changes: 1 addition & 1 deletion test/stdlib/TestDateInterval.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class TestDateInterval : TestDateIntervalSuper {
}

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

let start1a = dateWithString("2019-04-04 17:09:23 -0700")
let start1b = dateWithString("2019-04-04 17:09:23 -0700")
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/TestIndexPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class TestIndexPath: TestIndexPathSuper {
}

func testHashing() {
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else { return }
let samples: [IndexPath] = [
[],
[1],
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/TestMeasurement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class TestMeasurement : TestMeasurementSuper {
}

func testHashing() {
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else { return }
let lengths: [[Measurement<UnitLength>]] = [
[
Measurement(value: 5, unit: UnitLength.kilometers),
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/TestUUID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class TestUUID : TestUUIDSuper {
}

func test_hash() {
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else { return }
let values: [UUID] = [
// This list takes a UUID and tweaks every byte while
// leaving the version/variant intact.
Expand Down
12 changes: 9 additions & 3 deletions validation-test/stdlib/Dictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3004,7 +3004,9 @@ DictionaryTestSuite.test("BridgedFromObjC.Verbatim.RemoveAll") {
}

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


DictionaryTestSuite.test("BridgedFromObjC.Verbatim.Count") {
let d = getBridgedVerbatimDictionary()
let identity1 = d._rawIdentifier()
Expand Down Expand Up @@ -3298,6 +3299,12 @@ DictionaryTestSuite.test("BridgedFromObjC.Verbatim.EqualityTest_Empty") {
}

DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.EqualityTest_Empty") {
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else {
// Identity of empty dictionaries changed in
// https://github.com/apple/swift/pull/22527
return
}

let d1 = getBridgedNonverbatimEquatableDictionary([:])
let identity1 = d1._rawIdentifier()
assert(isNativeDictionary(d1))
Expand All @@ -3320,7 +3327,6 @@ DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.EqualityTest_Empty") {
assert(identity2 != d2._rawIdentifier())
}


DictionaryTestSuite.test("BridgedFromObjC.Verbatim.EqualityTest_Small") {
func helper(_ nd1: Dictionary<Int, Int>, _ nd2: Dictionary<Int, Int>, _ expectedEq: Bool) {
let d1 = getBridgedVerbatimEquatableDictionary(nd1)
Expand Down
144 changes: 81 additions & 63 deletions validation-test/stdlib/Set.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,8 @@ SetTestSuite.test("BridgedFromObjC.Verbatim.RemoveAll") {
}

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

SetTestSuite.test("BridgedFromObjC.Nonverbatim.EqualityTest_Empty") {
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else {
// Identity of empty sets changed in https://github.com/apple/swift/pull/22527
return
}
let s1 = getBridgedNonverbatimSet([])
let identity1 = s1._rawIdentifier()
expectTrue(isNativeSet(s1))
Expand Down Expand Up @@ -4649,45 +4654,49 @@ SetTestSuite.test("IndexValidation.RemoveAt.AfterGrow") {
}

#if _runtime(_ObjC)
SetTestSuite.test("ForcedNonverbatimBridge.Trap.String")
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
// https://github.com/apple/swift/pull/23174
SetTestSuite.test("ForcedNonverbatimBridge.Trap.String")
.skip(.custom(
{ _isFastAssertConfiguration() },
reason: "this trap is not guaranteed to happen in -Ounchecked"))
{ _isFastAssertConfiguration() },
reason: "this trap is not guaranteed to happen in -Ounchecked"))
.crashOutputMatches("Could not cast value of type")
.code {
let s1: NSSet = [
"Gordon" as NSString,
"William" as NSString,
"Katherine" as NSString,
"Lynn" as NSString,
"Brian" as NSString,
1756 as NSNumber]

let s1: NSSet = [
"Gordon" as NSString,
"William" as NSString,
"Katherine" as NSString,
"Lynn" as NSString,
"Brian" as NSString,
1756 as NSNumber]

expectCrashLater()
_ = s1 as! Set<String>
expectCrashLater()
_ = s1 as! Set<String>
}
}
#endif

#if _runtime(_ObjC)
SetTestSuite.test("ForcedNonverbatimBridge.Trap.Int")
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
// https://github.com/apple/swift/pull/23174
SetTestSuite.test("ForcedNonverbatimBridge.Trap.Int")
.skip(.custom(
{ _isFastAssertConfiguration() },
reason: "this trap is not guaranteed to happen in -Ounchecked"))
.crashOutputMatches("Could not cast value of type")
.code {
let s1: NSSet = [
4 as NSNumber,
8 as NSNumber,
15 as NSNumber,
16 as NSNumber,
23 as NSNumber,
42 as NSNumber,
"John" as NSString]

let s1: NSSet = [
4 as NSNumber,
8 as NSNumber,
15 as NSNumber,
16 as NSNumber,
23 as NSNumber,
42 as NSNumber,
"John" as NSString]

expectCrashLater()
_ = s1 as! Set<Int>
expectCrashLater()
_ = s1 as! Set<Int>
}
}
#endif

Expand Down Expand Up @@ -4800,61 +4809,70 @@ SetTestSuite.test("ForcedVerbatimDowncast.Trap.Int")
#endif

#if _runtime(_ObjC)
SetTestSuite.test("ForcedBridgingNonverbatimDowncast.Trap.String")
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
// https://github.com/apple/swift/pull/23174
SetTestSuite.test("ForcedBridgingNonverbatimDowncast.Trap.String")
.skip(.custom(
{ _isFastAssertConfiguration() },
reason: "this trap is not guaranteed to happen in -Ounchecked"))
.crashOutputMatches("Could not cast value of type")
.code {
let s1: Set<NSObject> = [
"Gordon" as NSString,
"William" as NSString,
"Katherine" as NSString,
"Lynn" as NSString,
"Brian" as NSString,
1756 as NSNumber]
expectCrashLater()
// Nonverbatim downcasts are greedy and they trap immediately.
let s2 = s1 as! Set<String>
_ = s2.contains("Gordon")
let s1: Set<NSObject> = [
"Gordon" as NSString,
"William" as NSString,
"Katherine" as NSString,
"Lynn" as NSString,
"Brian" as NSString,
1756 as NSNumber]
expectCrashLater()
// Nonverbatim downcasts are greedy and they trap immediately.
let s2 = s1 as! Set<String>
_ = s2.contains("Gordon")
}
}
#endif

#if _runtime(_ObjC)
SetTestSuite.test("ForcedBridgingNonverbatimDowncast.Trap.Int")
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
// https://github.com/apple/swift/pull/23174
SetTestSuite.test("ForcedBridgingNonverbatimDowncast.Trap.Int")
.skip(.custom(
{ _isFastAssertConfiguration() },
reason: "this trap is not guaranteed to happen in -Ounchecked"))
.crashOutputMatches("Could not cast value of type")
.code {
let s1: Set<NSObject> = [
4 as NSNumber,
8 as NSNumber,
15 as NSNumber,
16 as NSNumber,
23 as NSNumber,
42 as NSNumber,
"John" as NSString]
expectCrashLater()
// Nonverbatim downcasts are greedy and they trap immediately.
let s2 = s1 as! Set<Int>
_ = s2.contains(23)
let s1: Set<NSObject> = [
4 as NSNumber,
8 as NSNumber,
15 as NSNumber,
16 as NSNumber,
23 as NSNumber,
42 as NSNumber,
"John" as NSString]
expectCrashLater()
// Nonverbatim downcasts are greedy and they trap immediately.
let s2 = s1 as! Set<Int>
_ = s2.contains(23)
}
}
#endif

#if _runtime(_ObjC)
SetTestSuite.test("Upcast.StringEqualityMismatch") {
// Upcasting from NSString to String keys changes their concept of equality,
// resulting in two equal keys, one of which should be discarded by the
// downcast. (Along with its associated value.)
// rdar://problem/35995647
let s: Set<NSString> = [
"cafe\u{301}",
"café"
]
expectEqual(s.count, 2)
let s2 = s as Set<String>
expectEqual(s2.count, 1)
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
// https://github.com/apple/swift/pull/23683
SetTestSuite.test("Upcast.StringEqualityMismatch") {
// Upcasting from NSString to String keys changes their concept of equality,
// resulting in two equal keys, one of which should be discarded by the
// downcast. (Along with its associated value.)
// rdar://problem/35995647
let s: Set<NSString> = [
"cafe\u{301}",
"café"
]
expectEqual(s.count, 2)
let s2 = s as Set<String>
expectEqual(s2.count, 1)
}
}
#endif

Expand Down