Skip to content

Commit 9d6875c

Browse files
author
Harlan Haskins
committed
[SE-0046] Implemented consistent function labels
1 parent e74dea1 commit 9d6875c

File tree

11 files changed

+60
-60
lines changed

11 files changed

+60
-60
lines changed

Sources/XCTest/TestFiltering.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal struct TestFiltering {
3535
return { _ in true }
3636
}
3737

38-
static func filterTests(entries: [XCTestCaseEntry], filter: TestFilter) -> [XCTestCaseEntry] {
38+
static func filterTests(_ entries: [XCTestCaseEntry], filter: TestFilter) -> [XCTestCaseEntry] {
3939
return entries
4040
.map { testCase, tests in
4141
return (testCase, tests.filter { filter(testCase, $0.0) } )
@@ -68,7 +68,7 @@ private extension SelectedTest {
6868
}
6969
}
7070

71-
func matches(testCase testCase: XCTestCase.Type, testName: String) -> Bool {
71+
func matches(testCase: XCTestCase.Type, testName: String) -> Bool {
7272
return String(reflecting: testCase) == testCaseName && (self.testName == nil || testName == self.testName)
7373
}
7474
}

Sources/XCTest/XCTAssert.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private enum _XCTAssertionResult {
5858
}
5959
}
6060

61-
func failureDescription(assertion: _XCTAssertion) -> String {
61+
func failureDescription(_ assertion: _XCTAssertion) -> String {
6262
let explanation: String
6363
switch self {
6464
case .Success: explanation = "passed"
@@ -75,7 +75,7 @@ private enum _XCTAssertionResult {
7575
}
7676
}
7777

78-
private func _XCTEvaluateAssertion(assertion: _XCTAssertion, @autoclosure message: () -> String = "", file: StaticString = #file, line: UInt = #line, @noescape expression: () throws -> _XCTAssertionResult) {
78+
private func _XCTEvaluateAssertion(_ assertion: _XCTAssertion, @autoclosure message: () -> String = "", file: StaticString = #file, line: UInt = #line, @noescape expression: () throws -> _XCTAssertionResult) {
7979
let result: _XCTAssertionResult
8080
do {
8181
result = try expression()
@@ -148,7 +148,7 @@ private func _XCTEvaluateAssertion(assertion: _XCTAssertion, @autoclosure messag
148148
///
149149
/// Now calling failures in `AssertEmpty` will be reported in the file and on
150150
/// the line that the assert function is *called*, not where it is defined.
151-
public func XCTAssert(@autoclosure expression: () throws -> Boolean, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
151+
public func XCTAssert(@autoclosure _ expression: () throws -> Boolean, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
152152
XCTAssertTrue(expression, message, file: file, line: line)
153153
}
154154

@@ -218,7 +218,7 @@ public func XCTAssertEqualWithAccuracy<T: FloatingPoint>(@autoclosure expression
218218
}
219219
}
220220

221-
public func XCTAssertFalse(@autoclosure expression: () throws -> Boolean, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
221+
public func XCTAssertFalse(@autoclosure _ expression: () throws -> Boolean, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
222222
_XCTEvaluateAssertion(.False, message: message, file: file, line: line) {
223223
let value = try expression()
224224
if !value.boolValue {
@@ -273,7 +273,7 @@ public func XCTAssertLessThanOrEqual<T: Comparable>(@autoclosure expression1: ()
273273
}
274274
}
275275

276-
public func XCTAssertNil(@autoclosure expression: () throws -> Any?, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
276+
public func XCTAssertNil(@autoclosure _ expression: () throws -> Any?, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
277277
_XCTEvaluateAssertion(.Nil, message: message, file: file, line: line) {
278278
let value = try expression()
279279
if value == nil {
@@ -350,7 +350,7 @@ public func XCTAssertNotEqualWithAccuracy<T: FloatingPoint>(@autoclosure express
350350
}
351351
}
352352

353-
public func XCTAssertNotNil(@autoclosure expression: () throws -> Any?, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
353+
public func XCTAssertNotNil(@autoclosure _ expression: () throws -> Any?, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
354354
_XCTEvaluateAssertion(.NotNil, message: message, file: file, line: line) {
355355
let value = try expression()
356356
if value != nil {
@@ -361,7 +361,7 @@ public func XCTAssertNotNil(@autoclosure expression: () throws -> Any?, @autoclo
361361
}
362362
}
363363

364-
public func XCTAssertTrue(@autoclosure expression: () throws -> Boolean, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
364+
public func XCTAssertTrue(@autoclosure _ expression: () throws -> Boolean, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
365365
_XCTEvaluateAssertion(.True, message: message, file: file, line: line) {
366366
let value = try expression()
367367
if value.boolValue {
@@ -372,7 +372,7 @@ public func XCTAssertTrue(@autoclosure expression: () throws -> Boolean, @autocl
372372
}
373373
}
374374

375-
public func XCTFail(message: String = "", file: StaticString = #file, line: UInt = #line) {
375+
public func XCTFail(_ message: String = "", file: StaticString = #file, line: UInt = #line) {
376376
_XCTEvaluateAssertion(.Fail, message: message, file: file, line: line) {
377377
return .ExpectedFailure(nil)
378378
}

Sources/XCTest/XCTestCase.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ extension XCTestCase {
8484
}
8585
}
8686

87-
internal static func invokeTests(tests: [(String, XCTestCase throws -> Void)]) {
87+
internal static func invokeTests(_ tests: [(String, XCTestCase throws -> Void)]) {
8888
let observationCenter = XCTestObservationCenter.shared()
8989

9090
var totalDuration = 0.0
@@ -156,7 +156,7 @@ extension XCTestCase {
156156

157157
/// It is an API violation to create expectations but not wait for them to
158158
/// be completed. Notify the user of a mistake via a test failure.
159-
private func failIfExpectationsNotWaitedFor(expectations: [XCTestExpectation]) {
159+
private func failIfExpectationsNotWaitedFor(_ expectations: [XCTestExpectation]) {
160160
if expectations.count > 0 {
161161
let failure = XCTFailure(
162162
message: "Failed due to unwaited expectations.",
@@ -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 expectationWithDescription(_ 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 waitForExpectationsWithTimeout(_ timeout: NSTimeInterval, file: StaticString = #file, line: UInt = #line, handler: XCWaitCompletionHandler?) {
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 expectationForNotification(notificationName: String, object objectToObserve: AnyObject?, handler: XCNotificationExpectationHandler?) -> XCTestExpectation {
326+
public func expectationForNotification(_ notificationName: String, object objectToObserve: AnyObject?, handler: XCNotificationExpectationHandler?) -> XCTestExpectation {
327327
let objectDescription = objectToObserve == nil ? "any object" : "\(objectToObserve!)"
328328
let expectation = self.expectationWithDescription("Expect notification '\(notificationName)' from " + objectDescription)
329329
// Start observing the notification with specified name and object.

Sources/XCTest/XCTestExpectation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class XCTestExpectation {
4747
/// between these environments. To ensure compatibility of tests between
4848
/// swift-corelibs-xctest and Apple XCTest, it is not recommended to pass
4949
/// explicit values for `file` and `line`.
50-
public func fulfill(file: StaticString = #file, line: UInt = #line) {
50+
public func fulfill(_ file: StaticString = #file, line: UInt = #line) {
5151
// FIXME: Objective-C XCTest emits failures when expectations are
5252
// fulfilled after the test cases that generated those
5353
// expectations have completed. Similarly, this should cause an

Sources/XCTest/XCTestMain.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import SwiftFoundation
2121
#endif
2222

23-
internal func XCTPrint(message: String) {
23+
internal func XCTPrint(_ message: String) {
2424
print(message)
2525
fflush(stdout)
2626
}
@@ -34,7 +34,7 @@ struct XCTFailure {
3434

3535
var failureMessage: String { return "\(failureDescription) - \(message)" }
3636

37-
func emit(method: String) {
37+
func emit(_ method: String) {
3838
XCTPrint("\(file):\(line): \(expected ? "" : "unexpected ")error: \(method) : \(failureMessage)")
3939
}
4040
}
@@ -78,7 +78,7 @@ internal struct XCTRun {
7878
///
7979
/// - Parameter testCases: An array of test cases run, each produced by a call to the `testCase` function
8080
/// - seealso: `testCase`
81-
@noreturn public func XCTMain(testCases: [XCTestCaseEntry]) {
81+
@noreturn public func XCTMain(_ testCases: [XCTestCaseEntry]) {
8282
let observationCenter = XCTestObservationCenter.shared()
8383
let testBundle = NSBundle.mainBundle()
8484
observationCenter.testBundleWillStart(testBundle)

Sources/XCTest/XCTestObservation.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ public protocol XCTestObservation: class {
2525
/// Sent immediately before tests begin as a hook for any pre-testing setup.
2626
/// - Parameter testBundle: The bundle containing the tests that were
2727
/// executed.
28-
func testBundleWillStart(testBundle: NSBundle)
28+
func testBundleWillStart(_ testBundle: NSBundle)
2929

3030
/// Sent when a test suite starts executing.
3131
/// - Parameter testSuite: The test suite that started. Additional
3232
/// information can be retrieved from the associated XCTestRun.
33-
func testSuiteWillStart(testSuite: XCTestSuite)
33+
func testSuiteWillStart(_ testSuite: XCTestSuite)
3434

3535
/// Called just before a test begins executing.
3636
/// - Parameter testCase: The test case that is about to start. Its `name`
3737
/// property can be used to identify it.
38-
func testCaseWillStart(testCase: XCTestCase)
38+
func testCaseWillStart(_ testCase: XCTestCase)
3939

4040
/// Called when a test failure is reported.
4141
/// - Parameter testCase: The test case that failed. Its `name` property
@@ -45,17 +45,17 @@ public protocol XCTestObservation: class {
4545
/// was reported, if available.
4646
/// - Parameter lineNumber: The line number in the source file where the
4747
/// failure was reported.
48-
func testCase(testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt)
48+
func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt)
4949

5050
/// Called just after a test finishes executing.
5151
/// - Parameter testCase: The test case that finished. Its `name` property
5252
/// can be used to identify it.
53-
func testCaseDidFinish(testCase: XCTestCase)
53+
func testCaseDidFinish(_ testCase: XCTestCase)
5454

5555
/// Sent when a test suite finishes executing.
5656
/// - Parameter testSuite: The test suite that finished. Additional
5757
/// information can be retrieved from the associated XCTestRun.
58-
func testSuiteDidFinish(testSuite: XCTestSuite)
58+
func testSuiteDidFinish(_ testSuite: XCTestSuite)
5959

6060
/// Sent immediately after all tests have finished as a hook for any
6161
/// post-testing activity. The test process will generally exit after this
@@ -64,16 +64,16 @@ public protocol XCTestObservation: class {
6464
/// it blocks until all such activity is complete.
6565
/// - Parameter testBundle: The bundle containing the tests that were
6666
/// executed.
67-
func testBundleDidFinish(testBundle: NSBundle)
67+
func testBundleDidFinish(_ testBundle: NSBundle)
6868
}
6969

7070
// All `XCTestObservation` methods are optional, so empty default implementations are provided
7171
public extension XCTestObservation {
72-
func testBundleWillStart(testBundle: NSBundle) {}
73-
func testSuiteWillStart(testSuite: XCTestSuite) {}
74-
func testCaseWillStart(testCase: XCTestCase) {}
75-
func testCase(testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {}
76-
func testCaseDidFinish(testCase: XCTestCase) {}
77-
func testSuiteDidFinish(testSuite: XCTestSuite) {}
78-
func testBundleDidFinish(testBundle: NSBundle) {}
72+
func testBundleWillStart(_ testBundle: NSBundle) {}
73+
func testSuiteWillStart(_ testSuite: XCTestSuite) {}
74+
func testCaseWillStart(_ testCase: XCTestCase) {}
75+
func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {}
76+
func testCaseDidFinish(_ testCase: XCTestCase) {}
77+
func testSuiteDidFinish(_ testSuite: XCTestSuite) {}
78+
func testBundleDidFinish(_ testBundle: NSBundle) {}
7979
}

Sources/XCTest/XCTestObservationCenter.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,45 +33,45 @@ public class XCTestObservationCenter {
3333

3434
/// Register an observer to receive future events during a test run. The order
3535
/// in which individual observers are notified about events is undefined.
36-
public func addTestObserver(testObserver: XCTestObservation) {
36+
public func addTestObserver(_ testObserver: XCTestObservation) {
3737
observers.insert(testObserver.wrapper)
3838
}
3939

4040
/// Remove a previously-registered observer so that it will no longer receive
4141
/// event callbacks.
42-
public func removeTestObserver(testObserver: XCTestObservation) {
42+
public func removeTestObserver(_ testObserver: XCTestObservation) {
4343
observers.remove(testObserver.wrapper)
4444
}
4545

46-
internal func testBundleWillStart(testBundle: NSBundle) {
46+
internal func testBundleWillStart(_ testBundle: NSBundle) {
4747
forEachObserver { $0.testBundleWillStart(testBundle) }
4848
}
4949

50-
internal func testSuiteWillStart(testSuite: XCTestSuite) {
50+
internal func testSuiteWillStart(_ testSuite: XCTestSuite) {
5151
forEachObserver { $0.testSuiteWillStart(testSuite) }
5252
}
5353

54-
internal func testCaseWillStart(testCase: XCTestCase) {
54+
internal func testCaseWillStart(_ testCase: XCTestCase) {
5555
forEachObserver { $0.testCaseWillStart(testCase) }
5656
}
5757

58-
internal func testCase(testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {
58+
internal func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {
5959
forEachObserver { $0.testCase(testCase, didFailWithDescription: description, inFile: filePath, atLine: lineNumber) }
6060
}
6161

62-
internal func testCaseDidFinish(testCase: XCTestCase) {
62+
internal func testCaseDidFinish(_ testCase: XCTestCase) {
6363
forEachObserver { $0.testCaseDidFinish(testCase) }
6464
}
6565

66-
internal func testSuiteDidFinish(testSuite: XCTestSuite) {
66+
internal func testSuiteDidFinish(_ testSuite: XCTestSuite) {
6767
forEachObserver { $0.testSuiteDidFinish(testSuite) }
6868
}
6969

70-
internal func testBundleDidFinish(testBundle: NSBundle) {
70+
internal func testBundleDidFinish(_ testBundle: NSBundle) {
7171
forEachObserver { $0.testBundleDidFinish(testBundle) }
7272
}
7373

74-
private func forEachObserver(@noescape body: XCTestObservation -> Void) {
74+
private func forEachObserver(@noescape _ body: XCTestObservation -> Void) {
7575
for observer in observers {
7676
body(observer.object)
7777
}

Sources/XCTest/XCTestSuite.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class XCTestSuite: XCTest {
5252

5353
/// Adds a test (either an `XCTestSuite` or an `XCTestCase` to this
5454
/// collection.
55-
public func addTest(test: XCTest) {
55+
public func addTest(_ test: XCTest) {
5656
tests.append(test)
5757
}
5858
}

Sources/XCTest/XCTimeUtilities.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private func currentTimeIntervalSinceReferenceTime() -> NSTimeInterval {
3030
}
3131

3232
/// Execute the given block and return the time spent during execution
33-
internal func measureTimeExecutingBlock(@noescape block: () -> Void) -> NSTimeInterval {
33+
internal func measureTimeExecutingBlock(@noescape _ block: () -> Void) -> NSTimeInterval {
3434
let start = currentTimeIntervalSinceReferenceTime()
3535
block()
3636
let end = currentTimeIntervalSinceReferenceTime()
@@ -39,6 +39,6 @@ internal func measureTimeExecutingBlock(@noescape block: () -> Void) -> NSTimeIn
3939
}
4040

4141
/// Returns a string version of the given time interval rounded to no more than 3 decimal places.
42-
internal func printableStringForTimeInterval(timeInterval: NSTimeInterval) -> String {
42+
internal func printableStringForTimeInterval(_ timeInterval: NSTimeInterval) -> String {
4343
return String(round(timeInterval * 1000.0) / 1000.0)
4444
}

Tests/Functional/Observation/All/main.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,31 @@ class Observer: XCTestObservation {
1919
var finishedTestSuites = [XCTestSuite]()
2020
var finishedBundlePaths = [String]()
2121

22-
func testBundleWillStart(testBundle: NSBundle) {
22+
func testBundleWillStart(_ testBundle: NSBundle) {
2323
startedBundlePaths.append(testBundle.bundlePath)
2424
}
2525

26-
func testSuiteWillStart(testSuite: XCTestSuite) {
26+
func testSuiteWillStart(_ testSuite: XCTestSuite) {
2727
startedTestSuites.append(testSuite)
2828
}
2929

30-
func testCaseWillStart(testCase: XCTestCase) {
30+
func testCaseWillStart(_ testCase: XCTestCase) {
3131
startedTestCaseNames.append(testCase.name)
3232
}
3333

34-
func testCase(testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {
34+
func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {
3535
failureDescriptions.append(description)
3636
}
3737

38-
func testCaseDidFinish(testCase: XCTestCase) {
38+
func testCaseDidFinish(_ testCase: XCTestCase) {
3939
finishedTestCaseNames.append(testCase.name)
4040
}
4141

42-
func testSuiteDidFinish(testSuite: XCTestSuite) {
42+
func testSuiteDidFinish(_ testSuite: XCTestSuite) {
4343
print("In \(#function): \(testSuite.name)")
4444
}
4545

46-
func testBundleDidFinish(testBundle: NSBundle) {
46+
func testBundleDidFinish(_ testBundle: NSBundle) {
4747
print("In \(#function)")
4848
}
4949
}

Tests/Functional/Observation/Selected/main.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ class Observer: XCTestObservation {
1414
var startedTestSuites = [XCTestSuite]()
1515
var finishedTestSuites = [XCTestSuite]()
1616

17-
func testBundleWillStart(testBundle: NSBundle) {}
17+
func testBundleWillStart(_ testBundle: NSBundle) {}
1818

19-
func testSuiteWillStart(testSuite: XCTestSuite) {
19+
func testSuiteWillStart(_ testSuite: XCTestSuite) {
2020
startedTestSuites.append(testSuite)
2121
}
2222

23-
func testCaseWillStart(testCase: XCTestCase) {}
24-
func testCase(testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {}
25-
func testCaseDidFinish(testCase: XCTestCase) {}
23+
func testCaseWillStart(_ testCase: XCTestCase) {}
24+
func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {}
25+
func testCaseDidFinish(_ testCase: XCTestCase) {}
2626

27-
func testSuiteDidFinish(testSuite: XCTestSuite) {
27+
func testSuiteDidFinish(_ testSuite: XCTestSuite) {
2828
print("In \(#function): \(testSuite.name)")
2929
}
3030

31-
func testBundleDidFinish(testBundle: NSBundle) {}
31+
func testBundleDidFinish(_ testBundle: NSBundle) {}
3232
}
3333

3434
let observer = Observer()

0 commit comments

Comments
 (0)