Skip to content

Take advantage of type inference when specifying allTests variables. #117

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 1 commit into from
May 25, 2016
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 Documentation/Linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ 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 = {
return [
("test_URLStrings", test_URLStrings),
("test_fileURLWithPath_relativeToURL", test_fileURLWithPath_relativeToURL),
("test_fileURLWithPath", test_fileURLWithPath),
("test_fileURLWithPath_isDirectory", test_fileURLWithPath_isDirectory),
// Other tests go here
]
}
}()

func test_fileURLWithPath_relativeToURL() {
// Write your test here. Most of the XCTAssert macros you are familiar with are available.
Expand Down
4 changes: 2 additions & 2 deletions Sources/XCTest/XCTestMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
/// Example usage:
///
/// class TestFoo: XCTestCase {
/// static var allTests : [(String, (TestFoo) -> () throws -> Void)] {
/// static var allTests = {
/// return [
/// ("test_foo", test_foo),
/// ("test_bar", test_bar),
/// ]
/// }
/// }()
///
/// func test_foo() {
/// // Test things...
Expand Down
4 changes: 2 additions & 2 deletions 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 = {
return [
("test_waitingForAnUnfulfilledExpectation_fails", test_waitingForAnUnfulfilledExpectation_fails),
("test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails", test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails),
Expand All @@ -89,7 +89,7 @@ class ExpectationsTestCase: XCTestCase {
("test_whenTimeoutIsImmediate_andAllExpectationsAreFulfilled_passes", test_whenTimeoutIsImmediate_andAllExpectationsAreFulfilled_passes),
("test_whenTimeoutIsImmediate_butNotAllExpectationsAreFulfilled_fails", test_whenTimeoutIsImmediate_butNotAllExpectationsAreFulfilled_fails),
]
}
}()
}
// CHECK: Test Suite 'ExpectationsTestCase' failed at \d+:\d+:\d+\.\d+
// CHECK: \t Executed 7 tests, with 4 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Asynchronous/Handler/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ class HandlerTestCase: XCTestCase {
XCTAssertTrue(handlerWasCalled)
}

static var allTests: [(String, (HandlerTestCase) -> () throws -> Void)] {
static var allTests = {
return [
("test_whenExpectationsAreNotFulfilled_handlerCalled_andFails", test_whenExpectationsAreNotFulfilled_handlerCalled_andFails),
("test_whenExpectationsAreFulfilled_handlerCalled_andPasses", test_whenExpectationsAreFulfilled_handlerCalled_andPasses),
]
}
}()
}
// CHECK: Test Suite 'HandlerTestCase' failed at \d+:\d+:\d+\.\d+
// CHECK: \t Executed 2 tests, with 1 failure \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Asynchronous/Misuse/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ class MisuseTestCase: XCTestCase {
self.waitForExpectations(withTimeout: 0.1)
}

static var allTests: [(String, (MisuseTestCase) -> () throws -> Void)] {
static var allTests = {
return [
("test_whenExpectationsAreMade_butNotWaitedFor_fails", test_whenExpectationsAreMade_butNotWaitedFor_fails),
("test_whenNoExpectationsAreMade_butTheyAreWaitedFor_fails", test_whenNoExpectationsAreMade_butTheyAreWaitedFor_fails),
("test_whenExpectationIsFulfilledMultipleTimes_fails", test_whenExpectationIsFulfilledMultipleTimes_fails),
]
}
}()
}
// CHECK: Test Suite 'MisuseTestCase' failed at \d+:\d+:\d+\.\d+
// CHECK: \t Executed 3 tests, with 4 failures \(4 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ class NotificationExpectationsTestCase: XCTestCase {
waitForExpectations(withTimeout: 0.1)
}

static var allTests: [(String, (NotificationExpectationsTestCase) -> () throws -> Void)] {
static var allTests = {
return [
("test_observeNotificationWithName_passes", test_observeNotificationWithName_passes),
("test_observeNotificationWithNameAndObject_passes", test_observeNotificationWithNameAndObject_passes),
("test_observeNotificationWithNameAndObject_butExpectingNoObject_passes", test_observeNotificationWithNameAndObject_butExpectingNoObject_passes),
("test_observeNotificationWithIncorrectName_fails", test_observeNotificationWithIncorrectName_fails),
("test_observeNotificationWithIncorrectObject_fails", test_observeNotificationWithIncorrectObject_fails),
]
}
}()
}
// CHECK: Test Suite 'NotificationExpectationsTestCase' failed at \d+:\d+:\d+\.\d+
// CHECK: \t Executed 5 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ class NotificationHandlerTestCase: XCTestCase {
NSNotificationCenter.defaultCenter().postNotificationName("note", object: nil)
}

