Skip to content

Commit 77e2f94

Browse files
committed
Merge pull request #92 from harlanhaskins/se-0046-consistent-func-labels
[SE-0046] Implemented consistent function labels
2 parents f935137 + 3e931f2 commit 77e2f94

File tree

11 files changed

+78
-78
lines changed

11 files changed

+78
-78
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: 27 additions & 27 deletions
Large diffs are not rendered by default.

Sources/XCTest/XCTestCase.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ public class XCTestCase: XCTest {
5555
/// Wrapper function allowing an array of static test case methods to fit
5656
/// the signature required by `XCTMain`
5757
/// - seealso: `XCTMain`
58-
public func testCase<T: XCTestCase>(allTests: [(String, T -> () throws -> Void)]) -> XCTestCaseEntry {
58+
public func testCase<T: XCTestCase>(_ allTests: [(String, T -> () throws -> Void)]) -> XCTestCaseEntry {
5959
let tests: [(String, XCTestCase throws -> Void)] = allTests.map { ($0.0, test($0.1)) }
6060
return (T.self, tests)
6161
}
6262

63-
private func test<T: XCTestCase>(testFunc: T -> () throws -> Void) -> XCTestCase throws -> Void {
63+
private func test<T: XCTestCase>(_ testFunc: T -> () throws -> Void) -> XCTestCase throws -> Void {
6464
return { testCaseType in
6565
guard let testCase = testCaseType as? T else {
6666
fatalError("Attempt to invoke test on class \(T.self) with incompatible instance type \(testCaseType.dynamicType)")
@@ -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.",

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)