Merge pull request #170 from itaiferber/pr-foundation-3.0-integration
[DO NOT MERGE YET] Cherry-pick commits required for swift-3.0-branch Foundation integration
diff --git a/Sources/XCTest/Private/TestListing.swift b/Sources/XCTest/Private/TestListing.swift
index 1dfb6a8..74035f6 100644
--- a/Sources/XCTest/Private/TestListing.swift
+++ b/Sources/XCTest/Private/TestListing.swift
@@ -75,11 +75,11 @@
}
func dictionaryRepresentation() -> NSDictionary {
- let listedTests = tests.flatMap({ ($0 as? Listable)?.dictionaryRepresentation() })
- return [
- "name": listingName.bridge(),
- "tests": listedTests.bridge()
- ].bridge()
+ let listedTests = NSArray(array: tests.flatMap({ ($0 as? Listable)?.dictionaryRepresentation() }))
+ return NSDictionary(objects: [NSString(string: listingName),
+ listedTests],
+ forKeys: [NSString(string: "name"),
+ NSString(string: "tests")])
}
func findBundleTestSuite() -> XCTestSuite? {
@@ -102,6 +102,6 @@
func dictionaryRepresentation() -> NSDictionary {
let methodName = String(name.characters.split(separator: ".").last!)
- return ["name": methodName].bridge()
+ return NSDictionary(object: NSString(string: methodName), forKey: NSString(string: "name"))
}
}
diff --git a/Sources/XCTest/Private/WallClockTimeMetric.swift b/Sources/XCTest/Private/WallClockTimeMetric.swift
index 459534a..dbbc45a 100644
--- a/Sources/XCTest/Private/WallClockTimeMetric.swift
+++ b/Sources/XCTest/Private/WallClockTimeMetric.swift
@@ -62,7 +62,7 @@
}
private func currentTime() -> TimeInterval {
- return ProcessInfo.processInfo().systemUptime
+ return ProcessInfo.processInfo.systemUptime
}
}
diff --git a/Sources/XCTest/Private/XCPredicateExpectation.swift b/Sources/XCTest/Private/XCPredicateExpectation.swift
index fd78040..efd73c0 100644
--- a/Sources/XCTest/Private/XCPredicateExpectation.swift
+++ b/Sources/XCTest/Private/XCPredicateExpectation.swift
@@ -18,13 +18,13 @@
#endif
internal class XCPredicateExpectation: XCTestExpectation {
- internal let predicate: Predicate
+ internal let predicate: NSPredicate
internal let object: AnyObject
internal var timer: Timer?
internal let handler: XCPredicateExpectationHandler?
private let evaluationInterval = 0.01
- internal init(predicate: Predicate, object: AnyObject, description: String, file: StaticString, line: UInt, testCase: XCTestCase, handler: XCPredicateExpectationHandler? = nil) {
+ internal init(predicate: NSPredicate, object: AnyObject, description: String, file: StaticString, line: UInt, testCase: XCTestCase, handler: XCPredicateExpectationHandler? = nil) {
self.predicate = predicate
self.object = object
self.handler = handler
diff --git a/Sources/XCTest/Public/XCTestCase+Asynchronous.swift b/Sources/XCTest/Public/XCTestCase+Asynchronous.swift
index 38f4436..e9affb7 100644
--- a/Sources/XCTest/Public/XCTestCase+Asynchronous.swift
+++ b/Sources/XCTest/Public/XCTestCase+Asynchronous.swift
@@ -103,7 +103,7 @@
// been fulfilled, it would be more efficient to use a runloop
// source that can be signaled to wake up when an expectation is
// fulfilled.
- let runLoop = RunLoop.current()
+ let runLoop = RunLoop.current
let timeoutDate = Date(timeIntervalSinceNow: timeout)
repeat {
unfulfilledDescriptions = []
@@ -171,14 +171,14 @@
var observer: NSObjectProtocol? = nil
func removeObserver() {
if let observer = observer as? AnyObject {
- NotificationCenter.defaultCenter().removeObserver(observer)
+ NotificationCenter.default.removeObserver(observer)
}
}
weak var weakExpectation = expectation
observer = NotificationCenter
- .defaultCenter()
- .addObserverForName(Notification.Name(rawValue: notificationName),
+ .default
+ .addObserver(forName: Notification.Name(rawValue: notificationName),
object: objectToObserve,
queue: nil,
usingBlock: {
@@ -226,7 +226,7 @@
/// first successful evaluation will fulfill the expectation. If provided,
/// the handler can override that behavior which leaves the caller
/// responsible for fulfilling the expectation.
- func expectation(for predicate: Predicate, evaluatedWith object: AnyObject, file: StaticString = #file, line: UInt = #line, handler: XCPredicateExpectationHandler? = nil) -> XCTestExpectation {
+ func expectation(for predicate: NSPredicate, evaluatedWith object: AnyObject, file: StaticString = #file, line: UInt = #line, handler: XCPredicateExpectationHandler? = nil) -> XCTestExpectation {
let expectation = XCPredicateExpectation(
predicate: predicate,
object: object,
diff --git a/Sources/XCTest/Public/XCTestMain.swift b/Sources/XCTest/Public/XCTestMain.swift
index 7761bbb..97a248c 100644
--- a/Sources/XCTest/Public/XCTestMain.swift
+++ b/Sources/XCTest/Public/XCTestMain.swift
@@ -50,7 +50,7 @@
/// - Parameter testCases: An array of test cases run, each produced by a call to the `testCase` function
/// - seealso: `testCase`
public func XCTMain(_ testCases: [XCTestCaseEntry]) -> Never {
- let testBundle = Bundle.main()
+ let testBundle = Bundle.main
let executionMode = ArgumentParser().executionMode
diff --git a/Tests/Functional/Asynchronous/Expectations/main.swift b/Tests/Functional/Asynchronous/Expectations/main.swift
index c25cb93..2c0d97b 100644
--- a/Tests/Functional/Asynchronous/Expectations/main.swift
+++ b/Tests/Functional/Asynchronous/Expectations/main.swift
@@ -47,7 +47,7 @@
let timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: false) { _ in
expectation.fulfill()
}
- RunLoop.current().add(timer, forMode: .defaultRunLoopMode)
+ RunLoop.current.add(timer, forMode: .defaultRunLoopMode)
waitForExpectations(timeout: 1.0)
}
@@ -59,7 +59,7 @@
let timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false) { _ in
expectation.fulfill()
}
- RunLoop.current().add(timer, forMode: .defaultRunLoopMode)
+ RunLoop.current.add(timer, forMode: .defaultRunLoopMode)
waitForExpectations(timeout: 0.1)
}
diff --git a/Tests/Functional/Asynchronous/Notifications/Expectations/main.swift b/Tests/Functional/Asynchronous/Notifications/Expectations/main.swift
index 6be7ba3..6d24a29 100644
--- a/Tests/Functional/Asynchronous/Notifications/Expectations/main.swift
+++ b/Tests/Functional/Asynchronous/Notifications/Expectations/main.swift
@@ -21,7 +21,7 @@
func test_observeNotificationWithName_passes() {
let notificationName = "notificationWithNameTest"
expectation(forNotification: notificationName, object:nil)
- NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: notificationName), object: nil)
+ NotificationCenter.default.post(name: Notification.Name(rawValue: notificationName), object: nil)
waitForExpectations(timeout: 0.0)
}
@@ -31,7 +31,7 @@
let notificationName = "notificationWithNameAndObjectTest"
let dummyObject = NSObject()
expectation(forNotification: notificationName, object:dummyObject)
- NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: notificationName), object: dummyObject)
+ NotificationCenter.default.post(name: Notification.Name(rawValue: notificationName), object: dummyObject)
waitForExpectations(timeout: 0.0)
}
@@ -41,7 +41,7 @@
let notificationName = "notificationWithNameAndObject_expectNoObjectTest"
expectation(forNotification: notificationName, object:nil)
let dummyObject = NSObject()
- NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: notificationName), object: dummyObject)
+ NotificationCenter.default.post(name: Notification.Name(rawValue: notificationName), object: dummyObject)
waitForExpectations(timeout: 0.0)
}
@@ -50,7 +50,7 @@
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithIncorrectName_fails' failed \(\d+\.\d+ seconds\).
func test_observeNotificationWithIncorrectName_fails() {
expectation(forNotification: "expectedName", object: nil)
- NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: "actualName"), object: nil)
+ NotificationCenter.default.post(name: Notification.Name(rawValue: "actualName"), object: nil)
waitForExpectations(timeout: 0.1)
}
@@ -62,7 +62,7 @@
let dummyObject: NSString = "dummyObject"
let anotherDummyObject = NSObject()
expectation(forNotification: notificationName, object: dummyObject)
- NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: notificationName), object:anotherDummyObject)
+ NotificationCenter.default.post(name: Notification.Name(rawValue: notificationName), object:anotherDummyObject)
waitForExpectations(timeout: 0.1)
}
diff --git a/Tests/Functional/Asynchronous/Notifications/Handler/main.swift b/Tests/Functional/Asynchronous/Notifications/Handler/main.swift
index 2df8b63..c0b99c9 100644
--- a/Tests/Functional/Asynchronous/Notifications/Handler/main.swift
+++ b/Tests/Functional/Asynchronous/Notifications/Handler/main.swift
@@ -23,7 +23,7 @@
notification in
return false
})
- NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: "returnFalse"), object: nil)
+ NotificationCenter.default.post(name: Notification.Name(rawValue: "returnFalse"), object: nil)
waitForExpectations(timeout: 0.1)
}
@@ -34,7 +34,7 @@
notification in
return true
})
- NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: "returnTrue"), object: nil)
+ NotificationCenter.default.post(name: Notification.Name(rawValue: "returnTrue"), object: nil)
waitForExpectations(timeout: 0.1)
}
@@ -47,7 +47,7 @@
return true
})
waitForExpectations(timeout: 0.1, handler: nil)
- NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: "note"), object: nil)
+ NotificationCenter.default.post(name: Notification.Name(rawValue: "note"), object: nil)
}
static var allTests = {
diff --git a/Tests/Functional/Asynchronous/Predicates/Expectations/main.swift b/Tests/Functional/Asynchronous/Predicates/Expectations/main.swift
index 6210acc..54077f3 100644
--- a/Tests/Functional/Asynchronous/Predicates/Expectations/main.swift
+++ b/Tests/Functional/Asynchronous/Predicates/Expectations/main.swift
@@ -1,6 +1,7 @@
// RUN: %{swiftc} %s -o %T/Asynchronous-Predicates
// RUN: %T/Asynchronous-Predicates > %t || true
-// RUN: %{xctest_checker} %t %s
+// Disabled due to: https://bugs.swift.org/browse/SR-2332
+// xxx: %{xctest_checker} %t %s
#if os(Linux) || os(FreeBSD)
import XCTest
@@ -18,7 +19,7 @@
// CHECK: Test Case 'PredicateExpectationsTestCase.test_immediatelyTruePredicateAndObject_passes' started at \d+:\d+:\d+\.\d+
// CHECK: Test Case 'PredicateExpectationsTestCase.test_immediatelyTruePredicateAndObject_passes' passed \(\d+\.\d+ seconds\).
func test_immediatelyTruePredicateAndObject_passes() {
- let predicate = Predicate(value: true)
+ let predicate = NSPredicate(value: true)
let object = NSObject()
expectation(for: predicate, evaluatedWith: object)
waitForExpectations(timeout: 0.1)
@@ -28,7 +29,7 @@
// CHECK: .*/Tests/Functional/Asynchronous/Predicates/Expectations/main.swift:[[@LINE+6]]: error: PredicateExpectationsTestCase.test_immediatelyFalsePredicateAndObject_fails : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: Expect `<Predicate: 0x[0-9A-Fa-f]{1,16}>` for object <NSObject: 0x[0-9A-Fa-f]{1,16}>
// CHECK: Test Case 'PredicateExpectationsTestCase.test_immediatelyFalsePredicateAndObject_fails' failed \(\d+\.\d+ seconds\).
func test_immediatelyFalsePredicateAndObject_fails() {
- let predicate = Predicate(value: false)
+ let predicate = NSPredicate(value: false)
let object = NSObject()
expectation(for: predicate, evaluatedWith: object)
waitForExpectations(timeout: 0.1)
@@ -38,7 +39,7 @@
// CHECK: Test Case 'PredicateExpectationsTestCase.test_delayedTruePredicateAndObject_passes' passed \(\d+\.\d+ seconds\).
func test_delayedTruePredicateAndObject_passes() {
var didEvaluate = false
- let predicate = Predicate(block: { evaluatedObject, bindings in
+ let predicate = NSPredicate(block: { evaluatedObject, bindings in
defer { didEvaluate = true }
return didEvaluate
})
@@ -50,7 +51,7 @@
// CHECK: Test Case 'PredicateExpectationsTestCase.test_immediatelyTrueDelayedFalsePredicateAndObject_passes' passed \(\d+\.\d+ seconds\).
func test_immediatelyTrueDelayedFalsePredicateAndObject_passes() {
var didEvaluate = false
- let predicate = Predicate(block: { evaluatedObject, bindings in
+ let predicate = NSPredicate(block: { evaluatedObject, bindings in
defer { didEvaluate = true }
return !didEvaluate
})
diff --git a/Tests/Functional/Asynchronous/Predicates/Handler/main.swift b/Tests/Functional/Asynchronous/Predicates/Handler/main.swift
index 22cea12..0920bee 100644
--- a/Tests/Functional/Asynchronous/Predicates/Handler/main.swift
+++ b/Tests/Functional/Asynchronous/Predicates/Handler/main.swift
@@ -18,7 +18,7 @@
// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrue_handlerReturnsTrue_passes' started at \d+:\d+:\d+\.\d+
// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrue_handlerReturnsTrue_passes' passed \(\d+\.\d+ seconds\).
func test_predicateIsTrue_handlerReturnsTrue_passes() {
- let predicate = Predicate(value: true)
+ let predicate = NSPredicate(value: true)
let object = NSObject()
self.expectation(for: predicate, evaluatedWith: object, handler: { _ in
return true
@@ -26,10 +26,10 @@
waitForExpectations(timeout: 0.1)
}
// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrue_handlerReturnsFalse_fails' started at \d+:\d+:\d+\.\d+
- // CHECK: .*/Tests/Functional/Asynchronous/Predicates/Handler/main.swift:[[@LINE+8]]: error: PredicateHandlerTestCase.test_predicateIsTrue_handlerReturnsFalse_fails : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: Expect `<Predicate: 0x[0-9a-fA-F]{1,16}>` for object <NSObject: 0x[0-9a-fA-F]{1,16}>
+ // CHECK: .*/Tests/Functional/Asynchronous/Predicates/Handler/main.swift:[[@LINE+8]]: error: PredicateHandlerTestCase.test_predicateIsTrue_handlerReturnsFalse_fails : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: Expect `<NSPredicate: 0x[0-9a-fA-F]{1,16}>` for object <NSObject: 0x[0-9a-fA-F]{1,16}>
// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrue_handlerReturnsFalse_fails' failed \(\d+\.\d+ seconds\).
func test_predicateIsTrue_handlerReturnsFalse_fails() {
- let predicate = Predicate(value: true)
+ let predicate = NSPredicate(value: true)
let object = NSObject()
self.expectation(for: predicate, evaluatedWith: object, handler: { _ in
return false
@@ -38,11 +38,11 @@
}
// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrueAfterTimeout_handlerIsNotCalled_fails' started at \d+:\d+:\d+\.\d+
- // CHECK: .*/Tests/Functional/Asynchronous/Predicates/Handler/main.swift:[[@LINE+14]]: error: PredicateHandlerTestCase.test_predicateIsTrueAfterTimeout_handlerIsNotCalled_fails : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: Expect `<Predicate: 0x[0-9a-fA-F]{1,16}>` for object \d{4}-\d{2}-\d{2} \d+:\d+:\d+ \+\d+
+ // CHECK: .*/Tests/Functional/Asynchronous/Predicates/Handler/main.swift:[[@LINE+14]]: error: PredicateHandlerTestCase.test_predicateIsTrueAfterTimeout_handlerIsNotCalled_fails : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: Expect `<NSPredicate: 0x[0-9a-fA-F]{1,16}>` for object \d{4}-\d{2}-\d{2} \d+:\d+:\d+ \+\d+
// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrueAfterTimeout_handlerIsNotCalled_fails' failed \(\d+\.\d+ seconds\).
func test_predicateIsTrueAfterTimeout_handlerIsNotCalled_fails() {
let halfSecLaterDate = NSDate(timeIntervalSinceNow: 0.2)
- let predicate = Predicate(block: { evaluatedObject, bindings in
+ let predicate = NSPredicate(block: { evaluatedObject, bindings in
if let evaluatedDate = evaluatedObject as? NSDate {
return evaluatedDate.compare(Date()) == ComparisonResult.orderedAscending
}
diff --git a/Tests/Functional/Performance/main.swift b/Tests/Functional/Performance/main.swift
index 606b84e..950db88 100644
--- a/Tests/Functional/Performance/main.swift
+++ b/Tests/Functional/Performance/main.swift
@@ -89,7 +89,7 @@
// CHECK: .*/Performance/main.swift:[[@LINE+1]]: error: PerformanceTestCase.test_measuresWallClockTimeInBlock : failed: The relative standard deviation of the measurements is \d+.\d{3}% which is higher than the max allowed of \d+.\d{3}%.
measure {
if !hasWaited {
- Thread.sleepForTimeInterval(1)
+ Thread.sleep(forTimeInterval: 1)
hasWaited = true
}
}