Skip to content

Commit c82928c

Browse files
committed
Merge pull request #117 from briancroom/adjust-allTests
Take advantage of type inference when specifying `allTests` variables.
2 parents cf6b722 + 5b854aa commit c82928c

File tree

20 files changed

+49
-49
lines changed

20 files changed

+49
-49
lines changed

Documentation/Linux.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ When running on the Objective-C runtime, XCTest is able to find all of your test
44

55
```swift
66
class TestNSURL : XCTestCase {
7-
static var allTests : [(String, (TestNSURL) -> () throws -> Void)] {
7+
static var allTests = {
88
return [
99
("test_URLStrings", test_URLStrings),
1010
("test_fileURLWithPath_relativeToURL", test_fileURLWithPath_relativeToURL),
1111
("test_fileURLWithPath", test_fileURLWithPath),
1212
("test_fileURLWithPath_isDirectory", test_fileURLWithPath_isDirectory),
1313
// Other tests go here
1414
]
15-
}
15+
}()
1616

1717
func test_fileURLWithPath_relativeToURL() {
1818
// Write your test here. Most of the XCTAssert macros you are familiar with are available.

Sources/XCTest/XCTestMain.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
/// Example usage:
2727
///
2828
/// class TestFoo: XCTestCase {
29-
/// static var allTests : [(String, (TestFoo) -> () throws -> Void)] {
29+
/// static var allTests = {
3030
/// return [
3131
/// ("test_foo", test_foo),
3232
/// ("test_bar", test_bar),
3333
/// ]
34-
/// }
34+
/// }()
3535
///
3636
/// func test_foo() {
3737
/// // Test things...

Tests/Functional/Asynchronous/Expectations/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ExpectationsTestCase: XCTestCase {
7979
waitForExpectations(withTimeout: -1.0)
8080
}
8181

82-
static var allTests: [(String, (ExpectationsTestCase) -> () throws -> Void)] {
82+
static var allTests = {
8383
return [
8484
("test_waitingForAnUnfulfilledExpectation_fails", test_waitingForAnUnfulfilledExpectation_fails),
8585
("test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails", test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails),
@@ -89,7 +89,7 @@ class ExpectationsTestCase: XCTestCase {
8989
("test_whenTimeoutIsImmediate_andAllExpectationsAreFulfilled_passes", test_whenTimeoutIsImmediate_andAllExpectationsAreFulfilled_passes),
9090
("test_whenTimeoutIsImmediate_butNotAllExpectationsAreFulfilled_fails", test_whenTimeoutIsImmediate_butNotAllExpectationsAreFulfilled_fails),
9191
]
92-
}
92+
}()
9393
}
9494
// CHECK: Test Suite 'ExpectationsTestCase' failed at \d+:\d+:\d+\.\d+
9595
// CHECK: \t Executed 7 tests, with 4 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds

Tests/Functional/Asynchronous/Handler/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ class HandlerTestCase: XCTestCase {
4545
XCTAssertTrue(handlerWasCalled)
4646
}
4747

48-
static var allTests: [(String, (HandlerTestCase) -> () throws -> Void)] {
48+
static var allTests = {
4949
return [
5050
("test_whenExpectationsAreNotFulfilled_handlerCalled_andFails", test_whenExpectationsAreNotFulfilled_handlerCalled_andFails),
5151
("test_whenExpectationsAreFulfilled_handlerCalled_andPasses", test_whenExpectationsAreFulfilled_handlerCalled_andPasses),
5252
]
53-
}
53+
}()
5454
}
5555
// CHECK: Test Suite 'HandlerTestCase' failed at \d+:\d+:\d+\.\d+
5656
// CHECK: \t Executed 2 tests, with 1 failure \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds

Tests/Functional/Asynchronous/Misuse/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ class MisuseTestCase: XCTestCase {
4949
self.waitForExpectations(withTimeout: 0.1)
5050
}
5151

52-
static var allTests: [(String, (MisuseTestCase) -> () throws -> Void)] {
52+
static var allTests = {
5353
return [
5454
("test_whenExpectationsAreMade_butNotWaitedFor_fails", test_whenExpectationsAreMade_butNotWaitedFor_fails),
5555
("test_whenNoExpectationsAreMade_butTheyAreWaitedFor_fails", test_whenNoExpectationsAreMade_butTheyAreWaitedFor_fails),
5656
("test_whenExpectationIsFulfilledMultipleTimes_fails", test_whenExpectationIsFulfilledMultipleTimes_fails),
5757
]
58-
}
58+
}()
5959
}
6060
// CHECK: Test Suite 'MisuseTestCase' failed at \d+:\d+:\d+\.\d+
6161
// CHECK: \t Executed 3 tests, with 4 failures \(4 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds

Tests/Functional/Asynchronous/Notifications/Expectations/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ class NotificationExpectationsTestCase: XCTestCase {
6666
waitForExpectations(withTimeout: 0.1)
6767
}
6868

69-
static var allTests: [(String, (NotificationExpectationsTestCase) -> () throws -> Void)] {
69+
static var allTests = {
7070
return [
7171
("test_observeNotificationWithName_passes", test_observeNotificationWithName_passes),
7272
("test_observeNotificationWithNameAndObject_passes", test_observeNotificationWithNameAndObject_passes),
7373
("test_observeNotificationWithNameAndObject_butExpectingNoObject_passes", test_observeNotificationWithNameAndObject_butExpectingNoObject_passes),
7474
("test_observeNotificationWithIncorrectName_fails", test_observeNotificationWithIncorrectName_fails),
7575
("test_observeNotificationWithIncorrectObject_fails", test_observeNotificationWithIncorrectObject_fails),
7676
]
77-
}
77+
}()
7878
}
7979
// CHECK: Test Suite 'NotificationExpectationsTestCase' failed at \d+:\d+:\d+\.\d+
8080
// CHECK: \t Executed 5 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds

Tests/Functional/Asynchronous/Notifications/Handler/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ class NotificationHandlerTestCase: XCTestCase {
5050
NSNotificationCenter.defaultCenter().postNotificationName("note", object: nil)
5151
}
5252

53-
static var allTests: [(String, (NotificationHandlerTestCase) -> () throws -> Void)] {
53+
static var allTests = {
5454
return [
5555
("test_notificationNameIsObserved_handlerReturnsFalse_andFails", test_notificationNameIsObserved_handlerReturnsFalse_andFails),
5656
("test_notificationNameIsObserved_handlerReturnsTrue_andPasses", test_notificationNameIsObserved_handlerReturnsTrue_andPasses),
5757
("test_notificationNameIsObservedAfterTimeout_handlerIsNotCalled", test_notificationNameIsObservedAfterTimeout_handlerIsNotCalled),
5858
]
59-
}
59+
}()
6060
}
6161
// CHECK: Test Suite 'NotificationHandlerTestCase' failed at \d+:\d+:\d+\.\d+
6262
// CHECK: \t Executed 3 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds

Tests/Functional/Asynchronous/Predicates/Expectations/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ class PredicateExpectationsTestCase: XCTestCase {
6363
waitForExpectations(withTimeout: 0.1)
6464
}
6565

66-
static var allTests: [(String, (PredicateExpectationsTestCase) -> () throws -> Void)] {
66+
static var allTests = {
6767
return [
6868
("test_immediatelyTruePredicateAndObject_passes", test_immediatelyTruePredicateAndObject_passes),
6969
("test_immediatelyFalsePredicateAndObject_fails", test_immediatelyFalsePredicateAndObject_fails),
7070
("test_delayedTruePredicateAndObject_passes", test_delayedTruePredicateAndObject_passes),
7171
("test_immediatelyTrueDelayedFalsePredicateAndObject_passes", test_immediatelyTrueDelayedFalsePredicateAndObject_passes),
7272
]
73-
}
73+
}()
7474
}
7575

7676
// CHECK: Test Suite 'PredicateExpectationsTestCase' failed at \d+:\d+:\d+\.\d+

Tests/Functional/Asynchronous/Predicates/Handler/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ class PredicateHandlerTestCase: XCTestCase {
5555
waitForExpectations(withTimeout: 0.1, handler: nil)
5656
}
5757

58-
static var allTests: [(String, (PredicateHandlerTestCase) -> () throws -> Void)] {
58+
static var allTests = {
5959
return [
6060
("test_predicateIsTrue_handlerReturnsTrue_passes", test_predicateIsTrue_handlerReturnsTrue_passes),
6161
("test_predicateIsTrue_handlerReturnsFalse_fails", test_predicateIsTrue_handlerReturnsFalse_fails),
6262
("test_predicateIsTrueAfterTimeout_handlerIsNotCalled_fails", test_predicateIsTrueAfterTimeout_handlerIsNotCalled_fails),
6363
]
64-
}
64+
}()
6565
}
6666

6767
// CHECK: Test Suite 'PredicateHandlerTestCase' failed at \d+:\d+:\d+\.\d+

Tests/Functional/ErrorHandling/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
// CHECK: Test Suite 'ErrorHandling' started at \d+:\d+:\d+\.\d+
1515
class ErrorHandling: XCTestCase {
16-
static var allTests: [(String, (ErrorHandling) -> () throws -> Void)] {
16+
static var allTests = {
1717
return [
1818
// Tests for XCTAssertThrowsError
1919
("test_shouldButDoesNotThrowErrorInAssertion", test_shouldButDoesNotThrowErrorInAssertion),
@@ -27,7 +27,7 @@ class ErrorHandling: XCTestCase {
2727
// Tests for throwing assertion expressions
2828
("test_assertionExpressionCanThrow", test_assertionExpressionCanThrow),
2929
]
30-
}
30+
}()
3131

3232
func functionThatDoesNotThrowError() throws {
3333
}

Tests/Functional/FailingTestSuite/main.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

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

2222
// CHECK: Test Case 'PassingTestCase.test_passes' started at \d+:\d+:\d+\.\d+
2323
// CHECK: Test Case 'PassingTestCase.test_passes' passed \(\d+\.\d+ seconds\).
@@ -30,13 +30,13 @@ class PassingTestCase: XCTestCase {
3030

3131
// CHECK: Test Suite 'FailingTestCase' started at \d+:\d+:\d+\.\d+
3232
class FailingTestCase: XCTestCase {
33-
static var allTests: [(String, (FailingTestCase) -> () throws -> Void)] {
33+
static var allTests = {
3434
return [
3535
("test_passes", test_passes),
3636
("test_fails", test_fails),
3737
("test_fails_with_message", test_fails_with_message),
3838
]
39-
}
39+
}()
4040

4141
// CHECK: Test Case 'FailingTestCase.test_passes' started at \d+:\d+:\d+\.\d+
4242
// CHECK: Test Case 'FailingTestCase.test_passes' passed \(\d+\.\d+ seconds\).

Tests/Functional/FailureMessagesTestCase/main.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
// CHECK: Test Suite 'FailureMessagesTestCase' started at \d+:\d+:\d+\.\d+
1717
class FailureMessagesTestCase: XCTestCase {
18-
static var allTests: [(String, (FailureMessagesTestCase) -> () throws -> Void)] {
18+
static var allTests = {
1919
return [
2020
("testAssert", testAssert),
2121
("testAssertEqualOptionals", testAssertEqualOptionals),
@@ -40,12 +40,12 @@ class FailureMessagesTestCase: XCTestCase {
4040
("testAssertTrue", testAssertTrue),
4141
("testFail", testFail),
4242
]
43-
}
43+
}()
4444

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

Tests/Functional/NegativeAccuracyTestCase/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515

1616
// CHECK: Test Suite 'NegativeAccuracyTestCase' started at \d+:\d+:\d+\.\d+
1717
class NegativeAccuracyTestCase: XCTestCase {
18-
static var allTests: [(String, (NegativeAccuracyTestCase) -> () throws -> Void)] {
18+
static var allTests = {
1919
return [
2020
("test_equalWithAccuracy_passes", test_equalWithAccuracy_passes),
2121
("test_equalWithAccuracy_fails", test_equalWithAccuracy_fails),
2222
("test_notEqualWithAccuracy_passes", test_notEqualWithAccuracy_passes),
2323
("test_notEqualWithAccuracy_fails", test_notEqualWithAccuracy_fails),
2424
]
25-
}
25+
}()
2626

2727
// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_passes' started at \d+:\d+:\d+\.\d+
2828
// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_passes' passed \(\d+\.\d+ seconds\).

Tests/Functional/Observation/All/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ XCTestObservationCenter.shared().addTestObserver(observer)
5656

5757
// CHECK: Test Suite 'Observation' started at \d+:\d+:\d+\.\d+
5858
class Observation: XCTestCase {
59-
static var allTests: [(String, (Observation) -> () throws -> Void)] {
59+
static var allTests = {
6060
return [
6161
("test_one", test_one),
6262
("test_two", test_two),
6363
("test_three", test_three),
6464
]
65-
}
65+
}()
6666

6767
// CHECK: Test Case 'Observation.test_one' started at \d+:\d+:\d+\.\d+
6868
// CHECK: .*/Observation/All/main.swift:[[@LINE+12]]: error: Observation.test_one : failed - fail!

Tests/Functional/Observation/Selected/main.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ let observer = Observer()
3737
XCTestObservationCenter.shared().addTestObserver(observer)
3838

3939
class SkippedTestCase: XCTestCase {
40-
static var allTests: [(String, (SkippedTestCase) -> () throws -> Void)] {
40+
static var allTests = {
4141
return [
4242
("test_skipped", test_skipped),
4343
]
44-
}
44+
}()
4545

4646
func test_skipped() {
4747
XCTFail("This test case should not be executed.")
@@ -50,12 +50,12 @@ class SkippedTestCase: XCTestCase {
5050

5151
// CHECK: Test Suite 'ExecutedTestCase' started at \d+:\d+:\d+\.\d+
5252
class ExecutedTestCase: XCTestCase {
53-
static var allTests: [(String, (ExecutedTestCase) -> () throws -> Void)] {
53+
static var allTests = {
5454
return [
5555
("test_executed", test_executed),
5656
("test_skipped", test_skipped),
5757
]
58-
}
58+
}()
5959

6060
// CHECK: Test Case 'ExecutedTestCase.test_executed' started at \d+:\d+:\d+\.\d+
6161
// CHECK: Test Case 'ExecutedTestCase.test_executed' passed \(\d+\.\d+ seconds\).

Tests/Functional/Performance/Misuse/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class PerformanceMisuseTestCase: XCTestCase {
108108
}
109109
// CHECK: Test Case 'PerformanceMisuseTestCase.test_measuringUnknownMetric_fails' failed \(\d+\.\d+ seconds\).
110110

111-
static var allTests: [(String, (PerformanceMisuseTestCase) -> () throws -> Void)] {
111+
static var allTests = {
112112
return [
113113
("test_whenMeasuringMultipleInOneTest_fails", test_whenMeasuringMultipleInOneTest_fails),
114114
("test_whenMeasuringMetricsAndNotStartingOrEnding_fails", test_whenMeasuringMetricsAndNotStartingOrEnding_fails),
@@ -122,7 +122,7 @@ class PerformanceMisuseTestCase: XCTestCase {
122122
("test_measuringNoMetrics_fails", test_measuringNoMetrics_fails),
123123
("test_measuringUnknownMetric_fails", test_measuringUnknownMetric_fails),
124124
]
125-
}
125+
}()
126126
}
127127
// CHECK: Test Suite 'PerformanceMisuseTestCase' failed at \d+:\d+:\d+\.\d+
128128
// CHECK: \t Executed \d+ tests, with 12 failures \(12 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds

Tests/Functional/Performance/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class PerformanceTestCase: XCTestCase {
9696
}
9797
// CHECK: Test Case 'PerformanceTestCase.test_measuresWallClockTimeInBlock' failed \(\d+\.\d+ seconds\).
9898

99-
static var allTests: [(String, (PerformanceTestCase) -> () throws -> Void)] {
99+
static var allTests = {
100100
return [
101101
("test_measureBlockIteratesTenTimes", test_measureBlockIteratesTenTimes),
102102
("test_measuresMetricsWithAutomaticStartAndStop", test_measuresMetricsWithAutomaticStartAndStop),
@@ -107,7 +107,7 @@ class PerformanceTestCase: XCTestCase {
107107
("test_abortsMeasurementsAfterTestFailure", test_abortsMeasurementsAfterTestFailure),
108108
("test_measuresWallClockTimeInBlock", test_measuresWallClockTimeInBlock),
109109
]
110-
}
110+
}()
111111
}
112112
// CHECK: Test Suite 'PerformanceTestCase' failed at \d+:\d+:\d+\.\d+
113113
// CHECK: \t Executed \d+ tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds

Tests/Functional/SelectedTest/main.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
// CHECK-ALL: Test Suite '.*\.xctest' started at \d+:\d+:\d+\.\d+
1919

2020
class ExecutedTestCase: XCTestCase {
21-
static var allTests: [(String, (ExecutedTestCase) -> () throws -> Void)] {
21+
static var allTests = {
2222
return [
2323
("test_bar", test_bar),
2424
("test_foo", test_foo),
2525
]
26-
}
26+
}()
2727

2828
// CHECK-METHOD: Test Suite 'ExecutedTestCase' started at \d+:\d+:\d+\.\d+
2929
// CHECK-METHOD: Test Case 'ExecutedTestCase.test_foo' started at \d+:\d+:\d+\.\d+
@@ -52,9 +52,9 @@ class ExecutedTestCase: XCTestCase {
5252

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

5959
// CHECK-ALL: Test Case 'SkippedTestCase.test_baz' started at \d+:\d+:\d+\.\d+
6060
// CHECK-ALL: Test Case 'SkippedTestCase.test_baz' passed \(\d+\.\d+ seconds\).

Tests/Functional/SingleFailingTestCase/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

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

2222
// CHECK: Test Case 'SingleFailingTestCase.test_fails' started at \d+:\d+:\d+\.\d+
2323
// CHECK: .*/SingleFailingTestCase/main.swift:[[@LINE+3]]: error: SingleFailingTestCase.test_fails : XCTAssertTrue failed -

Tests/Functional/TestCaseLifecycle/main.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

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

2222
var value = 0
2323

@@ -60,12 +60,12 @@ class SetUpTearDownTestCase: XCTestCase {
6060

6161
// CHECK: Test Suite 'NewInstanceForEachTestTestCase' started at \d+:\d+:\d+\.\d+
6262
class NewInstanceForEachTestTestCase: XCTestCase {
63-
static var allTests: [(String, (NewInstanceForEachTestTestCase) -> () throws -> Void)] {
63+
static var allTests = {
6464
return [
6565
("test_hasInitializedValue", test_hasInitializedValue),
6666
("test_hasInitializedValueInAnotherTest", test_hasInitializedValueInAnotherTest),
6767
]
68-
}
68+
}()
6969

7070
var value = 1
7171

0 commit comments

Comments
 (0)