Skip to content

Commit f935137

Browse files
committed
Merge pull request swiftlang#88 from briancroom/swift-3-api-updates
Additional Swift 3 API naming updates
2 parents 810024a + 1ad6f7e commit f935137

File tree

9 files changed

+160
-160
lines changed

9 files changed

+160
-160
lines changed

Sources/XCTest/XCTAssert.swift

Lines changed: 105 additions & 105 deletions
Large diffs are not rendered by default.

Sources/XCTest/XCTestCase.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ extension XCTestCase {
190190
/// between these environments. To ensure compatibility of tests between
191191
/// swift-corelibs-xctest and Apple XCTest, it is not recommended to pass
192192
/// explicit values for `file` and `line`.
193-
public func expectationWithDescription(description: String, file: StaticString = #file, line: UInt = #line) -> XCTestExpectation {
193+
public func expectation(withDescription description: String, file: StaticString = #file, line: UInt = #line) -> XCTestExpectation {
194194
let expectation = XCTestExpectation(
195195
description: description,
196196
file: file,
@@ -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 waitForExpectationsWithTimeout(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
@@ -263,7 +263,7 @@ extension XCTestCase {
263263
repeat {
264264
unfulfilledDescriptions = []
265265
for expectation in _allExpectations {
266-
if !expectation.fulfilled {
266+
if !expectation.isFulfilled {
267267
unfulfilledDescriptions.append(expectation.description)
268268
}
269269
}
@@ -323,9 +323,9 @@ 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 expectationForNotification(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!)"
328-
let expectation = self.expectationWithDescription("Expect notification '\(notificationName)' from " + objectDescription)
328+
let expectation = self.expectation(withDescription: "Expect notification '\(notificationName)' from " + objectDescription)
329329
// Start observing the notification with specified name and object.
330330
var observer: NSObjectProtocol? = nil
331331
func removeObserver() {

Sources/XCTest/XCTestExpectation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class XCTestExpectation {
1717
internal let file: StaticString
1818
internal let line: UInt
1919

20-
internal var fulfilled = false
20+
internal var isFulfilled = false
2121
internal weak var testCase: XCTestCase?
2222

2323
internal init(description: String, file: StaticString, line: UInt, testCase: XCTestCase) {
@@ -52,7 +52,7 @@ public class XCTestExpectation {
5252
// fulfilled after the test cases that generated those
5353
// expectations have completed. Similarly, this should cause an
5454
// error as well.
55-
if fulfilled {
55+
if isFulfilled {
5656
// Mirror Objective-C XCTest behavior: treat multiple calls to
5757
// fulfill() as an unexpected failure.
5858
let failure = XCTFailure(
@@ -65,7 +65,7 @@ public class XCTestExpectation {
6565
failureHandler(failure)
6666
}
6767
} else {
68-
fulfilled = true
68+
isFulfilled = true
6969
}
7070
}
7171
}

Tests/Functional/Asynchronous/Expectations/main.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,64 +15,64 @@ class ExpectationsTestCase: XCTestCase {
1515
// CHECK: .*/Tests/Functional/Asynchronous/Expectations/main.swift:19: error: ExpectationsTestCase.test_waitingForAnUnfulfilledExpectation_fails : Asynchronous wait failed - Exceeded timeout of 0.2 seconds, with unfulfilled expectations: foo
1616
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForAnUnfulfilledExpectation_fails' failed \(\d+\.\d+ seconds\).
1717
func test_waitingForAnUnfulfilledExpectation_fails() {
18-
expectationWithDescription("foo")
19-
waitForExpectationsWithTimeout(0.2, handler: nil)
18+
expectation(withDescription: "foo")
19+
waitForExpectations(withTimeout: 0.2)
2020
}
2121

2222
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails' started.
2323
// CHECK: .*/Tests/Functional/Asynchronous/Expectations/main.swift:28: error: ExpectationsTestCase.test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails : Asynchronous wait failed - Exceeded timeout of 0.2 seconds, with unfulfilled expectations: bar, baz
2424
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails' failed \(\d+\.\d+ seconds\).
2525
func test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails() {
26-
expectationWithDescription("bar")
27-
expectationWithDescription("baz")
28-
waitForExpectationsWithTimeout(0.2, handler: nil)
26+
expectation(withDescription: "bar")
27+
expectation(withDescription: "baz")
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() {
34-
let expectation = expectationWithDescription("flim")
34+
let expectation = self.expectation(withDescription: "flim")
3535
expectation.fulfill()
36-
waitForExpectationsWithTimeout(0.2, handler: nil)
36+
waitForExpectations(withTimeout: 0.2)
3737
}
3838

3939
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForAnEventuallyFulfilledExpectation_passes' started.
4040
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForAnEventuallyFulfilledExpectation_passes' passed \(\d+\.\d+ seconds\).
4141
func test_waitingForAnEventuallyFulfilledExpectation_passes() {
42-
let expectation = expectationWithDescription("flam")
42+
let expectation = self.expectation(withDescription: "flam")
4343
let timer = NSTimer.scheduledTimer(0.1, repeats: false) { _ in
4444
expectation.fulfill()
4545
}
4646
NSRunLoop.currentRunLoop().addTimer(timer, forMode: NSDefaultRunLoopMode)
47-
waitForExpectationsWithTimeout(1.0, handler: nil)
47+
waitForExpectations(withTimeout: 1.0)
4848
}
4949

5050
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForAnExpectationFulfilledAfterTheTimeout_fails' started.
5151
// CHECK: .*/Tests/Functional/Asynchronous/Expectations/main.swift:59: error: ExpectationsTestCase.test_waitingForAnExpectationFulfilledAfterTheTimeout_fails : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: hog
5252
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForAnExpectationFulfilledAfterTheTimeout_fails' failed \(\d+\.\d+ seconds\).
5353
func test_waitingForAnExpectationFulfilledAfterTheTimeout_fails() {
54-
let expectation = expectationWithDescription("hog")
54+
let expectation = self.expectation(withDescription: "hog")
5555
let timer = NSTimer.scheduledTimer(1.0, repeats: false) { _ in
5656
expectation.fulfill()
5757
}
5858
NSRunLoop.currentRunLoop().addTimer(timer, forMode: NSDefaultRunLoopMode)
59-
waitForExpectationsWithTimeout(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() {
65-
let expectation = expectationWithDescription("smog")
65+
let expectation = self.expectation(withDescription: "smog")
6666
expectation.fulfill()
67-
waitForExpectationsWithTimeout(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() {
74-
expectationWithDescription("dog")
75-
waitForExpectationsWithTimeout(-1.0, handler: nil)
74+
expectation(withDescription: "dog")
75+
waitForExpectations(withTimeout: -1.0)
7676
}
7777

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

Tests/Functional/Asynchronous/Handler/main.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ class HandlerTestCase: XCTestCase {
1515
// CHECK: .*/Tests/Functional/Asynchronous/Handler/main.swift:21: error: HandlerTestCase.test_whenExpectationsAreNotFulfilled_handlerCalled_andFails : Asynchronous wait failed - Exceeded timeout of 0.2 seconds, with unfulfilled expectations: fog
1616
// CHECK: Test Case 'HandlerTestCase.test_whenExpectationsAreNotFulfilled_handlerCalled_andFails' failed \(\d+\.\d+ seconds\).
1717
func test_whenExpectationsAreNotFulfilled_handlerCalled_andFails() {
18-
self.expectationWithDescription("fog")
18+
self.expectation(withDescription: "fog")
1919

2020
var handlerWasCalled = false
21-
self.waitForExpectationsWithTimeout(0.2) { error in
21+
self.waitForExpectations(withTimeout: 0.2) { error in
2222
XCTAssertNotNil(error, "Expectation handlers for unfulfilled expectations should not be nil.")
2323
XCTAssertTrue(error!.domain.hasSuffix("XCTestErrorDomain"), "The last component of the error domain should match Objective-C XCTest.")
2424
XCTAssertEqual(error!.code, 0, "The error code should match Objective-C XCTest.")
@@ -30,11 +30,11 @@ class HandlerTestCase: XCTestCase {
3030
// CHECK: Test Case 'HandlerTestCase.test_whenExpectationsAreFulfilled_handlerCalled_andPasses' started.
3131
// CHECK: Test Case 'HandlerTestCase.test_whenExpectationsAreFulfilled_handlerCalled_andPasses' passed \(\d+\.\d+ seconds\).
3232
func test_whenExpectationsAreFulfilled_handlerCalled_andPasses() {
33-
let expectation = self.expectationWithDescription("bog")
33+
let expectation = self.expectation(withDescription: "bog")
3434
expectation.fulfill()
3535

3636
var handlerWasCalled = false
37-
self.waitForExpectationsWithTimeout(0.2) { error in
37+
self.waitForExpectations(withTimeout: 0.2) { error in
3838
XCTAssertNil(error, "Expectation handlers for fulfilled expectations should be nil.")
3939
handlerWasCalled = true
4040
}

Tests/Functional/Asynchronous/Misuse/main.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ class MisuseTestCase: XCTestCase {
1313
// CHECK: .*/Tests/Functional/Asynchronous/Misuse/main.swift:17: unexpected error: MisuseTestCase.test_whenExpectationsAreMade_butNotWaitedFor_fails : - Failed due to unwaited expectations.
1414
// CHECK: Test Case 'MisuseTestCase.test_whenExpectationsAreMade_butNotWaitedFor_fails' failed \(\d+\.\d+ seconds\).
1515
func test_whenExpectationsAreMade_butNotWaitedFor_fails() {
16-
self.expectationWithDescription("the first expectation")
17-
self.expectationWithDescription("the second expectation (the file and line number for this one are included in the failure message")
16+
self.expectation(withDescription: "the first expectation")
17+
self.expectation(withDescription: "the second expectation (the file and line number for this one are included in the failure message")
1818
}
1919

2020
// CHECK: Test Case 'MisuseTestCase.test_whenNoExpectationsAreMade_butTheyAreWaitedFor_fails' started.
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.waitForExpectationsWithTimeout(0.1, handler: nil)
24+
self.waitForExpectations(withTimeout: 0.1)
2525
}
2626

2727
// CHECK: Test Case 'MisuseTestCase.test_whenExpectationIsFulfilledMultipleTimes_fails' started.
2828
// CHECK: .*/Tests/Functional/Asynchronous/Misuse/main.swift:34: unexpected error: MisuseTestCase.test_whenExpectationIsFulfilledMultipleTimes_fails : API violation - multiple calls made to XCTestExpectation.fulfill\(\) for rob.
2929
// CHECK: .*/Tests/Functional/Asynchronous/Misuse/main.swift:44: unexpected error: MisuseTestCase.test_whenExpectationIsFulfilledMultipleTimes_fails : API violation - multiple calls made to XCTestExpectation.fulfill\(\) for rob.
3030
// CHECK: Test Case 'MisuseTestCase.test_whenExpectationIsFulfilledMultipleTimes_fails' failed \(\d+\.\d+ seconds\).
3131
func test_whenExpectationIsFulfilledMultipleTimes_fails() {
32-
let expectation = self.expectationWithDescription("rob")
32+
let expectation = self.expectation(withDescription: "rob")
3333
expectation.fulfill()
3434
expectation.fulfill()
3535
// FIXME: The behavior here is subtly different from Objective-C XCTest.
@@ -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.waitForExpectationsWithTimeout(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-
expectationForNotification(notificationName, object:nil, handler:nil)
18+
expectation(forNotification: notificationName, object:nil)
1919
NSNotificationCenter.defaultCenter().postNotificationName(notificationName, object: nil)
20-
waitForExpectationsWithTimeout(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-
expectationForNotification(notificationName, object:dummyObject, handler:nil)
28+
expectation(forNotification: notificationName, object:dummyObject)
2929
NSNotificationCenter.defaultCenter().postNotificationName(notificationName, object: dummyObject)
30-
waitForExpectationsWithTimeout(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-
expectationForNotification(notificationName, object:nil, handler:nil)
37+
expectation(forNotification: notificationName, object:nil)
3838
let dummyObject = NSObject()
3939
NSNotificationCenter.defaultCenter().postNotificationName(notificationName, object: dummyObject)
40-
waitForExpectationsWithTimeout(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-
expectationForNotification("expectedName", object: nil, handler:nil)
47+
expectation(forNotification: "expectedName", object: nil)
4848
NSNotificationCenter.defaultCenter().postNotificationName("actualName", object: nil)
49-
waitForExpectationsWithTimeout(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-
expectationForNotification(notificationName, object: dummyObject, handler: nil)
59+
expectation(forNotification: notificationName, object: dummyObject)
6060
NSNotificationCenter.defaultCenter().postNotificationName(notificationName, object:anotherDummyObject)
61-
waitForExpectationsWithTimeout(0.1, handler: nil)
61+
waitForExpectations(withTimeout: 0.1)
6262
}
6363

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

0 commit comments

Comments
 (0)