Skip to content

Commit d8d6c78

Browse files
author
Itai Ferber
committed
Add #available checks for NSKeyedArchiver methods in tests
1 parent 5154886 commit d8d6c78

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

test/stdlib/ErrorBridged.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ ErrorBridgingTests.test("NSCopying") {
7070
}
7171
}
7272

73+
// Gated on the availability of NSKeyedArchiver.archivedData(withRootObject:).
74+
@available(macOS 10.11, iOS 9.0, tvOS 9.0, watchOS 2.0, *)
7375
func archiveAndUnarchiveObject<T: NSCoding>(
7476
_ object: T
7577
) -> T?
@@ -81,11 +83,13 @@ where T: NSObject {
8183
return unarchiver.decodeObject(of: T.self, forKey: "root")
8284
}
8385
ErrorBridgingTests.test("NSCoding") {
84-
autoreleasepool {
85-
let orig = EnumError.ReallyBadError as NSError
86-
let unarchived = archiveAndUnarchiveObject(orig)!
87-
expectEqual(orig, unarchived)
88-
expectTrue(type(of: unarchived) == NSError.self)
86+
if #available(macOS 10.11, iOS 9.0, tvOS 9.0, watchOS 2.0, *) {
87+
autoreleasepool {
88+
let orig = EnumError.ReallyBadError as NSError
89+
let unarchived = archiveAndUnarchiveObject(orig)!
90+
expectEqual(orig, unarchived)
91+
expectTrue(type(of: unarchived) == NSError.self)
92+
}
8993
}
9094
}
9195

test/stdlib/TestUserInfo.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,16 @@ class TestUserInfo : TestUserInfoSuper {
135135
func test_classForCoder() {
136136
// confirm internal bridged impl types are not exposed to archival machinery
137137
// we have to be circuitous here, as bridging makes it very difficult to confirm this
138-
let note = Notification(name: Notification.Name(rawValue: "TestSwiftNotification"), userInfo: [AnyHashable("key"):"value"])
139-
let archivedNote = NSKeyedArchiver.archivedData(withRootObject: note)
140-
let noteAsPlist = try! PropertyListSerialization.propertyList(from: archivedNote, options: [], format: nil)
141-
let plistAsData = try! PropertyListSerialization.data(fromPropertyList: noteAsPlist, format: .xml, options: 0)
142-
let xml = NSString(data: plistAsData, encoding: String.Encoding.utf8.rawValue)!
143-
expectEqual(xml.range(of: "_NSUserInfoDictionary").location, NSNotFound)
138+
//
139+
// Gated on the availability of NSKeyedArchiver.archivedData(withRootObject:).
140+
if #available(macOS 10.11, iOS 9.0, tvOS 9.0, watchOS 2.0, *) {
141+
let note = Notification(name: Notification.Name(rawValue: "TestSwiftNotification"), userInfo: [AnyHashable("key"):"value"])
142+
let archivedNote = NSKeyedArchiver.archivedData(withRootObject: note)
143+
let noteAsPlist = try! PropertyListSerialization.propertyList(from: archivedNote, options: [], format: nil)
144+
let plistAsData = try! PropertyListSerialization.data(fromPropertyList: noteAsPlist, format: .xml, options: 0)
145+
let xml = NSString(data: plistAsData, encoding: String.Encoding.utf8.rawValue)!
146+
expectEqual(xml.range(of: "_NSUserInfoDictionary").location, NSNotFound)
147+
}
144148
}
145149

146150
func test_AnyHashableContainingNotification() {

0 commit comments

Comments
 (0)