static var allTests: [(String, (NotificationHandlerTestCase) -> () throws -> Void)] {
static var allTests = {
return [
("test_notificationNameIsObserved_handlerReturnsFalse_andFails", test_notificationNameIsObserved_handlerReturnsFalse_andFails),
("test_notificationNameIsObserved_handlerReturnsTrue_andPasses", test_notificationNameIsObserved_handlerReturnsTrue_andPasses),
("test_notificationNameIsObservedAfterTimeout_handlerIsNotCalled", test_notificationNameIsObservedAfterTimeout_handlerIsNotCalled),
]
}
}()
}
// CHECK: Test Suite 'NotificationHandlerTestCase' failed at \d+:\d+:\d+\.\d+
// CHECK: \t Executed 3 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ class PredicateExpectationsTestCase: XCTestCase {
waitForExpectations(withTimeout: 0.1)
}

static var allTests: [(String, (PredicateExpectationsTestCase) -> () throws -> Void)] {
static var allTests = {
return [
("test_immediatelyTruePredicateAndObject_passes", test_immediatelyTruePredicateAndObject_passes),
("test_immediatelyFalsePredicateAndObject_fails", test_immediatelyFalsePredicateAndObject_fails),
("test_delayedTruePredicateAndObject_passes", test_delayedTruePredicateAndObject_passes),
("test_immediatelyTrueDelayedFalsePredicateAndObject_passes", test_immediatelyTrueDelayedFalsePredicateAndObject_passes),
]
}
}()
}

// CHECK: Test Suite 'PredicateExpectationsTestCase' failed at \d+:\d+:\d+\.\d+
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Asynchronous/Predicates/Handler/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ class PredicateHandlerTestCase: XCTestCase {
waitForExpectations(withTimeout: 0.1, handler: nil)
}

static var allTests: [(String, (PredicateHandlerTestCase) -> () throws -> Void)] {
static var allTests = {
return [
("test_predicateIsTrue_handlerReturnsTrue_passes", test_predicateIsTrue_handlerReturnsTrue_passes),
("test_predicateIsTrue_handlerReturnsFalse_fails", test_predicateIsTrue_handlerReturnsFalse_fails),
("test_predicateIsTrueAfterTimeout_handlerIsNotCalled_fails", test_predicateIsTrueAfterTimeout_handlerIsNotCalled_fails),
]
}
}()
}

// CHECK: Test Suite 'PredicateHandlerTestCase' failed at \d+:\d+:\d+\.\d+
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 = {
return [
// Tests for XCTAssertThrowsError
("test_shouldButDoesNotThrowErrorInAssertion", test_shouldButDoesNotThrowErrorInAssertion),
Expand All @@ -27,7 +27,7 @@ class ErrorHandling: XCTestCase {
// Tests for throwing assertion expressions
("test_assertionExpressionCanThrow", test_assertionExpressionCanThrow),
]
}
}()

func functionThatDoesNotThrowError() throws {
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/Functional/FailingTestSuite/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

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

// CHECK: Test Case 'PassingTestCase.test_passes' started at \d+:\d+:\d+\.\d+
// CHECK: Test Case 'PassingTestCase.test_passes' passed \(\d+\.\d+ seconds\).
Expand All @@ -30,13 +30,13 @@ 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 = {
return [
("test_passes", test_passes),
("test_fails", test_fails),
("test_fails_with_message", test_fails_with_message),
]
}
}()

// CHECK: Test Case 'FailingTestCase.test_passes' started at \d+:\d+:\d+\.\d+
// CHECK: Test Case 'FailingTestCase.test_passes' passed \(\d+\.\d+ seconds\).
Expand Down
6 changes: 3 additions & 3 deletions 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 = {
return [
("testAssert", testAssert),
("testAssertEqualOptionals", testAssertEqualOptionals),
Expand All @@ -40,12 +40,12 @@ class FailureMessagesTestCase: XCTestCase {
("testAssertTrue", testAssertTrue),
("testFail", testFail),
]
}
}()

