Skip to content

Commit ad54a1f

Browse files
authored
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
2 parents 4400b02 + e16b9a5 commit ad54a1f

File tree

11 files changed

+37
-36
lines changed

11 files changed

+37
-36
lines changed

Sources/XCTest/Private/TestListing.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ extension XCTestSuite: Listable {
7575
}
7676

7777
func dictionaryRepresentation() -> NSDictionary {
78-
let listedTests = tests.flatMap({ ($0 as? Listable)?.dictionaryRepresentation() })
79-
return [
80-
"name": listingName.bridge(),
81-
"tests": listedTests.bridge()
82-
].bridge()
78+
let listedTests = NSArray(array: tests.flatMap({ ($0 as? Listable)?.dictionaryRepresentation() }))
79+
return NSDictionary(objects: [NSString(string: listingName),
80+
listedTests],
81+
forKeys: [NSString(string: "name"),
82+
NSString(string: "tests")])
8383
}
8484

8585
func findBundleTestSuite() -> XCTestSuite? {
@@ -102,6 +102,6 @@ extension XCTestCase: Listable {
102102

103103
func dictionaryRepresentation() -> NSDictionary {
104104
let methodName = String(name.characters.split(separator: ".").last!)
105-
return ["name": methodName].bridge()
105+
return NSDictionary(object: NSString(string: methodName), forKey: NSString(string: "name"))
106106
}
107107
}

Sources/XCTest/Private/WallClockTimeMetric.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ internal final class WallClockTimeMetric: PerformanceMetric {
6262
}
6363

6464
private func currentTime() -> TimeInterval {
65-
return ProcessInfo.processInfo().systemUptime
65+
return ProcessInfo.processInfo.systemUptime
6666
}
6767
}
6868

Sources/XCTest/Private/XCPredicateExpectation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
#endif
1919

