Skip to content

Commit eb1ff85

Browse files
committed
Added tests for overloaded XCTAssertThrowsError to validate that it rethrows when the error handler throws
1 parent 6286750 commit eb1ff85

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

Tests/Functional/ErrorHandling/main.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class ErrorHandling: XCTestCase {
1616
static var allTests = {
1717
return [
1818
// Tests for XCTAssertThrowsError
19+
("test_shouldRethrowErrorFromHandler", test_shouldRethrowErrorFromHandler),
20+
("test_shouldNotRethrowWhenHandlerDoesNotThrow", test_shouldNotRethrowWhenHandlerDoesNotThrow),
1921
("test_shouldButDoesNotThrowErrorInAssertion", test_shouldButDoesNotThrowErrorInAssertion),
2022
("test_shouldThrowErrorInAssertion", test_shouldThrowErrorInAssertion),
2123
("test_throwsErrorInAssertionButFailsWhenCheckingError", test_throwsErrorInAssertionButFailsWhenCheckingError),
@@ -59,6 +61,19 @@ class ErrorHandling: XCTestCase {
5961
throw SomeError.anError("an error message")
6062
}
6163

64+
// CHECK: Test Case 'ErrorHandling.test_shouldRethrowErrorFromHandler' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
65+
// CHECK: .*[/\\]ErrorHandling[/\\]main.swift:[[@LINE+3]]: error: ErrorHandling.test_shouldRethrowErrorFromHandler : XCTAssertThrowsError threw error "anError\("an error message"\)" -
66+
// CHECK: Test Case 'ErrorHandling.test_shouldRethrowErrorFromHandler' failed \(\d+\.\d+ seconds\)
67+
func test_shouldRethrowErrorFromHandler() throws {
68+
try XCTAssertThrowsError(try functionThatDoesThrowError()) {_ in try functionThatDoesThrowError() }
69+
}
70+
71+
// CHECK: Test Case 'ErrorHandling.test_shouldNotRethrowWhenHandlerDoesNotThrow' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
72+
// CHECK: Test Case 'ErrorHandling.test_shouldNotRethrowWhenHandlerDoesNotThrow' passed \(\d+\.\d+ seconds\)
73+
func test_shouldNotRethrowWhenHandlerDoesNotThrow() throws {
74+
try XCTAssertThrowsError(try functionThatDoesThrowError()) {_ in try functionThatDoesNotThrowError() }
75+
}
76+
6277
// CHECK: Test Case 'ErrorHandling.test_shouldButDoesNotThrowErrorInAssertion' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
6378
// CHECK: .*[/\\]ErrorHandling[/\\]main.swift:[[@LINE+3]]: error: ErrorHandling.test_shouldButDoesNotThrowErrorInAssertion : XCTAssertThrowsError failed: did not throw error -
6479
// CHECK: Test Case 'ErrorHandling.test_shouldButDoesNotThrowErrorInAssertion' failed \(\d+\.\d+ seconds\)
@@ -278,11 +293,11 @@ class ErrorHandling: XCTestCase {
278293
}
279294

280295
// CHECK: Test Suite 'ErrorHandling' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
281-
// CHECK: \t Executed \d+ tests, with \d+ failures \(5 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
296+
// CHECK: \t Executed \d+ tests, with \d+ failures \(6 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
282297

283298
XCTMain([testCase(ErrorHandling.allTests)])
284299

285300
// CHECK: Test Suite '.*\.xctest' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
286-
// CHECK: \t Executed \d+ tests, with \d+ failures \(5 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
301+
// CHECK: \t Executed \d+ tests, with \d+ failures \(6 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
287302
// CHECK: Test Suite 'All tests' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
288-
// CHECK: \t Executed \d+ tests, with \d+ failures \(5 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
303+
// CHECK: \t Executed \d+ tests, with \d+ failures \(6 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds

0 commit comments

Comments
 (0)