Skip to content

Commit 4944003

Browse files
committed
[XCTestCase] Output "test passed"
Fix a regression introduced in #33 that causes the "test passed" message to never be output. Add a test to prevent future regressions.
1 parent 0a33c52 commit 4944003

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-3
lines changed

Sources/XCTest/XCTestCase.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,20 @@ extension XCTestCase {
5555
tearDown()
5656

5757
totalDuration += duration
58+
59+
var result = "passed"
5860
for failure in failures {
5961
failure.emit(method)
6062
totalFailures += 1
6163
if !failure.expected {
6264
unexpectedFailures += 1
6365
}
6466

65-
let result = failures.count > 0 ? "failed" : "passed"
66-
67-
print("Test Case '\(method)' \(result) (\(printableStringForTimeInterval(duration)) seconds).")
67+
result = failures.count > 0 ? "failed" : "passed"
6868
XCTAllRuns.append(XCTRun(duration: duration, method: method, passed: failures.count == 0, failures: failures))
6969
}
70+
71+
print("Test Case '\(method)' \(result) (\(printableStringForTimeInterval(duration)) seconds).")
7072
XCTFailureHandler = nil
7173
}
7274
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// RUN: %{swiftc} %s -o %{built_tests_dir}/FailingTestSuite
2+
// RUN: %{built_tests_dir}/FailingTestSuite > %t || true
3+
// 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 2 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
17+
18+
#if os(Linux) || os(FreeBSD)
19+
import XCTest
20+
#else
21+
import SwiftXCTest
22+
#endif
23+
24+
class PassingTestCase: XCTestCase {
25+
var allTests: [(String, () -> ())] {
26+
return [
27+
("test_passes", test_passes),
28+
]
29+
}
30+
31+
func test_passes() {
32+
XCTAssert(true)
33+
}
34+
}
35+
36+
class FailingTestCase: XCTestCase {
37+
var allTests: [(String, () -> ())] {
38+
return [
39+
("test_passes", test_passes),
40+
("test_fails", test_fails),
41+
("test_fails_with_message", test_fails_with_message),
42+
]
43+
}
44+
45+
func test_passes() {
46+
XCTAssert(true)
47+
}
48+
49+
func test_fails() {
50+
XCTAssert(false)
51+
}
52+
53+
func test_fails_with_message() {
54+
XCTAssert(false, "Foo bar.")
55+
}
56+
}
57+
58+
XCTMain([
59+
PassingTestCase(),
60+
FailingTestCase(),
61+
])

XCTest.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
DA78F7F61C4039410082E15B /* compare.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = compare.py; sourceTree = "<group>"; };
4545
DA78F7F81C4039410082E15B /* main.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = main.py; sourceTree = "<group>"; };
4646
DA78F7FA1C4039410082E15B /* xctest_checker.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = xctest_checker.py; sourceTree = "<group>"; };
47+
DADB975E1C44BE8B005E68B6 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
4748
EA3E74BB1BF2B6D500635A73 /* build_script.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = build_script.py; sourceTree = "<group>"; };
4849
/* End PBXFileReference section */
4950

@@ -122,6 +123,7 @@
122123
children = (
123124
DA78F7E91C4039410082E15B /* lit.cfg */,
124125
DA78F7EA1C4039410082E15B /* SingleFailingTestCase */,
126+
DADB975D1C44BE73005E68B6 /* FailingTestSuite */,
125127
DA78F7ED1C4039410082E15B /* xctest_checker */,
126128
);
127129
path = Functional;
@@ -166,6 +168,14 @@
166168
path = xctest_checker;
167169
sourceTree = "<group>";
168170
};
171+
DADB975D1C44BE73005E68B6 /* FailingTestSuite */ = {
172+
isa = PBXGroup;
173+
children = (
174+
DADB975E1C44BE8B005E68B6 /* main.swift */,
175+
);
176+
path = FailingTestSuite;
177+
sourceTree = "<group>";
178+
};
169179
EA3E74BC1BF2B6D700635A73 /* Linux Build */ = {
170180
isa = PBXGroup;
171181
children = (

0 commit comments

Comments
 (0)