2020
internal class XCPredicateExpectation: XCTestExpectation {
21-
internal let predicate: Predicate
21+
internal let predicate: NSPredicate
2222
internal let object: AnyObject
2323
internal var timer: Timer?
2424
internal let handler: XCPredicateExpectationHandler?
2525
private let evaluationInterval = 0.01
2626

27-
internal init(predicate: Predicate, object: AnyObject, description: String, file: StaticString, line: UInt, testCase: XCTestCase, handler: XCPredicateExpectationHandler? = nil) {
27+
internal init(predicate: NSPredicate, object: AnyObject, description: String, file: StaticString, line: UInt, testCase: XCTestCase, handler: XCPredicateExpectationHandler? = nil) {
2828
self.predicate = predicate
2929
self.object = object
3030
self.handler = handler

Sources/XCTest/Public/XCTestCase+Asynchronous.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public extension XCTestCase {
103103
// been fulfilled, it would be more efficient to use a runloop
104104
// source that can be signaled to wake up when an expectation is
105105
// fulfilled.
106-
let runLoop = RunLoop.current()
106+
let runLoop = RunLoop.current
107107
let timeoutDate = Date(timeIntervalSinceNow: timeout)
108108
repeat {
109109
unfulfilledDescriptions = []
@@ -171,14 +171,14 @@ public extension XCTestCase {
171171
var observer: NSObjectProtocol? = nil
172172
func removeObserver() {
173173
if let observer = observer as? AnyObject {
174-
NotificationCenter.defaultCenter().removeObserver(observer)
174+
NotificationCenter.default.removeObserver(observer)
175175
}
176176
}
177177

178178
weak var weakExpectation = expectation
179179
observer = NotificationCenter
180-
.defaultCenter()
181-
.addObserverForName(Notification.Name(rawValue: notificationName),
180+
.default
181+
.addObserver(forName: Notification.Name(rawValue: notificationName),
182182
object: objectToObserve,
183183
queue: nil,
184184
usingBlock: {
@@ -226,7 +226,7 @@ public extension XCTestCase {
226226
/// first successful evaluation will fulfill the expectation. If provided,
227227
/// the handler can override that behavior which leaves the caller
228228
/// responsible for fulfilling the expectation.
229-
func expectation(for predicate: Predicate, evaluatedWith object: AnyObject, file: StaticString = #file, line: UInt = #line, handler: XCPredicateExpectationHandler? = nil) -> XCTestExpectation {
229+
func expectation(for predicate: NSPredicate, evaluatedWith object: AnyObject, file: StaticString = #file, line: UInt = #line, handler: XCPredicateExpectationHandler? = nil) -> XCTestExpectation {
230230
let expectation = XCPredicateExpectation(
231231
predicate: predicate,
232232
object: object,

Sources/XCTest/Public/XCTestMain.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
/// - Parameter testCases: An array of test cases run, each produced by a call to the `testCase` function
5151
/// - seealso: `testCase`
5252
public func XCTMain(_ testCases: [XCTestCaseEntry]) -> Never {
53-
let testBundle = Bundle.main()
53+
let testBundle = Bundle.main
5454

5555
let executionMode = ArgumentParser().executionMode
5656

Tests/Functional/Asynchronous/Expectations/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ExpectationsTestCase: XCTestCase {
4747
let timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: false) { _ in
4848
expectation.fulfill()
4949
}
50-
RunLoop.current().add(timer, forMode: .defaultRunLoopMode)
50+
RunLoop.current.add(timer, forMode: .defaultRunLoopMode)
5151
waitForExpectations(timeout: 1.0)
5252
}
5353

@@ -59,7 +59,7 @@ class ExpectationsTestCase: XCTestCase {
5959
let timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false) { _ in
6060
expectation.fulfill()
6161
}
62-
RunLoop.current().add(timer, forMode: .defaultRunLoopMode)
62+
RunLoop.current.add(timer, forMode: .defaultRunLoopMode)
6363
waitForExpectations(timeout: 0.1)
6464
}
6565

Tests/Functional/Asynchronous/Notifications/Expectations/main.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class NotificationExpectationsTestCase: XCTestCase {
2121
func test_observeNotificationWithName_passes() {
2222
let notificationName = "notificationWithNameTest"
2323
expectation(forNotification: notificationName, object:nil)
24-
NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: notificationName), object: nil)
24+
NotificationCenter.default.post(name: Notification.Name(rawValue: notificationName), object: nil)
2525
waitForExpectations(timeout: 0.0)
2626
}
2727

@@ -31,7 +31,7 @@ class NotificationExpectationsTestCase: XCTestCase {
3131
let notificationName = "notificationWithNameAndObjectTest"
3232
let dummyObject = NSObject()
3333
expectation(forNotification: notificationName, object:dummyObject)
34-
NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: notificationName), object: dummyObject)
34+
NotificationCenter.default.post(name: Notification.Name(rawValue: notificationName), object: dummyObject)
3535
waitForExpectations(timeout: 0.0)
3636
}
3737

@@ -41,7 +41,7 @@ class NotificationExpectationsTestCase: XCTestCase {
4141
let notificationName = "notificationWithNameAndObject_expectNoObjectTest"
4242
expectation(forNotification: notificationName, object:nil)
4343
let dummyObject = NSObject()
44-
NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: notificationName), object: dummyObject)
44+
NotificationCenter.default.post(name: Notification.Name(rawValue: notificationName), object: dummyObject)
4545
waitForExpectations(timeout: 0.0)
4646
}
4747

@@ -50,7 +50,7 @@ class NotificationExpectationsTestCase: XCTestCase {
5050
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithIncorrectName_fails' failed \(\d+\.\d+ seconds\).
5151
func test_observeNotificationWithIncorrectName_fails() {
5252
expectation(forNotification: "expectedName", object: nil)
53-
NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: "actualName"), object: nil)
53+
NotificationCenter.default.post(name: Notification.Name(rawValue: "actualName"), object: nil)
5454
waitForExpectations(timeout: 0.1)
5555
}
5656

@@ -62,7 +62,7 @@ class NotificationExpectationsTestCase: XCTestCase {
6262
let dummyObject: NSString = "dummyObject"
6363
let anotherDummyObject = NSObject()
6464
expectation(forNotification: notificationName, object: dummyObject)
65-
NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: notificationName), object:anotherDummyObject)
65+
NotificationCenter.default.post(name: Notification.Name(rawValue: notificationName), object:anotherDummyObject)
6666
waitForExpectations(timeout: 0.1)
6767
}
6868

Tests/Functional/Asynchronous/Notifications/Handler/main.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class NotificationHandlerTestCase: XCTestCase {
2323
notification in
2424
return false
2525
})
26-
NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: "returnFalse"), object: nil)
26+
NotificationCenter.default.post(name: Notification.Name(rawValue: "returnFalse"), object: nil)
2727
waitForExpectations(timeout: 0.1)
2828
}
2929

@@ -34,7 +34,7 @@ class NotificationHandlerTestCase: XCTestCase {
3434
notification in
3535
return true
3636
})
37-
NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: "returnTrue"), object: nil)
37+
NotificationCenter.default.post(name: Notification.Name(rawValue: "returnTrue"), object: nil)
3838
waitForExpectations(timeout: 0.1)
3939
}
4040

@@ -47,7 +47,7 @@ class NotificationHandlerTestCase: XCTestCase {
4747
return true
4848
})
4949
waitForExpectations(timeout: 0.1, handler: nil)
50-
NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: "note"), object: nil)
50+
NotificationCenter.default.post(name: Notification.Name(rawValue: "note"), object: nil)
5151
}
5252

