Skip to content

Commit 4d70c0c

Browse files
committed
Add a nil default value for optional handler parameters
This is to match another Swift 3 API importer change.
1 parent 1c3ca29 commit 4d70c0c

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

Sources/XCTest/XCTestCase.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ extension XCTestCase {
225225
/// these environments. To ensure compatibility of tests between
226226
/// swift-corelibs-xctest and Apple XCTest, it is not recommended to pass
227227
/// explicit values for `file` and `line`.
228-
public func waitForExpectations(withTimeout timeout: NSTimeInterval, file: StaticString = #file, line: UInt = #line, handler: XCWaitCompletionHandler?) {
228+
public func waitForExpectations(withTimeout timeout: NSTimeInterval, file: StaticString = #file, line: UInt = #line, handler: XCWaitCompletionHandler? = nil) {
229229
// Mirror Objective-C XCTest behavior; display an unexpected test
230230
// failure when users wait without having first set expectations.
231231
// FIXME: Objective-C XCTest raises an exception for most "API
@@ -323,7 +323,7 @@ extension XCTestCase {
323323
/// notification is observed. It will not be invoked on timeout. Use the
324324
/// handler to further investigate if the notification fulfills the
325325
/// expectation.
326-
public func expectation(forNotification notificationName: String, object objectToObserve: AnyObject?, handler: XCNotificationExpectationHandler?) -> XCTestExpectation {
326+
public func expectation(forNotification notificationName: String, object objectToObserve: AnyObject?, handler: XCNotificationExpectationHandler? = nil) -> XCTestExpectation {
327327
let objectDescription = objectToObserve == nil ? "any object" : "\(objectToObserve!)"
328328
let expectation = self.expectation(withDescription: "Expect notification '\(notificationName)' from " + objectDescription)
329329
// Start observing the notification with specified name and object.

Tests/Functional/Asynchronous/Expectations/main.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ExpectationsTestCase: XCTestCase {
1616
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForAnUnfulfilledExpectation_fails' failed \(\d+\.\d+ seconds\).
1717
func test_waitingForAnUnfulfilledExpectation_fails() {
1818
expectation(withDescription: "foo")
19-
waitForExpectations(withTimeout: 0.2, handler: nil)
19+
waitForExpectations(withTimeout: 0.2)
2020
}
2121

2222
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails' started.
@@ -25,15 +25,15 @@ class ExpectationsTestCase: XCTestCase {
2525
func test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails() {
2626
expectation(withDescription: "bar")
2727
expectation(withDescription: "baz")
28-
waitForExpectations(withTimeout: 0.2, handler: nil)
28+
waitForExpectations(withTimeout: 0.2)
2929
}
3030

3131
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForAnImmediatelyFulfilledExpectation_passes' started.
3232
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForAnImmediatelyFulfilledExpectation_passes' passed \(\d+\.\d+ seconds\).
3333
func test_waitingForAnImmediatelyFulfilledExpectation_passes() {
3434
let expectation = self.expectation(withDescription: "flim")
3535
expectation.fulfill()
36-
waitForExpectations(withTimeout: 0.2, handler: nil)
36+
waitForExpectations(withTimeout: 0.2)
3737
}
3838

3939
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForAnEventuallyFulfilledExpectation_passes' started.
@@ -44,7 +44,7 @@ class ExpectationsTestCase: XCTestCase {
4444
expectation.fulfill()
4545
}
4646
NSRunLoop.currentRunLoop().addTimer(timer, forMode: NSDefaultRunLoopMode)
47-
waitForExpectations(withTimeout: 1.0, handler: nil)
47+
waitForExpectations(withTimeout: 1.0)
4848
}
4949

5050
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForAnExpectationFulfilledAfterTheTimeout_fails' started.
@@ -56,23 +56,23 @@ class ExpectationsTestCase: XCTestCase {
5656
expectation.fulfill()
5757
}
5858
NSRunLoop.currentRunLoop().addTimer(timer, forMode: NSDefaultRunLoopMode)
59-
waitForExpectations(withTimeout: 0.1, handler: nil)
59+
waitForExpectations(withTimeout: 0.1)
6060
}
6161

6262
// CHECK: Test Case 'ExpectationsTestCase.test_whenTimeoutIsImmediate_andAllExpectationsAreFulfilled_passes' started.
6363
// CHECK: Test Case 'ExpectationsTestCase.test_whenTimeoutIsImmediate_andAllExpectationsAreFulfilled_passes' passed \(\d+\.\d+ seconds\).
6464
func test_whenTimeoutIsImmediate_andAllExpectationsAreFulfilled_passes() {
6565
let expectation = self.expectation(withDescription: "smog")
6666
expectation.fulfill()
67-
waitForExpectations(withTimeout: 0.0, handler: nil)
67+
waitForExpectations(withTimeout: 0.0)
6868
}
6969

7070
// CHECK: Test Case 'ExpectationsTestCase.test_whenTimeoutIsImmediate_butNotAllExpectationsAreFulfilled_fails' started.
7171
// CHECK: .*/Tests/Functional/Asynchronous/Expectations/main.swift:75: error: ExpectationsTestCase.test_whenTimeoutIsImmediate_butNotAllExpectationsAreFulfilled_fails : Asynchronous wait failed - Exceeded timeout of -1.0 seconds, with unfulfilled expectations: dog
7272
// CHECK: Test Case 'ExpectationsTestCase.test_whenTimeoutIsImmediate_butNotAllExpectationsAreFulfilled_fails' failed \(\d+\.\d+ seconds\).
7373
func test_whenTimeoutIsImmediate_butNotAllExpectationsAreFulfilled_fails() {
7474
expectation(withDescription: "dog")
75-
waitForExpectations(withTimeout: -1.0, handler: nil)
75+
waitForExpectations(withTimeout: -1.0)
7676
}
7777

7878
static var allTests: [(String, ExpectationsTestCase -> () throws -> Void)] {

Tests/Functional/Asynchronous/Misuse/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class MisuseTestCase: XCTestCase {
2121
// CHECK: .*/Tests/Functional/Asynchronous/Misuse/main.swift:24: unexpected error: MisuseTestCase.test_whenNoExpectationsAreMade_butTheyAreWaitedFor_fails : API violation - call made to wait without any expectations having been set.
2222
// CHECK: Test Case 'MisuseTestCase.test_whenNoExpectationsAreMade_butTheyAreWaitedFor_fails' failed \(\d+\.\d+ seconds\).
2323
func test_whenNoExpectationsAreMade_butTheyAreWaitedFor_fails() {
24-
self.waitForExpectations(withTimeout: 0.1, handler: nil)
24+
self.waitForExpectations(withTimeout: 0.1)
2525
}
2626

2727
// CHECK: Test Case 'MisuseTestCase.test_whenExpectationIsFulfilledMultipleTimes_fails' started.
@@ -42,7 +42,7 @@ class MisuseTestCase: XCTestCase {
4242
// highlights both the lines above and below as failures.
4343
// This should be fixed such that the behavior is identical.
4444
expectation.fulfill()
45-
self.waitForExpectations(withTimeout: 0.1, handler: nil)
45+
self.waitForExpectations(withTimeout: 0.1)
4646
}
4747

4848
static var allTests: [(String, MisuseTestCase -> () throws -> Void)] {

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,38 @@ class NotificationExpectationsTestCase: XCTestCase {
1515
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithName_passes' passed \(\d+\.\d+ seconds\).
1616
func test_observeNotificationWithName_passes() {
1717
let notificationName = "notificationWithNameTest"
18-
expectation(forNotification: notificationName, object:nil, handler:nil)
18+
expectation(forNotification: notificationName, object:nil)
1919
NSNotificationCenter.defaultCenter().postNotificationName(notificationName, object: nil)
20-
waitForExpectations(withTimeout: 0.0, handler: nil)
20+
waitForExpectations(withTimeout: 0.0)
2121
}
2222

2323
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithNameAndObject_passes' started.
2424
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithNameAndObject_passes' passed \(\d+\.\d+ seconds\).
2525
func test_observeNotificationWithNameAndObject_passes() {
2626
let notificationName = "notificationWithNameAndObjectTest"
2727
let dummyObject = NSObject()
28-
expectation(forNotification: notificationName, object:dummyObject, handler:nil)
28+
expectation(forNotification: notificationName, object:dummyObject)
2929
NSNotificationCenter.defaultCenter().postNotificationName(notificationName, object: dummyObject)
30-
waitForExpectations(withTimeout: 0.0, handler: nil)
30+
waitForExpectations(withTimeout: 0.0)
3131
}
3232

3333
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithNameAndObject_butExpectingNoObject_passes' started.
3434
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithNameAndObject_butExpectingNoObject_passes' passed \(\d+\.\d+ seconds\).
3535
func test_observeNotificationWithNameAndObject_butExpectingNoObject_passes() {
3636
let notificationName = "notificationWithNameAndObject_expectNoObjectTest"
37-
expectation(forNotification: notificationName, object:nil, handler:nil)
37+
expectation(forNotification: notificationName, object:nil)
3838
let dummyObject = NSObject()
3939
NSNotificationCenter.defaultCenter().postNotificationName(notificationName, object: dummyObject)
40-
waitForExpectations(withTimeout: 0.0, handler: nil)
40+
waitForExpectations(withTimeout: 0.0)
4141
}
4242

4343
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithIncorrectName_fails' started.
4444
// CHECK: .*/Tests/Functional/Asynchronous/Notifications/Expectations/main.swift:49: error: NotificationExpectationsTestCase.test_observeNotificationWithIncorrectName_fails : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: Expect notification 'expectedName' from any object
4545
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithIncorrectName_fails' failed \(\d+\.\d+ seconds\).
4646
func test_observeNotificationWithIncorrectName_fails() {
47-
expectation(forNotification: "expectedName", object: nil, handler:nil)
47+
expectation(forNotification: "expectedName", object: nil)
4848
NSNotificationCenter.defaultCenter().postNotificationName("actualName", object: nil)
49-
waitForExpectations(withTimeout: 0.1, handler: nil)
49+
waitForExpectations(withTimeout: 0.1)
5050
}
5151

5252
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithIncorrectObject_fails' started.
@@ -56,9 +56,9 @@ class NotificationExpectationsTestCase: XCTestCase {
5656
let notificationName = "notificationWithIncorrectObjectTest"
5757
let dummyObject: NSString = "dummyObject"
5858
let anotherDummyObject = NSObject()
59-
expectation(forNotification: notificationName, object: dummyObject, handler: nil)
59+
expectation(forNotification: notificationName, object: dummyObject)
6060
NSNotificationCenter.defaultCenter().postNotificationName(notificationName, object:anotherDummyObject)
61-
waitForExpectations(withTimeout: 0.1, handler: nil)
61+
waitForExpectations(withTimeout: 0.1)
6262
}
6363

6464
static var allTests: [(String, NotificationExpectationsTestCase -> () throws -> Void)] {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class NotificationHandlerTestCase: XCTestCase {
2020
return false
2121
})
2222
NSNotificationCenter.defaultCenter().postNotificationName("returnFalse", object: nil)
23-
waitForExpectations(withTimeout: 0.1, handler: nil)
23+
waitForExpectations(withTimeout: 0.1)
2424
}
2525

2626
// CHECK: Test Case 'NotificationHandlerTestCase.test_notificationNameIsObserved_handlerReturnsTrue_andPasses' started.
@@ -31,7 +31,7 @@ class NotificationHandlerTestCase: XCTestCase {
3131
return true
3232
})
3333
NSNotificationCenter.defaultCenter().postNotificationName("returnTrue", object: nil)
34-
waitForExpectations(withTimeout: 0.1, handler: nil)
34+
waitForExpectations(withTimeout: 0.1)
3535
}
3636

3737
static var allTests: [(String, NotificationHandlerTestCase -> () throws -> Void)] {

0 commit comments

Comments
 (0)