1
1
// RUN: %{swiftc} %s -o %{built_tests_dir}/ErrorHandling
2
2
// RUN: %{built_tests_dir}/ErrorHandling > %t || true
3
3
// RUN: %{xctest_checker} %t %s
4
- // CHECK: Test Case 'ErrorHandling.test_shouldButDoesNotThrowErrorInAssertion' started.
5
- // CHECK: .*/Tests/Functional/ErrorHandling/main.swift:\d+: error: ErrorHandling.test_shouldButDoesNotThrowErrorInAssertion : XCTAssertThrowsError failed: did not throw error -
6
- // CHECK: Test Case 'ErrorHandling.test_shouldButDoesNotThrowErrorInAssertion' failed \(\d+\.\d+ seconds\).
7
- // CHECK: Test Case 'ErrorHandling.test_shouldThrowErrorInAssertion' started.
8
- // CHECK: Test Case 'ErrorHandling.test_shouldThrowErrorInAssertion' passed \(\d+\.\d+ seconds\).
9
- // CHECK: Test Case 'ErrorHandling.test_throwsErrorInAssertionButFailsWhenCheckingError' started.
10
- // CHECK: .*/Tests/Functional/ErrorHandling/main.swift:\d+: error: ErrorHandling.test_throwsErrorInAssertionButFailsWhenCheckingError : XCTAssertEqual failed: \("Optional\("an error message"\)"\) is not equal to \("Optional\(""\)"\) -
11
- // CHECK: Test Case 'ErrorHandling.test_throwsErrorInAssertionButFailsWhenCheckingError' failed \(\d+\.\d+ seconds\).
12
- // CHECK: Test Case 'ErrorHandling.test_canAndDoesThrowErrorFromTestMethod' started.
13
- // CHECK: \<EXPR\>:0: unexpected error: ErrorHandling.test_canAndDoesThrowErrorFromTestMethod : threw error "AnError\("an error message"\)" -
14
- // CHECK: Test Case 'ErrorHandling.test_canAndDoesThrowErrorFromTestMethod' failed \(\d+\.\d+ seconds\).
15
- // CHECK: Test Case 'ErrorHandling.test_canButDoesNotThrowErrorFromTestMethod' started.
16
- // CHECK: Test Case 'ErrorHandling.test_canButDoesNotThrowErrorFromTestMethod' passed \(\d+\.\d+ seconds\).
17
- // CHECK: Test Case 'ErrorHandling.test_assertionExpressionCanThrow' started.
18
- // CHECK: .*/Tests/Functional/ErrorHandling/main.swift:\d+: unexpected error: ErrorHandling.test_assertionExpressionCanThrow : XCTAssertEqual threw error "AnError\("did not actually return"\)" -
19
- // CHECK: Test Case 'ErrorHandling.test_assertionExpressionCanThrow' failed \(\d+\.\d+ seconds\).
20
- // CHECK: Executed 6 tests, with 4 failures \(2 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
21
- // CHECK: Total executed 6 tests, with 4 failures \(2 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
22
4
23
5
#if os(Linux) || os(FreeBSD)
24
6
import XCTest
@@ -53,11 +35,16 @@ class ErrorHandling: XCTestCase {
53
35
func functionThatDoesThrowError( ) throws {
54
36
throw SomeError . AnError ( " an error message " )
55
37
}
56
-
38
+
39
+ // CHECK: Test Case 'ErrorHandling.test_shouldButDoesNotThrowErrorInAssertion' started.
40
+ // CHECK: .*/ErrorHandling/main.swift:\d+: error: ErrorHandling.test_shouldButDoesNotThrowErrorInAssertion : XCTAssertThrowsError failed: did not throw error -
41
+ // CHECK: Test Case 'ErrorHandling.test_shouldButDoesNotThrowErrorInAssertion' failed \(\d+\.\d+ seconds\).
57
42
func test_shouldButDoesNotThrowErrorInAssertion( ) {
58
43
XCTAssertThrowsError ( try functionThatDoesNotThrowError ( ) )
59
44
}
60
45
46
+ // CHECK: Test Case 'ErrorHandling.test_shouldThrowErrorInAssertion' started.
47
+ // CHECK: Test Case 'ErrorHandling.test_shouldThrowErrorInAssertion' passed \(\d+\.\d+ seconds\).
61
48
func test_shouldThrowErrorInAssertion( ) {
62
49
XCTAssertThrowsError ( try functionThatDoesThrowError ( ) ) { error in
63
50
guard let thrownError = error as? SomeError else {
@@ -72,6 +59,9 @@ class ErrorHandling: XCTestCase {
72
59
}
73
60
}
74
61
62
+ // CHECK: Test Case 'ErrorHandling.test_throwsErrorInAssertionButFailsWhenCheckingError' started.
63
+ // CHECK: .*/ErrorHandling/main.swift:\d+: error: ErrorHandling.test_throwsErrorInAssertionButFailsWhenCheckingError : XCTAssertEqual failed: \("Optional\("an error message"\)"\) is not equal to \("Optional\(""\)"\) -
64
+ // CHECK: Test Case 'ErrorHandling.test_throwsErrorInAssertionButFailsWhenCheckingError' failed \(\d+\.\d+ seconds\).
75
65
func test_throwsErrorInAssertionButFailsWhenCheckingError( ) {
76
66
XCTAssertThrowsError ( try functionThatDoesThrowError ( ) ) { error in
77
67
guard let thrownError = error as? SomeError else {
@@ -86,10 +76,15 @@ class ErrorHandling: XCTestCase {
86
76
}
87
77
}
88
78
79
+ // CHECK: Test Case 'ErrorHandling.test_canAndDoesThrowErrorFromTestMethod' started.
80
+ // CHECK: \<EXPR\>:0: unexpected error: ErrorHandling.test_canAndDoesThrowErrorFromTestMethod : threw error "AnError\("an error message"\)" -
81
+ // CHECK: Test Case 'ErrorHandling.test_canAndDoesThrowErrorFromTestMethod' failed \(\d+\.\d+ seconds\).
89
82
func test_canAndDoesThrowErrorFromTestMethod( ) throws {
90
83
try functionThatDoesThrowError ( )
91
84
}
92
85
86
+ // CHECK: Test Case 'ErrorHandling.test_canButDoesNotThrowErrorFromTestMethod' started.
87
+ // CHECK: Test Case 'ErrorHandling.test_canButDoesNotThrowErrorFromTestMethod' passed \(\d+\.\d+ seconds\).
93
88
func test_canButDoesNotThrowErrorFromTestMethod( ) throws {
94
89
try functionThatDoesNotThrowError ( )
95
90
}
@@ -98,9 +93,15 @@ class ErrorHandling: XCTestCase {
98
93
throw SomeError . AnError ( " did not actually return " )
99
94
}
100
95
96
+ // CHECK: Test Case 'ErrorHandling.test_assertionExpressionCanThrow' started.
97
+ // CHECK: .*/ErrorHandling/main.swift:\d+: unexpected error: ErrorHandling.test_assertionExpressionCanThrow : XCTAssertEqual threw error "AnError\("did not actually return"\)" -
98
+ // CHECK: Test Case 'ErrorHandling.test_assertionExpressionCanThrow' failed \(\d+\.\d+ seconds\).
101
99
func test_assertionExpressionCanThrow( ) {
102
100
XCTAssertEqual ( try functionThatShouldReturnButThrows ( ) , 1 )
103
101
}
104
102
}
105
103
106
104
XCTMain ( [ testCase ( ErrorHandling . allTests) ] )
105
+
106
+ // CHECK: Executed 6 tests, with 4 failures \(2 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
107
+ // CHECK: Total executed 6 tests, with 4 failures \(2 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
0 commit comments