Skip to content

[SE-0046] Implemented consistent function labels #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/XCTest/TestFiltering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal struct TestFiltering {
return { _ in true }
}

static func filterTests(entries: [XCTestCaseEntry], filter: TestFilter) -> [XCTestCaseEntry] {
static func filterTests(_ entries: [XCTestCaseEntry], filter: TestFilter) -> [XCTestCaseEntry] {
return entries
.map { testCase, tests in
return (testCase, tests.filter { filter(testCase, $0.0) } )
Expand Down Expand Up @@ -68,7 +68,7 @@ private extension SelectedTest {
}
}

func matches(testCase testCase: XCTestCase.Type, testName: String) -> Bool {
func matches(testCase: XCTestCase.Type, testName: String) -> Bool {
return String(reflecting: testCase) == testCaseName && (self.testName == nil || testName == self.testName)
}
}
54 changes: 27 additions & 27 deletions Sources/XCTest/XCTAssert.swift

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Sources/XCTest/XCTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public class XCTestCase: XCTest {
/// Wrapper function allowing an array of static test case methods to fit
/// the signature required by `XCTMain`
/// - seealso: `XCTMain`
public func testCase<T: XCTestCase>(allTests: [(String, T -> () throws -> Void)]) -> XCTestCaseEntry {
public func testCase<T: XCTestCase>(_ allTests: [(String, T -> () throws -> Void)]) -> XCTestCaseEntry {
let tests: [(String, XCTestCase throws -> Void)] = allTests.map { ($0.0, test($0.1)) }
return (T.self, tests)
}

private func test<T: XCTestCase>(testFunc: T -> () throws -> Void) -> XCTestCase throws -> Void {
private func test<T: XCTestCase>(_ testFunc: T -> () throws -> Void) -> XCTestCase throws -> Void {
return { testCaseType in
guard let testCase = testCaseType as? T else {
fatalError("Attempt to invoke test on class \(T.self) with incompatible instance type \(testCaseType.dynamicType)")
Expand All @@ -84,7 +84,7 @@ extension XCTestCase {
}
}

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

var totalDuration = 0.0
Expand Down Expand Up @@ -156,7 +156,7 @@ extension XCTestCase {

/// It is an API violation to create expectations but not wait for them to
/// be completed. Notify the user of a mistake via a test failure.
private func failIfExpectationsNotWaitedFor(expectations: [XCTestExpectation]) {
private func failIfExpectationsNotWaitedFor(_ expectations: [XCTestExpectation]) {
if expectations.count > 0 {
let failure = XCTFailure(
message: "Failed due to unwaited expectations.",
Expand Down
2 changes: 1 addition & 1 deletion Sources/XCTest/XCTestExpectation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class XCTestExpectation {
/// between these environments. To ensure compatibility of tests between
/// swift-corelibs-xctest and Apple XCTest, it is not recommended to pass
/// explicit values for `file` and `line`.
public func fulfill(file: StaticString = #file, line: UInt = #line) {
public func fulfill(_ file: StaticString = #file, line: UInt = #line) {
// FIXME: Objective-C XCTest emits failures when expectations are
// fulfilled after the test cases that generated those
// expectations have completed. Similarly, this should cause an
Expand Down
6 changes: 3 additions & 3 deletions Sources/XCTest/XCTestMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import SwiftFoundation
#endif

internal func XCTPrint(message: String) {
internal func XCTPrint(_ message: String) {
print(message)
fflush(stdout)
}
Expand All @@ -34,7 +34,7 @@ struct XCTFailure {

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

func emit(method: String) {
func emit(_ method: String) {
XCTPrint("\(file):\(line): \(expected ? "" : "unexpected ")error: \(method) : \(failureMessage)")
}
}
Expand Down Expand Up @@ -78,7 +78,7 @@ internal struct XCTRun {
///
/// - Parameter testCases: An array of test cases run, each produced by a call to the `testCase` function
/// - seealso: `testCase`
@noreturn public func XCTMain(testCases: [XCTestCaseEntry]) {
@noreturn public func XCTMain(_ testCases: [XCTestCaseEntry]) {
let observationCenter = XCTestObservationCenter.shared()
let testBundle = NSBundle.mainBundle()
observationCenter.testBundleWillStart(testBundle)
Expand Down
28 changes: 14 additions & 14 deletions Sources/XCTest/XCTestObservation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ public protocol XCTestObservation: class {
/// Sent immediately before tests begin as a hook for any pre-testing setup.
/// - Parameter testBundle: The bundle containing the tests that were
/// executed.
func testBundleWillStart(testBundle: NSBundle)
func testBundleWillStart(_ testBundle: NSBundle)

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

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

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

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

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

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

// All `XCTestObservation` methods are optional, so empty default implementations are provided
public extension XCTestObservation {
func testBundleWillStart(testBundle: NSBundle) {}
func testSuiteWillStart(testSuite: XCTestSuite) {}
func testCaseWillStart(testCase: XCTestCase) {}
func testCase(testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {}
func testCaseDidFinish(testCase: XCTestCase) {}
func testSuiteDidFinish(testSuite: XCTestSuite) {}
func testBundleDidFinish(testBundle: NSBundle) {}
func testBundleWillStart(_ testBundle: NSBundle) {}
func testSuiteWillStart(_ testSuite: XCTestSuite) {}
func testCaseWillStart(_ testCase: XCTestCase) {}
func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {}
func testCaseDidFinish(_ testCase: XCTestCase) {}
func testSuiteDidFinish(_ testSuite: XCTestSuite) {}
func testBundleDidFinish(_ testBundle: NSBundle) {}
}
20 changes: 10 additions & 10 deletions Sources/XCTest/XCTestObservationCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,45 @@ public class XCTestObservationCenter {

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

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

internal func testBundleWillStart(testBundle: NSBundle) {
internal func testBundleWillStart(_ testBundle: NSBundle) {
forEachObserver { $0.testBundleWillStart(testBundle) }
}

internal func testSuiteWillStart(testSuite: XCTestSuite) {
internal func testSuiteWillStart(_ testSuite: XCTestSuite) {
forEachObserver { $0.testSuiteWillStart(testSuite) }
}

internal func testCaseWillStart(testCase: XCTestCase) {
internal func testCaseWillStart(_ testCase: XCTestCase) {
forEachObserver { $0.testCaseWillStart(testCase) }
}

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

internal func testCaseDidFinish(testCase: XCTestCase) {
internal func testCaseDidFinish(_ testCase: XCTestCase) {
forEachObserver { $0.testCaseDidFinish(testCase) }
}

internal func testSuiteDidFinish(testSuite: XCTestSuite) {
internal func testSuiteDidFinish(_ testSuite: XCTestSuite) {
forEachObserver { $0.testSuiteDidFinish(testSuite) }
}

internal func testBundleDidFinish(testBundle: NSBundle) {
internal func testBundleDidFinish(_ testBundle: NSBundle) {
forEachObserver { $0.testBundleDidFinish(testBundle) }
}

private func forEachObserver(@noescape body: XCTestObservation -> Void) {
private func forEachObserver(@noescape _ body: XCTestObservation -> Void) {
for observer in observers {
body(observer.object)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/XCTest/XCTestSuite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class XCTestSuite: XCTest {

/// Adds a test (either an `XCTestSuite` or an `XCTestCase` to this
/// collection.
public func addTest(test: XCTest) {
public func addTest(_ test: XCTest) {
tests.append(test)
}
}
4 changes: 2 additions & 2 deletions Sources/XCTest/XCTimeUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private func currentTimeIntervalSinceReferenceTime() -> NSTimeInterval {
}

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

/// Returns a string version of the given time interval rounded to no more than 3 decimal places.
internal func printableStringForTimeInterval(timeInterval: NSTimeInterval) -> String {
internal func printableStringForTimeInterval(_ timeInterval: NSTimeInterval) -> String {
return String(round(timeInterval * 1000.0) / 1000.0)
}
14 changes: 7 additions & 7 deletions Tests/Functional/Observation/All/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@ class Observer: XCTestObservation {
var finishedTestSuites = [XCTestSuite]()
var finishedBundlePaths = [String]()

func testBundleWillStart(testBundle: NSBundle) {
func testBundleWillStart(_ testBundle: NSBundle) {
startedBundlePaths.append(testBundle.bundlePath)
}

func testSuiteWillStart(testSuite: XCTestSuite) {
func testSuiteWillStart(_ testSuite: XCTestSuite) {
startedTestSuites.append(testSuite)
}

func testCaseWillStart(testCase: XCTestCase) {
func testCaseWillStart(_ testCase: XCTestCase) {
startedTestCaseNames.append(testCase.name)
}

func testCase(testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {
func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {
failureDescriptions.append(description)
}

func testCaseDidFinish(testCase: XCTestCase) {
func testCaseDidFinish(_ testCase: XCTestCase) {
finishedTestCaseNames.append(testCase.name)
}

func testSuiteDidFinish(testSuite: XCTestSuite) {
func testSuiteDidFinish(_ testSuite: XCTestSuite) {
print("In \(#function): \(testSuite.name)")
}

func testBundleDidFinish(testBundle: NSBundle) {
func testBundleDidFinish(_ testBundle: NSBundle) {
print("In \(#function)")
}
}
Expand Down
14 changes: 7 additions & 7 deletions Tests/Functional/Observation/Selected/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ class Observer: XCTestObservation {
var startedTestSuites = [XCTestSuite]()
var finishedTestSuites = [XCTestSuite]()

func testBundleWillStart(testBundle: NSBundle) {}
func testBundleWillStart(_ testBundle: NSBundle) {}

func testSuiteWillStart(testSuite: XCTestSuite) {
func testSuiteWillStart(_ testSuite: XCTestSuite) {
startedTestSuites.append(testSuite)
}

func testCaseWillStart(testCase: XCTestCase) {}
func testCase(testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {}
func testCaseDidFinish(testCase: XCTestCase) {}
func testCaseWillStart(_ testCase: XCTestCase) {}
func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {}
func testCaseDidFinish(_ testCase: XCTestCase) {}

func testSuiteDidFinish(testSuite: XCTestSuite) {
func testSuiteDidFinish(_ testSuite: XCTestSuite) {
print("In \(#function): \(testSuite.name)")
}

func testBundleDidFinish(testBundle: NSBundle) {}
func testBundleDidFinish(_ testBundle: NSBundle) {}
}

let observer = Observer()
Expand Down