Skip to content

Commit ced7f2b

Browse files
committed
Update tests to meet the new requirements
* Add XCTestCaseType conformances and update XCTMain invocation * Use the static allTests property
1 parent d3358bc commit ced7f2b

File tree

6 files changed

+64
-56
lines changed

6 files changed

+64
-56
lines changed

Tests/Functional/ErrorHandling/main.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@
2727
#endif
2828

2929
class ErrorHandling: XCTestCase {
30-
var allTests: [(String, () throws -> ())] {
30+
static var allTests: [(String, XCTestCaseType throws -> Void)] {
3131
return [
3232
// Tests for XCTAssertThrowsError
33-
("test_shouldButDoesNotThrowErrorInAssertion", test_shouldButDoesNotThrowErrorInAssertion),
34-
("test_shouldThrowErrorInAssertion", test_shouldThrowErrorInAssertion),
35-
("test_throwsErrorInAssertionButFailsWhenCheckingError", test_throwsErrorInAssertionButFailsWhenCheckingError),
33+
("test_shouldButDoesNotThrowErrorInAssertion", test(test_shouldButDoesNotThrowErrorInAssertion)),
34+
("test_shouldThrowErrorInAssertion", test(test_shouldThrowErrorInAssertion)),
35+
("test_throwsErrorInAssertionButFailsWhenCheckingError", test(test_throwsErrorInAssertionButFailsWhenCheckingError)),
3636

3737
// Tests for "testFoo() throws"
38-
("test_canAndDoesThrowErrorFromTestMethod", test_canAndDoesThrowErrorFromTestMethod),
39-
("test_canButDoesNotThrowErrorFromTestMethod", test_canButDoesNotThrowErrorFromTestMethod),
38+
("test_canAndDoesThrowErrorFromTestMethod", test(test_canAndDoesThrowErrorFromTestMethod)),
39+
("test_canButDoesNotThrowErrorFromTestMethod", test(test_canButDoesNotThrowErrorFromTestMethod)),
4040

4141
// Tests for throwing assertion expressions
42-
("test_assertionExpressionCanThrow", test_assertionExpressionCanThrow),
42+
("test_assertionExpressionCanThrow", test(test_assertionExpressionCanThrow)),
4343
]
4444
}
4545

@@ -103,4 +103,5 @@ class ErrorHandling: XCTestCase {
103103
}
104104
}
105105

106-
XCTMain([ErrorHandling()])
106+
extension ErrorHandling: XCTestCaseType {}
107+
XCTMain([ErrorHandling.self])

Tests/Functional/FailingTestSuite/main.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
#endif
2323

2424
class PassingTestCase: XCTestCase {
25-
var allTests: [(String, () throws -> ())] {
25+
static var allTests: [(String, XCTestCaseType throws -> Void)] {
2626
return [
27-
("test_passes", test_passes),
27+
("test_passes", test(test_passes)),
2828
]
2929
}
3030

@@ -34,11 +34,11 @@ class PassingTestCase: XCTestCase {
3434
}
3535

3636
class FailingTestCase: XCTestCase {
37-
var allTests: [(String, () throws -> ())] {
37+
static var allTests: [(String, XCTestCaseType throws -> Void)] {
3838
return [
39-
("test_passes", test_passes),
40-
("test_fails", test_fails),
41-
("test_fails_with_message", test_fails_with_message),
39+
("test_passes", test(test_passes)),
40+
("test_fails", test(test_fails)),
41+
("test_fails_with_message", test(test_fails_with_message)),
4242
]
4343
}
4444

@@ -55,7 +55,9 @@ class FailingTestCase: XCTestCase {
5555
}
5656
}
5757

58+
extension PassingTestCase: XCTestCaseType {}
59+
extension FailingTestCase: XCTestCaseType {}
5860
XCTMain([
59-
PassingTestCase(),
60-
FailingTestCase(),
61+
PassingTestCase.self,
62+
FailingTestCase.self,
6163
])

Tests/Functional/FailureMessagesTestCase/main.swift

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,30 +78,30 @@
7878

7979
// Regression test for https://github.com/apple/swift-corelibs-xctest/pull/22
8080
class FailureMessagesTestCase: XCTestCase {
81-
var allTests : [(String, () throws -> Void)] {
81+
static var allTests: [(String, XCTestCaseType throws -> Void)] {
8282
return [
83-
("testAssert", testAssert),
84-
("testAssertEqualOptionals", testAssertEqualOptionals),
85-
("testAssertEqualArraySlices", testAssertEqualArraySlices),
86-
("testAssertEqualContiguousArrays", testAssertEqualContiguousArrays),
87-
("testAssertEqualArrays", testAssertEqualArrays),
88-
("testAssertEqualDictionaries", testAssertEqualDictionaries),
89-
("testAssertEqualWithAccuracy", testAssertEqualWithAccuracy),
90-
("testAssertFalse", testAssertFalse),
91-
("testAssertGreaterThan", testAssertGreaterThan),
92-
("testAssertGreaterThanOrEqual", testAssertGreaterThanOrEqual),
93-
("testAssertLessThan", testAssertLessThan),
94-
("testAssertLessThanOrEqual", testAssertLessThanOrEqual),
95-
("testAssertNil", testAssertNil),
96-
("testAssertNotEqualOptionals", testAssertNotEqualOptionals),
97-
("testAssertNotEqualArraySlices", testAssertNotEqualArraySlices),
98-
("testAssertNotEqualContiguousArrays", testAssertNotEqualContiguousArrays),
99-
("testAssertNotEqualArrays", testAssertNotEqualArrays),
100-
("testAssertNotEqualDictionaries", testAssertNotEqualDictionaries),
101-
("testAssertNotEqualWithAccuracy", testAssertNotEqualWithAccuracy),
102-
("testAssertNotNil", testAssertNotNil),
103-
("testAssertTrue", testAssertTrue),
104-
("testFail", testFail),
83+
("testAssert", test(testAssert)),
84+
("testAssertEqualOptionals", test(testAssertEqualOptionals)),
85+
("testAssertEqualArraySlices", test(testAssertEqualArraySlices)),
86+
("testAssertEqualContiguousArrays", test(testAssertEqualContiguousArrays)),
87+
("testAssertEqualArrays", test(testAssertEqualArrays)),
88+
("testAssertEqualDictionaries", test(testAssertEqualDictionaries)),
89+
("testAssertEqualWithAccuracy", test(testAssertEqualWithAccuracy)),
90+
("testAssertFalse", test(testAssertFalse)),
91+
("testAssertGreaterThan", test(testAssertGreaterThan)),
92+
("testAssertGreaterThanOrEqual", test(testAssertGreaterThanOrEqual)),
93+
("testAssertLessThan", test(testAssertLessThan)),
94+
("testAssertLessThanOrEqual", test(testAssertLessThanOrEqual)),
95+
("testAssertNil", test(testAssertNil)),
96+
("testAssertNotEqualOptionals", test(testAssertNotEqualOptionals)),
97+
("testAssertNotEqualArraySlices", test(testAssertNotEqualArraySlices)),
98+
("testAssertNotEqualContiguousArrays", test(testAssertNotEqualContiguousArrays)),
99+
("testAssertNotEqualArrays", test(testAssertNotEqualArrays)),
100+
("testAssertNotEqualDictionaries", test(testAssertNotEqualDictionaries)),
101+
("testAssertNotEqualWithAccuracy", test(testAssertNotEqualWithAccuracy)),
102+
("testAssertNotNil", test(testAssertNotNil)),
103+
("testAssertTrue", test(testAssertTrue)),
104+
("testFail", test(testFail)),
105105
]
106106
}
107107

@@ -194,4 +194,5 @@ class FailureMessagesTestCase: XCTestCase {
194194
}
195195
}
196196

197-
XCTMain([FailureMessagesTestCase()])
197+
extension FailureMessagesTestCase: XCTestCaseType {}
198+
XCTMain([FailureMessagesTestCase.self])

Tests/Functional/NegativeAccuracyTestCase/main.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222

2323
// Regression test for https://github.com/apple/swift-corelibs-xctest/pull/7
2424
class NegativeAccuracyTestCase: XCTestCase {
25-
var allTests: [(String, () throws -> ())] {
25+
static var allTests: [(String, XCTestCaseType throws -> Void)] {
2626
return [
27-
("test_equalWithAccuracy_passes", test_equalWithAccuracy_passes),
28-
("test_equalWithAccuracy_fails", test_equalWithAccuracy_fails),
29-
("test_notEqualWithAccuracy_passes", test_notEqualWithAccuracy_passes),
30-
("test_notEqualWithAccuracy_fails", test_notEqualWithAccuracy_fails),
27+
("test_equalWithAccuracy_passes", test(test_equalWithAccuracy_passes)),
28+
("test_equalWithAccuracy_fails", test(test_equalWithAccuracy_fails)),
29+
("test_notEqualWithAccuracy_passes", test(test_notEqualWithAccuracy_passes)),
30+
("test_notEqualWithAccuracy_fails", test(test_notEqualWithAccuracy_fails)),
3131
]
3232
}
3333

@@ -48,4 +48,5 @@ class NegativeAccuracyTestCase: XCTestCase {
4848
}
4949
}
5050

51-
XCTMain([NegativeAccuracyTestCase()])
51+
extension NegativeAccuracyTestCase: XCTestCaseType {}
52+
XCTMain([NegativeAccuracyTestCase.self])

Tests/Functional/SingleFailingTestCase/main.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#endif
1515

1616
class SingleFailingTestCase: XCTestCase {
17-
var allTests: [(String, () throws -> ())] {
17+
static var allTests: [(String, XCTestCaseType throws -> Void)] {
1818
return [
19-
("test_fails", test_fails),
19+
("test_fails", test(test_fails))
2020
]
2121
}
2222

@@ -25,4 +25,5 @@ class SingleFailingTestCase: XCTestCase {
2525
}
2626
}
2727

28-
XCTMain([SingleFailingTestCase()])
28+
extension SingleFailingTestCase: XCTestCaseType {}
29+
XCTMain([SingleFailingTestCase.self])

Tests/Functional/TestCaseLifecycle/main.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#endif
2222

2323
class SetUpTearDownTestCase: XCTestCase {
24-
var allTests: [(String, () throws -> Void)] {
24+
static var allTests: [(String, XCTestCaseType throws -> Void)] {
2525
return [
26-
("test_hasValueFromSetUp", test_hasValueFromSetUp),
26+
("test_hasValueFromSetUp", test(test_hasValueFromSetUp)),
2727
]
2828
}
2929

@@ -47,10 +47,10 @@ class SetUpTearDownTestCase: XCTestCase {
4747
}
4848

4949
class NewInstanceForEachTestTestCase: XCTestCase {
50-
var allTests: [(String, () throws -> Void)] {
50+
static var allTests: [(String, XCTestCaseType throws -> Void)] {
5151
return [
52-
("test_hasInitializedValue", test_hasInitializedValue),
53-
("test_hasInitializedValueInAnotherTest", test_hasInitializedValueInAnotherTest),
52+
("test_hasInitializedValue", test(test_hasInitializedValue)),
53+
("test_hasInitializedValueInAnotherTest", test(test_hasInitializedValueInAnotherTest)),
5454
]
5555
}
5656

@@ -66,7 +66,9 @@ class NewInstanceForEachTestTestCase: XCTestCase {
6666
}
6767
}
6868

69+
extension SetUpTearDownTestCase: XCTestCaseType {}
70+
extension NewInstanceForEachTestTestCase: XCTestCaseType {}
6971
XCTMain([
70-
SetUpTearDownTestCase(),
71-
NewInstanceForEachTestTestCase()
72+
SetUpTearDownTestCase.self,
73+
NewInstanceForEachTestTestCase.self
7274
])

0 commit comments

Comments
 (0)