Skip to content

Commit a3ddbc0

Browse files
committed
Add labels and move failure summary to end of output
1 parent dd6105b commit a3ddbc0

3 files changed

Lines changed: 101 additions & 12 deletions

File tree

Sources/Testing/Events/Recorder/Event.ConsoleOutputRecorder.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,6 @@ extension Event.ConsoleOutputRecorder {
306306
/// destination.
307307
@discardableResult public func record(_ event: borrowing Event, in context: borrowing Event.Context) -> Bool {
308308
let messages = _humanReadableOutputRecorder.record(event, in: context)
309-
310-
// Print failure summary when run ends, unless an environment variable is
311-
// set to explicitly disable it.
312-
if case .runEnded = event.kind, Environment.flag(named: "SWT_FAILURE_SUMMARY_ENABLED") != false {
313-
if let summary = _humanReadableOutputRecorder.generateFailureSummary(options: options) {
314-
// Add blank line before summary and after summary for visual separation
315-
write("\n\(summary)\n")
316-
}
317-
}
318309

319310
// Padding to use in place of a symbol for messages that don't have one.
320311
var padding = " "
@@ -349,6 +340,17 @@ extension Event.ConsoleOutputRecorder {
349340
}
350341

351342
write(lines.joined())
343+
344+
// Print failure summary when run ends, unless an environment variable is
345+
// set to explicitly disable it. The summary is printed after the main
346+
// output so it appears at the very end of the console output.
347+
if case .runEnded = event.kind, Environment.flag(named: "SWT_FAILURE_SUMMARY_ENABLED") != false {
348+
if let summary = _humanReadableOutputRecorder.generateFailureSummary(options: options) {
349+
// Add blank line before summary for visual separation
350+
write("\n\(summary)")
351+
}
352+
}
353+
352354
return !messages.isEmpty
353355
}
354356

Sources/Testing/Events/Recorder/Event.HumanReadableOutputRecorder.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,15 @@ extension Event {
197197
// Build fully qualified name
198198
let fullyQualifiedName = fullyQualifiedName(for: failedTest)
199199

200-
result += "\(symbol) \(fullyQualifiedName)\n"
200+
result += "\(symbol) Test \(fullyQualifiedName)\n"
201201

202202
// For parameterized tests: show test cases grouped under the parent test
203203
if !failedTest.testCases.isEmpty {
204204
for testCase in failedTest.testCases {
205-
// Show test case arguments with additional indentation
206-
result += " (\(testCase.arguments))\n"
205+
// Show test case with argument count phrase and arguments
206+
let argumentCount = testCase.arguments.split(separator: ",").count
207+
let argumentPhrase = argumentCount.counting("argument")
208+
result += " Test case with \(argumentPhrase): (\(testCase.arguments))\n"
207209
// List each issue for this test case with additional indentation
208210
for issue in testCase.issues {
209211
result += formatIssue(issue, indentLevel: 2)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Tests/TestingTests/FailureSummaryDemoTests.swift
2+
// Demo tests to showcase the failure summary feature
3+
4+
import Testing
5+
6+
/// Demo tests showcasing the refactored failure summary feature.
7+
@Suite("Failure Summary Demo")
8+
struct FailureSummaryDemoTests {
9+
10+
// MARK: - Math Operations
11+
@Suite("Math Operations")
12+
struct MathTests {
13+
@Test("Addition works correctly")
14+
func addition() {
15+
let result = 2 + 2
16+
#expect(result == 4)
17+
}
18+
19+
@Test("Division fails")
20+
func division() {
21+
let result = 10 / 3
22+
#expect(result == 4) // This will fail (result is 3)
23+
}
24+
}
25+
26+
// MARK: - String Operations
27+
@Suite("String Operations")
28+
struct StringTests {
29+
@Test("String concatenation fails")
30+
func stringConcat() {
31+
let greeting = "Hello"
32+
let name = "World"
33+
#expect(greeting + name == "Hello World") // Missing space
34+
}
35+
36+
@Test("String comparison passes")
37+
func stringComparison() {
38+
#expect("swift" == "swift")
39+
}
40+
41+
@Test("Multiple string failures")
42+
func multipleFailures() {
43+
#expect("a" == "b")
44+
#expect("hello".count == 10)
45+
#expect("swift".uppercased() == "swift")
46+
}
47+
}
48+
49+
// MARK: - Array Operations
50+
@Suite("Array Operations")
51+
struct ArrayTests {
52+
@Test("Array equality")
53+
func arrayEquality() {
54+
let numbers = [1, 2, 3]
55+
#expect(numbers == [1, 2, 3])
56+
}
57+
58+
@Test("Array contains element")
59+
func arrayContains() {
60+
let numbers = [1, 2, 3, 4, 5]
61+
#expect(numbers.contains(10)) // Will fail
62+
}
63+
}
64+
65+
// MARK: - Parameterized Tests
66+
@Suite("Parameterized Tests")
67+
struct ParameterizedTests {
68+
@Test("Check even numbers", arguments: [2, 4, 6, 7, 10])
69+
func testEvenNumbers(value: Int) {
70+
#expect(value % 2 == 0) // 7 will fail
71+
}
72+
73+
@Test("String length validation", arguments: ["hello", "world", "a", "swift"])
74+
func testStringLength(text: String) {
75+
#expect(text.count >= 5) // "a" will fail
76+
}
77+
78+
@Test("This is a custom display name")
79+
func testWithDisplayName() {
80+
let value = 42
81+
#expect(value == 100) // Will fail
82+
}
83+
}
84+
}
85+

0 commit comments

Comments
 (0)