// CHECK: Test Case 'FailureMessagesTestCase.testAssert' started at \d+:\d+:\d+\.\d+
// CHECK: test.swift:[[@LINE+3]]: error: FailureMessagesTestCase.testAssert : XCTAssertTrue failed - message
// CHECK: Test Case 'FailureMessagesTestCase.testAssert' failed \(\d+\.\d+ seconds\).
func testAssert() {
func testAssert() throws {
XCTAssert(false, "message", file: "test.swift")
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/NegativeAccuracyTestCase/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

// CHECK: Test Suite 'NegativeAccuracyTestCase' started at \d+:\d+:\d+\.\d+
class NegativeAccuracyTestCase: XCTestCase {
static var allTests: [(String, (NegativeAccuracyTestCase) -> () throws -> Void)] {
static var allTests = {
return [
("test_equalWithAccuracy_passes", test_equalWithAccuracy_passes),
("test_equalWithAccuracy_fails", test_equalWithAccuracy_fails),
("test_notEqualWithAccuracy_passes", test_notEqualWithAccuracy_passes),
("test_notEqualWithAccuracy_fails", test_notEqualWithAccuracy_fails),
]
}
}()

// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_passes' started at \d+:\d+:\d+\.\d+
// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_passes' passed \(\d+\.\d+ seconds\).
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Observation/All/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ 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 = {
return [
("test_one", test_one),
("test_two", test_two),
("test_three", test_three),
]
}
}()

// CHECK: Test Case 'Observation.test_one' started at \d+:\d+:\d+\.\d+
// CHECK: .*/Observation/All/main.swift:[[@LINE+12]]: error: Observation.test_one : failed - fail!
Expand Down
8 changes: 4 additions & 4 deletions Tests/Functional/Observation/Selected/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ let observer = Observer()
XCTestObservationCenter.shared().addTestObserver(observer)

class SkippedTestCase: XCTestCase {
static var allTests: [(String, (SkippedTestCase) -> () throws -> Void)] {
static var allTests = {
return [
("test_skipped", test_skipped),
]
}
}()

func test_skipped() {
XCTFail("This test case should not be executed.")
Expand All @@ -50,12 +50,12 @@ 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 = {
return [
("test_executed", test_executed),
("test_skipped", test_skipped),
]
}
}()

// CHECK: Test Case 'ExecutedTestCase.test_executed' started at \d+:\d+:\d+\.\d+
// CHECK: Test Case 'ExecutedTestCase.test_executed' passed \(\d+\.\d+ seconds\).
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Performance/Misuse/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class PerformanceMisuseTestCase: XCTestCase {
}
// CHECK: Test Case 'PerformanceMisuseTestCase.test_measuringUnknownMetric_fails' failed \(\d+\.\d+ seconds\).

static var allTests: [(String, (PerformanceMisuseTestCase) -> () throws -> Void)] {
static var allTests = {
return [
("test_whenMeasuringMultipleInOneTest_fails", test_whenMeasuringMultipleInOneTest_fails),
("test_whenMeasuringMetricsAndNotStartingOrEnding_fails", test_whenMeasuringMetricsAndNotStartingOrEnding_fails),
Expand All @@ -122,7 +122,7 @@ class PerformanceMisuseTestCase: XCTestCase {
("test_measuringNoMetrics_fails", test_measuringNoMetrics_fails),
("test_measuringUnknownMetric_fails", test_measuringUnknownMetric_fails),
]
}
}()
}
// CHECK: Test Suite 'PerformanceMisuseTestCase' failed at \d+:\d+:\d+\.\d+
// CHECK: \t Executed \d+ tests, with 12 failures \(12 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Performance/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class PerformanceTestCase: XCTestCase {
}
// CHECK: Test Case 'PerformanceTestCase.test_measuresWallClockTimeInBlock' failed \(\d+\.\d+ seconds\).

static var allTests: [(String, (PerformanceTestCase) -> () throws -> Void)] {
static var allTests = {
return [
("test_measureBlockIteratesTenTimes", test_measureBlockIteratesTenTimes),
("test_measuresMetricsWithAutomaticStartAndStop", test_measuresMetricsWithAutomaticStartAndStop),
Expand All @@ -107,7 +107,7 @@ class PerformanceTestCase: XCTestCase {
("test_abortsMeasurementsAfterTestFailure", test_abortsMeasurementsAfterTestFailure),
("test_measuresWallClockTimeInBlock", test_measuresWallClockTimeInBlock),
]
}
}()
}
// CHECK: Test Suite 'PerformanceTestCase' failed at \d+:\d+:\d+\.\d+
// CHECK: \t Executed \d+ tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
Expand Down
8 changes: 4 additions & 4 deletions Tests/Functional/SelectedTest/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
// CHECK-ALL: Test Suite '.*\.xctest' started at \d+:\d+:\d+\.\d+

class ExecutedTestCase: XCTestCase {
static var allTests: [(String, (ExecutedTestCase) -> () throws -> Void)] {
static var allTests = {
return [
("test_bar", test_bar),
("test_foo", test_foo),
]
}
}()

// CHECK-METHOD: Test Suite 'ExecutedTestCase' started at \d+:\d+:\d+\.\d+
// CHECK-METHOD: Test Case 'ExecutedTestCase.test_foo' started at \d+:\d+:\d+\.\d+
Expand Down Expand Up @@ -52,9 +52,9 @@ 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 = {
return [("test_baz", test_baz)]
}
}()

// CHECK-ALL: Test Case 'SkippedTestCase.test_baz' started at \d+:\d+:\d+\.\d+
// CHECK-ALL: Test Case 'SkippedTestCase.test_baz' passed \(\d+\.\d+ seconds\).
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/SingleFailingTestCase/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

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

// CHECK: Test Case 'SingleFailingTestCase.test_fails' started at \d+:\d+:\d+\.\d+
// CHECK: .*/SingleFailingTestCase/main.swift:[[@LINE+3]]: error: SingleFailingTestCase.test_fails : XCTAssertTrue failed -
Expand Down
8 changes: 4 additions & 4 deletions Tests/Functional/TestCaseLifecycle/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

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

var value = 0

Expand Down Expand Up @@ -60,12 +60,12 @@ 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 = {
return [
("test_hasInitializedValue", test_hasInitializedValue),
("test_hasInitializedValueInAnotherTest", test_hasInitializedValueInAnotherTest),
]
}
}()

var value = 1

Expand Down