5353
static var allTests = {

Tests/Functional/Asynchronous/Predicates/Expectations/main.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %{swiftc} %s -o %T/Asynchronous-Predicates
22
// RUN: %T/Asynchronous-Predicates > %t || true
3-
// RUN: %{xctest_checker} %t %s
3+
// Disabled due to: https://bugs.swift.org/browse/SR-2332
4+
// xxx: %{xctest_checker} %t %s
45

56
#if os(Linux) || os(FreeBSD)
67
import XCTest
@@ -18,7 +19,7 @@ class PredicateExpectationsTestCase: XCTestCase {
1819
// CHECK: Test Case 'PredicateExpectationsTestCase.test_immediatelyTruePredicateAndObject_passes' started at \d+:\d+:\d+\.\d+
1920
// CHECK: Test Case 'PredicateExpectationsTestCase.test_immediatelyTruePredicateAndObject_passes' passed \(\d+\.\d+ seconds\).
2021
func test_immediatelyTruePredicateAndObject_passes() {
21-
let predicate = Predicate(value: true)
22+
let predicate = NSPredicate(value: true)
2223
let object = NSObject()
2324
expectation(for: predicate, evaluatedWith: object)
2425
waitForExpectations(timeout: 0.1)
@@ -28,7 +29,7 @@ class PredicateExpectationsTestCase: XCTestCase {
2829
// 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}>
2930
// CHECK: Test Case 'PredicateExpectationsTestCase.test_immediatelyFalsePredicateAndObject_fails' failed \(\d+\.\d+ seconds\).
3031
func test_immediatelyFalsePredicateAndObject_fails() {
31-
let predicate = Predicate(value: false)
32+
let predicate = NSPredicate(value: false)
3233
let object = NSObject()
3334
expectation(for: predicate, evaluatedWith: object)
3435
waitForExpectations(timeout: 0.1)
@@ -38,7 +39,7 @@ class PredicateExpectationsTestCase: XCTestCase {
3839
// CHECK: Test Case 'PredicateExpectationsTestCase.test_delayedTruePredicateAndObject_passes' passed \(\d+\.\d+ seconds\).
3940
func test_delayedTruePredicateAndObject_passes() {
4041
var didEvaluate = false
41-
let predicate = Predicate(block: { evaluatedObject, bindings in
42+
let predicate = NSPredicate(block: { evaluatedObject, bindings in
4243
defer { didEvaluate = true }
4344
return didEvaluate
4445
})
@@ -50,7 +51,7 @@ class PredicateExpectationsTestCase: XCTestCase {
5051
// CHECK: Test Case 'PredicateExpectationsTestCase.test_immediatelyTrueDelayedFalsePredicateAndObject_passes' passed \(\d+\.\d+ seconds\).
5152
func test_immediatelyTrueDelayedFalsePredicateAndObject_passes() {
5253
var didEvaluate = false
53-
let predicate = Predicate(block: { evaluatedObject, bindings in
54+
let predicate = NSPredicate(block: { evaluatedObject, bindings in
5455
defer { didEvaluate = true }
5556
return !didEvaluate
5657
})

Tests/Functional/Asynchronous/Predicates/Handler/main.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ class PredicateHandlerTestCase: XCTestCase {
1818
// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrue_handlerReturnsTrue_passes' started at \d+:\d+:\d+\.\d+
1919
// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrue_handlerReturnsTrue_passes' passed \(\d+\.\d+ seconds\).
2020
func test_predicateIsTrue_handlerReturnsTrue_passes() {
21-
let predicate = Predicate(value: true)
21+
let predicate = NSPredicate(value: true)
2222
let object = NSObject()
2323
self.expectation(for: predicate, evaluatedWith: object, handler: { _ in
2424
return true
2525
})
2626
waitForExpectations(timeout: 0.1)
2727
}
2828
// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrue_handlerReturnsFalse_fails' started at \d+:\d+:\d+\.\d+
29-
// 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}>
29+
// 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}>
3030
// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrue_handlerReturnsFalse_fails' failed \(\d+\.\d+ seconds\).
3131
func test_predicateIsTrue_handlerReturnsFalse_fails() {
32-
let predicate = Predicate(value: true)
32+
let predicate = NSPredicate(value: true)
3333
let object = NSObject()
3434
self.expectation(for: predicate, evaluatedWith: object, handler: { _ in
3535
return false
@@ -38,11 +38,11 @@ class PredicateHandlerTestCase: XCTestCase {
3838
}
3939

4040
// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrueAfterTimeout_handlerIsNotCalled_fails' started at \d+:\d+:\d+\.\d+
41-
// 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+
41+
// 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+
4242
// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrueAfterTimeout_handlerIsNotCalled_fails' failed \(\d+\.\d+ seconds\).
4343
func test_predicateIsTrueAfterTimeout_handlerIsNotCalled_fails() {
4444
let halfSecLaterDate = NSDate(timeIntervalSinceNow: 0.2)
45-
let predicate = Predicate(block: { evaluatedObject, bindings in
45+
let predicate = NSPredicate(block: { evaluatedObject, bindings in
4646
if let evaluatedDate = evaluatedObject as? NSDate {
4747
return evaluatedDate.compare(Date()) == ComparisonResult.orderedAscending
4848
}

Tests/Functional/Performance/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class PerformanceTestCase: XCTestCase {
8989
// 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}%.
9090
measure {
9191
if !hasWaited {
92-
Thread.sleepForTimeInterval(1)
92+
Thread.sleep(forTimeInterval: 1)
9393
hasWaited = true
9494
}
9595
}

0 commit comments

Comments
 (0)