Skip to content

Commit 69a1e26

Browse files
authored
JUnit XML recorder should ignore warning issues (#986)
This updates `Event.JUnitXMLRecorder` to ignore `Issue` instances whose `severity` is less than `.error` (such as `.warning`). ### Motivation: The concept of issue severity was recently added in #931 (but was reverted and re-landed in #952), and that did not adjust the JUnit XML recorder logic. The JUnit XML schema we currently attempt to adhere to does not appear to have a way to represent non-fatal issues, so I think it would be best for now to ignore these issues. ### Modifications: - Implement the fix and a validating unit test. - (Drive-by) Fix a nearby test I noticed wasn't actually working as intended and wasn't properly validating the fix it was intended to. ### 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 0c84d57 commit 69a1e26

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ extension Event.JUnitXMLRecorder {
122122
}
123123
return nil
124124
case let .issueRecorded(issue):
125-
if issue.isKnown {
125+
if issue.isKnown || issue.severity < .error {
126126
return nil
127127
}
128128
if let id = test?.id {

Tests/TestingTests/EventRecorderTests.swift

+25-5
Original file line numberDiff line numberDiff line change
@@ -467,15 +467,35 @@ struct EventRecorderTests {
467467
@Test("JUnitXMLRecorder counts issues without associated tests")
468468
func junitRecorderCountsIssuesWithoutTests() async throws {
469469
let issue = Issue(kind: .unconditional)
470-
let event = Event(.issueRecorded(issue), testID: nil, testCaseID: nil)
471470
let context = Event.Context(test: nil, testCase: nil, configuration: nil)
472471

473-
let recorder = Event.JUnitXMLRecorder { string in
474-
if string.contains("<testsuite") {
475-
#expect(string.contains(#"failures=1"#))
472+
await confirmation { wroteTestSuite in
473+
let recorder = Event.JUnitXMLRecorder { string in
474+
if string.contains("<testsuite ") {
475+
#expect(string.contains(#"failures="1""#))
476+
wroteTestSuite()
477+
}
478+
}
479+
recorder.record(Event(.issueRecorded(issue), testID: nil, testCaseID: nil), in: context)
480+
recorder.record(Event(.runEnded, testID: nil, testCaseID: nil), in: context)
481+
}
482+
}
483+
484+
@Test("JUnitXMLRecorder ignores warning issues")
485+
func junitRecorderIgnoresWarningIssues() async throws {
486+
let issue = Issue(kind: .unconditional, severity: .warning)
487+
let context = Event.Context(test: nil, testCase: nil, configuration: nil)
488+
489+
await confirmation { wroteTestSuite in
490+
let recorder = Event.JUnitXMLRecorder { string in
491+
if string.contains("<testsuite ") {
492+
#expect(string.contains(#"failures="0""#))
493+
wroteTestSuite()
494+
}
476495
}
496+
recorder.record(Event(.issueRecorded(issue), testID: nil, testCaseID: nil), in: context)
497+
recorder.record(Event(.runEnded, testID: nil, testCaseID: nil), in: context)
477498
}
478-
_ = recorder.record(event, in: context)
479499
}
480500
}
481501

Tests/TestingTests/TestSupport/TestingAdditions.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
@testable @_spi(ForToolsIntegrationOnly) import Testing
11+
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
1212
#if canImport(XCTest)
1313
import XCTest
1414
#endif
@@ -368,8 +368,8 @@ extension Trait where Self == TimeLimitTrait {
368368
}
369369

370370
extension Issue {
371-
init(kind: Kind, sourceContext: SourceContext = .init()) {
372-
self.init(kind: kind, comments: [], sourceContext: sourceContext)
371+
init(kind: Kind, severity: Severity = .error, sourceContext: SourceContext = .init()) {
372+
self.init(kind: kind, severity: severity, comments: [], sourceContext: sourceContext)
373373
}
374374
}
375375

0 commit comments

Comments
 (0)