Skip to content

[SE-0066] Adapt to new function type syntax #104

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
2 changes: 1 addition & 1 deletion Documentation/Linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ When running on the Objective-C runtime, XCTest is able to find all of your test

```swift
class TestNSURL : XCTestCase {
static var allTests : [(String, TestNSURL -> () throws -> Void)] {
static var allTests : [(String, (TestNSURL) -> () throws -> Void)] {
return [
("test_URLStrings", test_URLStrings),
("test_fileURLWithPath_relativeToURL", test_fileURLWithPath_relativeToURL),
Expand Down
2 changes: 1 addition & 1 deletion Sources/XCTest/XCAbstractTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ public class XCTest {
// FIXME: This initializer is required due to a Swift compiler bug on Linux.
// It should be removed once the bug is fixed.
public init() {}
}
}
9 changes: 4 additions & 5 deletions Sources/XCTest/XCTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/// This type is intended to be produced by the `testCase` helper function.
/// - seealso: `testCase`
/// - seealso: `XCTMain`
public typealias XCTestCaseEntry = (testCaseClass: XCTestCase.Type, allTests: [(String, XCTestCase throws -> Void)])
public typealias XCTestCaseEntry = (testCaseClass: XCTestCase.Type, allTests: [(String, (XCTestCase) throws -> Void)])

// A global pointer to the currently running test case. This is required in
// order for XCTAssert functions to report failures.
Expand All @@ -33,7 +33,7 @@ internal var XCTCurrentTestCase: XCTestCase?
/// methods containing the tests to run.
/// - seealso: `XCTMain`
public class XCTestCase: XCTest {
private let testClosure: XCTestCase throws -> Void
private let testClosure: (XCTestCase) throws -> Void

/// The name of the test case, consisting of its class name and the method
/// name it will run.
Expand Down Expand Up @@ -81,7 +81,7 @@ public class XCTestCase: XCTest {
/// - Note: Like the designated initializer for Apple XCTest's XCTestCase,
/// `-[XCTestCase initWithInvocation:]`, it's rare for anyone outside of
/// XCTest itself to call this initializer.
public required init(name: String, testClosure: XCTestCase throws -> Void) {
public required init(name: String, testClosure: (XCTestCase) throws -> Void) {
_name = "\(self.dynamicType).\(name)"
self.testClosure = testClosure
}
Expand Down Expand Up @@ -142,7 +142,7 @@ 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)
}
Expand All @@ -158,7 +158,6 @@ private func test<T: XCTestCase>(_ testFunc: T -> () throws -> Void) -> XCTestCa
}

extension XCTestCase {

public var continueAfterFailure: Bool {
get {
return true
Expand Down
2 changes: 1 addition & 1 deletion Sources/XCTest/XCTestMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/// Example usage:
///
/// class TestFoo: XCTestCase {
/// static var allTests : [(String, TestFoo -> () throws -> Void)] {
/// static var allTests : [(String, (TestFoo) -> () throws -> Void)] {
/// return [
/// ("test_foo", test_foo),
/// ("test_bar", test_bar),
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Asynchronous/Expectations/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ExpectationsTestCase: XCTestCase {
waitForExpectations(withTimeout: -1.0)
}

static var allTests: [(String, ExpectationsTestCase -> () throws -> Void)] {
static var allTests: [(String, (ExpectationsTestCase) -> () throws -> Void)] {
return [
("test_waitingForAnUnfulfilledExpectation_fails", test_waitingForAnUnfulfilledExpectation_fails),
("test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails", test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails),
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Asynchronous/Handler/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class HandlerTestCase: XCTestCase {
XCTAssertTrue(handlerWasCalled)
}

static var allTests: [(String, HandlerTestCase -> () throws -> Void)] {
static var allTests: [(String, (HandlerTestCase) -> () throws -> Void)] {
return [
("test_whenExpectationsAreNotFulfilled_handlerCalled_andFails", test_whenExpectationsAreNotFulfilled_handlerCalled_andFails),
("test_whenExpectationsAreFulfilled_handlerCalled_andPasses", test_whenExpectationsAreFulfilled_handlerCalled_andPasses),
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Asynchronous/Misuse/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MisuseTestCase: XCTestCase {
self.waitForExpectations(withTimeout: 0.1)
}

static var allTests: [(String, MisuseTestCase -> () throws -> Void)] {
static var allTests: [(String, (MisuseTestCase) -> () throws -> Void)] {
return [
("test_whenExpectationsAreMade_butNotWaitedFor_fails", test_whenExpectationsAreMade_butNotWaitedFor_fails),
("test_whenNoExpectationsAreMade_butTheyAreWaitedFor_fails", test_whenNoExpectationsAreMade_butTheyAreWaitedFor_fails),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class NotificationExpectationsTestCase: XCTestCase {
waitForExpectations(withTimeout: 0.1)
}

static var allTests: [(String, NotificationExpectationsTestCase -> () throws -> Void)] {
static var allTests: [(String, (NotificationExpectationsTestCase) -> () throws -> Void)] {
return [
("test_observeNotificationWithName_passes", test_observeNotificationWithName_passes),
("test_observeNotificationWithNameAndObject_passes", test_observeNotificationWithNameAndObject_passes),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class NotificationHandlerTestCase: XCTestCase {
NSNotificationCenter.defaultCenter().postNotificationName("note", object: nil)
}

static var allTests: [(String, NotificationHandlerTestCase -> () throws -> Void)] {
static var allTests: [(String, (NotificationHandlerTestCase) -> () throws -> Void)] {
return [
("test_notificationNameIsObserved_handlerReturnsFalse_andFails", test_notificationNameIsObserved_handlerReturnsFalse_andFails),
("test_notificationNameIsObserved_handlerReturnsTrue_andPasses", test_notificationNameIsObserved_handlerReturnsTrue_andPasses),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class PredicateExpectationsTestCase: XCTestCase {
waitForExpectations(withTimeout: 0.1)
}

static var allTests: [(String, PredicateExpectationsTestCase -> () throws -> Void)] {
static var allTests: [(String, (PredicateExpectationsTestCase) -> () throws -> Void)] {
return [
("test_immediatelyTruePredicateAndObject_passes", test_immediatelyTruePredicateAndObject_passes),
("test_immediatelyFalsePredicateAndObject_fails", test_immediatelyFalsePredicateAndObject_fails),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class PredicateHandlerTestCase: XCTestCase {
waitForExpectations(withTimeout: 0.1, handler: nil)
}

static var allTests: [(String, PredicateHandlerTestCase -> () throws -> Void)] {
static var allTests: [(String, (PredicateHandlerTestCase) -> () throws -> Void)] {
return [
("test_predicateIsTrue_handlerReturnsTrue_passes", test_predicateIsTrue_handlerReturnsTrue_passes),
("test_predicateIsTrue_handlerReturnsFalse_fails", test_predicateIsTrue_handlerReturnsFalse_fails),
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/ErrorHandling/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// CHECK: Test Suite 'ErrorHandling' started at \d+:\d+:\d+\.\d+
class ErrorHandling: XCTestCase {
static var allTests: [(String, ErrorHandling -> () throws -> Void)] {
static var allTests: [(String, (ErrorHandling) -> () throws -> Void)] {
return [
// Tests for XCTAssertThrowsError
("test_shouldButDoesNotThrowErrorInAssertion", test_shouldButDoesNotThrowErrorInAssertion),
Expand Down Expand Up @@ -112,4 +112,4 @@ XCTMain([testCase(ErrorHandling.allTests)])
// CHECK: Test Suite '.*\.xctest' failed at \d+:\d+:\d+\.\d+
// CHECK: \t Executed 6 tests, with 4 failures \(2 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
// CHECK: Test Suite 'All tests' failed at \d+:\d+:\d+\.\d+
// CHECK: \t Executed 6 tests, with 4 failures \(2 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
// CHECK: \t Executed 6 tests, with 4 failures \(2 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
4 changes: 2 additions & 2 deletions Tests/Functional/FailingTestSuite/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// CHECK: Test Suite 'PassingTestCase' started at \d+:\d+:\d+\.\d+
class PassingTestCase: XCTestCase {
static var allTests: [(String, PassingTestCase -> () throws -> Void)] {
static var allTests: [(String, (PassingTestCase) -> () throws -> Void)] {
return [
("test_passes", test_passes),
]
Expand All @@ -30,7 +30,7 @@ class PassingTestCase: XCTestCase {

// CHECK: Test Suite 'FailingTestCase' started at \d+:\d+:\d+\.\d+
class FailingTestCase: XCTestCase {
static var allTests: [(String, FailingTestCase -> () throws -> Void)] {
static var allTests: [(String, (FailingTestCase) -> () throws -> Void)] {
return [
("test_passes", test_passes),
("test_fails", test_fails),
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/FailureMessagesTestCase/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

// CHECK: Test Suite 'FailureMessagesTestCase' started at \d+:\d+:\d+\.\d+
class FailureMessagesTestCase: XCTestCase {
static var allTests: [(String, FailureMessagesTestCase -> () throws -> Void)] {
static var allTests: [(String, (FailureMessagesTestCase) -> () throws -> Void)] {
return [
("testAssert", testAssert),
("testAssertEqualOptionals", testAssertEqualOptionals),
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/NegativeAccuracyTestCase/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

// CHECK: Test Suite 'NegativeAccuracyTestCase' started at \d+:\d+:\d+\.\d+
class NegativeAccuracyTestCase: XCTestCase {
static var allTests: [(String, NegativeAccuracyTestCase -> () throws -> Void)] {
static var allTests: [(String, (NegativeAccuracyTestCase) -> () throws -> Void)] {
return [
("test_equalWithAccuracy_passes", test_equalWithAccuracy_passes),
("test_equalWithAccuracy_fails", test_equalWithAccuracy_fails),
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Observation/All/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ XCTestObservationCenter.shared().addTestObserver(observer)

// CHECK: Test Suite 'Observation' started at \d+:\d+:\d+\.\d+
class Observation: XCTestCase {
static var allTests: [(String, Observation -> () throws -> Void)] {
static var allTests: [(String, (Observation) -> () throws -> Void)] {
return [
("test_one", test_one),
("test_two", test_two),
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Observation/Selected/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let observer = Observer()
XCTestObservationCenter.shared().addTestObserver(observer)

class SkippedTestCase: XCTestCase {
static var allTests: [(String, SkippedTestCase -> () throws -> Void)] {
static var allTests: [(String, (SkippedTestCase) -> () throws -> Void)] {
return [
("test_skipped", test_skipped),
]
Expand All @@ -50,7 +50,7 @@ class SkippedTestCase: XCTestCase {

// CHECK: Test Suite 'ExecutedTestCase' started at \d+:\d+:\d+\.\d+
class ExecutedTestCase: XCTestCase {
static var allTests: [(String, ExecutedTestCase -> () throws -> Void)] {
static var allTests: [(String, (ExecutedTestCase) -> () throws -> Void)] {
return [
("test_executed", test_executed),
("test_skipped", test_skipped),
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/SelectedTest/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// CHECK-ALL: Test Suite '.*\.xctest' started at \d+:\d+:\d+\.\d+

class ExecutedTestCase: XCTestCase {
static var allTests: [(String, ExecutedTestCase -> () throws -> Void)] {
static var allTests: [(String, (ExecutedTestCase) -> () throws -> Void)] {
return [
("test_bar", test_bar),
("test_foo", test_foo),
Expand Down Expand Up @@ -52,7 +52,7 @@ class ExecutedTestCase: XCTestCase {

// CHECK-ALL: Test Suite 'SkippedTestCase' started at \d+:\d+:\d+\.\d+
class SkippedTestCase: XCTestCase {
static var allTests: [(String, SkippedTestCase -> () throws -> Void)] {
static var allTests: [(String, (SkippedTestCase) -> () throws -> Void)] {
return [("test_baz", test_baz)]
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/SingleFailingTestCase/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// CHECK: Test Suite 'SingleFailingTestCase' started at \d+:\d+:\d+\.\d+
class SingleFailingTestCase: XCTestCase {
static var allTests: [(String, SingleFailingTestCase -> () throws -> Void)] {
static var allTests: [(String, (SingleFailingTestCase) -> () throws -> Void)] {
return [
("test_fails", test_fails)
]
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/TestCaseLifecycle/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// CHECK: Test Suite 'SetUpTearDownTestCase' started at \d+:\d+:\d+\.\d+
class SetUpTearDownTestCase: XCTestCase {
static var allTests: [(String, SetUpTearDownTestCase -> () throws -> Void)] {
static var allTests: [(String, (SetUpTearDownTestCase) -> () throws -> Void)] {
return [
("test_hasValueFromSetUp", test_hasValueFromSetUp),
]
Expand Down Expand Up @@ -60,7 +60,7 @@ class SetUpTearDownTestCase: XCTestCase {

// CHECK: Test Suite 'NewInstanceForEachTestTestCase' started at \d+:\d+:\d+\.\d+
class NewInstanceForEachTestTestCase: XCTestCase {
static var allTests: [(String, NewInstanceForEachTestTestCase -> () throws -> Void)] {
static var allTests: [(String, (NewInstanceForEachTestTestCase) -> () throws -> Void)] {
return [
("test_hasInitializedValue", test_hasInitializedValue),
("test_hasInitializedValueInAnotherTest", test_hasInitializedValueInAnotherTest),
Expand Down