Skip to content

JUnit XML recorder should ignore warning issues #986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ extension Event.JUnitXMLRecorder {
}
return nil
case let .issueRecorded(issue):
if issue.isKnown {
if issue.isKnown || issue.severity < .error {
return nil
}
if let id = test?.id {
Expand Down
30 changes: 25 additions & 5 deletions Tests/TestingTests/EventRecorderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,35 @@ struct EventRecorderTests {
@Test("JUnitXMLRecorder counts issues without associated tests")
func junitRecorderCountsIssuesWithoutTests() async throws {
let issue = Issue(kind: .unconditional)
let event = Event(.issueRecorded(issue), testID: nil, testCaseID: nil)
let context = Event.Context(test: nil, testCase: nil, configuration: nil)

let recorder = Event.JUnitXMLRecorder { string in
if string.contains("<testsuite") {
#expect(string.contains(#"failures=1"#))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a drive-by fix to the pre-existing test above the new one I added below: This one wasn't actually working, since no .runEnded event was recorded, so this callback wasn't happening. Once I fixed that I noticed a secondary issue, which is that the "failures=1" string was missing double quotes around the number 1.

await confirmation { wroteTestSuite in
let recorder = Event.JUnitXMLRecorder { string in
if string.contains("<testsuite ") {
#expect(string.contains(#"failures="1""#))
wroteTestSuite()
}
}
recorder.record(Event(.issueRecorded(issue), testID: nil, testCaseID: nil), in: context)
recorder.record(Event(.runEnded, testID: nil, testCaseID: nil), in: context)
}
}

@Test("JUnitXMLRecorder ignores warning issues")
func junitRecorderIgnoresWarningIssues() async throws {
let issue = Issue(kind: .unconditional, severity: .warning)
let context = Event.Context(test: nil, testCase: nil, configuration: nil)

await confirmation { wroteTestSuite in
let recorder = Event.JUnitXMLRecorder { string in
if string.contains("<testsuite ") {
#expect(string.contains(#"failures="0""#))
wroteTestSuite()
}
}
recorder.record(Event(.issueRecorded(issue), testID: nil, testCaseID: nil), in: context)
recorder.record(Event(.runEnded, testID: nil, testCaseID: nil), in: context)
}
_ = recorder.record(event, in: context)
}
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/TestingTests/TestSupport/TestingAdditions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
//

@testable @_spi(ForToolsIntegrationOnly) import Testing
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
#if canImport(XCTest)
import XCTest
#endif
Expand Down Expand Up @@ -368,8 +368,8 @@ extension Trait where Self == TimeLimitTrait {
}

extension Issue {
init(kind: Kind, sourceContext: SourceContext = .init()) {
self.init(kind: kind, comments: [], sourceContext: sourceContext)
init(kind: Kind, severity: Severity = .error, sourceContext: SourceContext = .init()) {
self.init(kind: kind, severity: severity, comments: [], sourceContext: sourceContext)
}
}

Expand Down