Skip to content

Commit ba2f7e3

Browse files
committed
Simplify issue count tracking with a dictionary
1 parent 21e1852 commit ba2f7e3

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,9 @@ extension Event {
5656
/// The instant at which the test started.
5757
var startInstant: Test.Clock.Instant
5858

59-
/// The number of issues with error severity recorded for the test.
60-
var errorIssueCount = 0
61-
62-
/// The number of issues with warning severity recorded for the test.
63-
var warningIssueCount = 0
59+
/// The number of issues recorded for the test, grouped by their
60+
/// level of severity.
61+
var issueCount: [Issue.Severity: Int] = [:]
6462

6563
/// The number of known issues recorded for the test.
6664
var knownIssueCount = 0
@@ -121,8 +119,8 @@ extension Event.HumanReadableOutputRecorder {
121119
guard let graph else {
122120
return (0, 0, 0, 0, "")
123121
}
124-
let errorIssueCount = graph.compactMap(\.value?.errorIssueCount).reduce(into: 0, +=)
125-
let warningIssueCount = graph.compactMap(\.value?.warningIssueCount).reduce(into: 0, +=)
122+
let errorIssueCount = graph.compactMap { $0.value?.issueCount[.error] }.reduce(into: 0, +=)
123+
let warningIssueCount = graph.compactMap { $0.value?.issueCount[.warning] }.reduce(into: 0, +=)
126124
let knownIssueCount = graph.compactMap(\.value?.knownIssueCount).reduce(into: 0, +=)
127125
let totalIssueCount = errorIssueCount + warningIssueCount + knownIssueCount
128126

@@ -279,12 +277,7 @@ extension Event.HumanReadableOutputRecorder {
279277
if issue.isKnown {
280278
testData.knownIssueCount += 1
281279
} else {
282-
switch issue.severity {
283-
case .warning:
284-
testData.warningIssueCount += 1
285-
case .error:
286-
testData.errorIssueCount += 1
287-
}
280+
testData.issueCount[issue.severity, default: 0] += 1
288281
}
289282
context.testData[id] = testData
290283

0 commit comments

Comments
 (0)