Skip to content

Commit afc816c

Browse files
committed
Merge pull request #66 from briancroom/reorganize-test-assertions
Reorganize test assertions
2 parents 50d3823 + 3a1ae3b commit afc816c

File tree

6 files changed

+143
-133
lines changed

6 files changed

+143
-133
lines changed

Tests/Functional/ErrorHandling/main.swift

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
11
// RUN: %{swiftc} %s -o %{built_tests_dir}/ErrorHandling
22
// RUN: %{built_tests_dir}/ErrorHandling > %t || true
33
// 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
224

235
#if os(Linux) || os(FreeBSD)
246
import XCTest
@@ -53,11 +35,16 @@ class ErrorHandling: XCTestCase {
5335
func functionThatDoesThrowError() throws {
5436
throw SomeError.AnError("an error message")
5537
}
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\).
5742
func test_shouldButDoesNotThrowErrorInAssertion() {
5843
XCTAssertThrowsError(try functionThatDoesNotThrowError())
5944
}
6045

46+
// CHECK: Test Case 'ErrorHandling.test_shouldThrowErrorInAssertion' started.
47+
// CHECK: Test Case 'ErrorHandling.test_shouldThrowErrorInAssertion' passed \(\d+\.\d+ seconds\).
6148
func test_shouldThrowErrorInAssertion() {
6249
XCTAssertThrowsError(try functionThatDoesThrowError()) { error in
6350
guard let thrownError = error as? SomeError else {
@@ -72,6 +59,9 @@ class ErrorHandling: XCTestCase {
7259
}
7360
}
7461

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\).
7565
func test_throwsErrorInAssertionButFailsWhenCheckingError() {
7666
XCTAssertThrowsError(try functionThatDoesThrowError()) { error in
7767
guard let thrownError = error as? SomeError else {
@@ -86,10 +76,15 @@ class ErrorHandling: XCTestCase {
8676
}
8777
}
8878

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\).
8982
func test_canAndDoesThrowErrorFromTestMethod() throws {
9083
try functionThatDoesThrowError()
9184
}
9285

86+
// CHECK: Test Case 'ErrorHandling.test_canButDoesNotThrowErrorFromTestMethod' started.
87+
// CHECK: Test Case 'ErrorHandling.test_canButDoesNotThrowErrorFromTestMethod' passed \(\d+\.\d+ seconds\).
9388
func test_canButDoesNotThrowErrorFromTestMethod() throws {
9489
try functionThatDoesNotThrowError()
9590
}
@@ -98,9 +93,15 @@ class ErrorHandling: XCTestCase {
9893
throw SomeError.AnError("did not actually return")
9994
}
10095

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\).
10199
func test_assertionExpressionCanThrow() {
102100
XCTAssertEqual(try functionThatShouldReturnButThrows(), 1)
103101
}
104102
}
105103

106104
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
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
// RUN: %{swiftc} %s -o %{built_tests_dir}/FailingTestSuite
22
// RUN: %{built_tests_dir}/FailingTestSuite > %t || true
33
// RUN: %{xctest_checker} %t %s
4-
// CHECK: Test Case 'PassingTestCase.test_passes' started.
5-
// CHECK: Test Case 'PassingTestCase.test_passes' passed \(\d+\.\d+ seconds\).
6-
// CHECK: Executed 1 test, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
7-
// CHECK: Test Case 'FailingTestCase.test_passes' started.
8-
// CHECK: Test Case 'FailingTestCase.test_passes' passed \(\d+\.\d+ seconds\).
9-
// CHECK: Test Case 'FailingTestCase.test_fails' started.
10-
// CHECK: .*/Tests/Functional/FailingTestSuite/main.swift:50: error: FailingTestCase.test_fails : XCTAssertTrue failed - $
11-
// CHECK: Test Case 'FailingTestCase.test_fails' failed \(\d+\.\d+ seconds\).
12-
// CHECK: Test Case 'FailingTestCase.test_fails_with_message' started.
13-
// CHECK: .*/Tests/Functional/FailingTestSuite/main.swift:54: error: FailingTestCase.test_fails_with_message : XCTAssertTrue failed - Foo bar.
14-
// CHECK: Test Case 'FailingTestCase.test_fails_with_message' failed \(\d+\.\d+ seconds\).
15-
// CHECK: Executed 3 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
16-
// CHECK: Total executed 4 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
174

185
#if os(Linux) || os(FreeBSD)
196
import XCTest
@@ -28,10 +15,14 @@ class PassingTestCase: XCTestCase {
2815
]
2916
}
3017

18+
// CHECK: Test Case 'PassingTestCase.test_passes' started.
19+
// CHECK: Test Case 'PassingTestCase.test_passes' passed \(\d+\.\d+ seconds\).
3120
func test_passes() {
3221
XCTAssert(true)
3322
}
3423
}
24+
// CHECK: Executed 1 test, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
25+
3526

3627
class FailingTestCase: XCTestCase {
3728
static var allTests: [(String, FailingTestCase -> () throws -> Void)] {
@@ -42,20 +33,32 @@ class FailingTestCase: XCTestCase {
4233
]
4334
}
4435

36+
// CHECK: Test Case 'FailingTestCase.test_passes' started.
37+
// CHECK: Test Case 'FailingTestCase.test_passes' passed \(\d+\.\d+ seconds\).
4538
func test_passes() {
4639
XCTAssert(true)
4740
}
4841

42+
// CHECK: Test Case 'FailingTestCase.test_fails' started.
43+
// CHECK: .*/FailingTestSuite/main.swift:\d+: error: FailingTestCase.test_fails : XCTAssertTrue failed - $
44+
// CHECK: Test Case 'FailingTestCase.test_fails' failed \(\d+\.\d+ seconds\).
4945
func test_fails() {
5046
XCTAssert(false)
5147
}
5248

49+
// CHECK: Test Case 'FailingTestCase.test_fails_with_message' started.
50+
// CHECK: .*/FailingTestSuite/main.swift:\d+: error: FailingTestCase.test_fails_with_message : XCTAssertTrue failed - Foo bar.
51+
// CHECK: Test Case 'FailingTestCase.test_fails_with_message' failed \(\d+\.\d+ seconds\).
5352
func test_fails_with_message() {
5453
XCTAssert(false, "Foo bar.")
5554
}
5655
}
56+
// CHECK: Executed 3 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
57+
5758

5859
XCTMain([
5960
testCase(PassingTestCase.allTests),
6061
testCase(FailingTestCase.allTests),
6162
])
63+
64+
// CHECK: Total executed 4 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds

0 commit comments

Comments
 (0)