Skip to content

Commit 17c00b0

Browse files
authored
Include total number of suites in "run ended" console message (#1116)
This enhances the console output message shown when a test run finishes by including the total number of suites which ran or skipped, after the total number of test functions. Example: ``` ✔ Test run with 456 tests in 62 suites passed after 3.389 seconds. ``` The data was already being collected to support this, in a property named `suiteCount`, but it was not being used anywhere. So this PR adopts that property to augment the current "test run ended" message. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 464c01a commit 17c00b0

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ extension Event.HumanReadableOutputRecorder {
542542

543543
case .runEnded:
544544
let testCount = context.testCount
545+
let suiteCount = context.suiteCount
545546
let issues = _issueCounts(in: context.testData)
546547
let runStartInstant = context.runStartInstant ?? instant
547548
let duration = runStartInstant.descriptionOfDuration(to: instant)
@@ -550,14 +551,14 @@ extension Event.HumanReadableOutputRecorder {
550551
[
551552
Message(
552553
symbol: .fail,
553-
stringValue: "Test run with \(testCount.counting("test")) failed after \(duration)\(issues.description)."
554+
stringValue: "Test run with \(testCount.counting("test")) in \(suiteCount.counting("suite")) failed after \(duration)\(issues.description)."
554555
)
555556
]
556557
} else {
557558
[
558559
Message(
559560
symbol: .pass(knownIssueCount: issues.knownIssueCount),
560-
stringValue: "Test run with \(testCount.counting("test")) passed after \(duration)\(issues.description)."
561+
stringValue: "Test run with \(testCount.counting("test")) in \(suiteCount.counting("suite")) passed after \(duration)\(issues.description)."
561562
)
562563
]
563564
}

Tests/TestingTests/EventRecorderTests.swift

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,20 +322,29 @@ struct EventRecorderTests {
322322
print(buffer, terminator: "")
323323
}
324324

325+
let testCount = Reference<Int?>()
326+
let suiteCount = Reference<Int?>()
327+
let issueCount = Reference<Int?>()
328+
let knownIssueCount = Reference<Int?>()
329+
325330
let runFailureRegex = Regex {
326331
One(.anyGraphemeCluster)
327332
" Test run with "
328-
OneOrMore(.digit)
333+
Capture(as: testCount) { OneOrMore(.digit) } transform: { Int($0) }
329334
" test"
330335
Optionally("s")
336+
" in "
337+
Capture(as: suiteCount) { OneOrMore(.digit) } transform: { Int($0) }
338+
" suite"
339+
Optionally("s")
331340
" failed "
332341
ZeroOrMore(.any)
333342
" with "
334-
Capture { OneOrMore(.digit) } transform: { Int($0) }
343+
Capture(as: issueCount) { OneOrMore(.digit) } transform: { Int($0) }
335344
" issue"
336345
Optionally("s")
337346
" (including "
338-
Capture { OneOrMore(.digit) } transform: { Int($0) }
347+
Capture(as: knownIssueCount) { OneOrMore(.digit) } transform: { Int($0) }
339348
" known issue"
340349
Optionally("s")
341350
")."
@@ -346,8 +355,10 @@ struct EventRecorderTests {
346355
.compactMap(runFailureRegex.wholeMatch(in:))
347356
.first
348357
)
349-
#expect(match.output.1 == 12)
350-
#expect(match.output.2 == 5)
358+
#expect(match[testCount] == 9)
359+
#expect(match[suiteCount] == 2)
360+
#expect(match[issueCount] == 12)
361+
#expect(match[knownIssueCount] == 5)
351362
}
352363

353364
@Test("Issue counts are summed correctly on run end for a test with only warning issues")
@@ -369,16 +380,24 @@ struct EventRecorderTests {
369380
print(buffer, terminator: "")
370381
}
371382

383+
let testCount = Reference<Int?>()
384+
let suiteCount = Reference<Int?>()
385+
let warningCount = Reference<Int?>()
386+
372387
let runFailureRegex = Regex {
373388
One(.anyGraphemeCluster)
374389
" Test run with "
375-
OneOrMore(.digit)
390+
Capture(as: testCount) { OneOrMore(.digit) } transform: { Int($0) }
376391
" test"
377392
Optionally("s")
393+
" in "
394+
Capture(as: suiteCount) { OneOrMore(.digit) } transform: { Int($0) }
395+
" suite"
396+
Optionally("s")
378397
" passed "
379398
ZeroOrMore(.any)
380399
" with "
381-
Capture { OneOrMore(.digit) } transform: { Int($0) }
400+
Capture(as: warningCount) { OneOrMore(.digit) } transform: { Int($0) }
382401
" warning"
383402
Optionally("s")
384403
"."
@@ -390,7 +409,9 @@ struct EventRecorderTests {
390409
.first,
391410
"buffer: \(buffer)"
392411
)
393-
#expect(match.output.1 == 1)
412+
#expect(match[testCount] == 1)
413+
#expect(match[suiteCount] == 1)
414+
#expect(match[warningCount] == 1)
394415
}
395416
#endif
396417

@@ -691,6 +712,8 @@ struct EventRecorderTests {
691712
func n(_ arg: Int) {
692713
#expect(arg > 0)
693714
}
715+
716+
@Suite struct PredictableSubsuite {}
694717
}
695718

696719
@Suite(.hidden) struct PredictablyFailingKnownIssueTests {

0 commit comments

Comments
 (0)