Skip to content

Commit dcb61b8

Browse files
committed
Ensure xUnit/JUnit XML output correctly counts test-less issues.
This PR ensures that issues that occur on detached tasks are recorded in the XML output provided by Swift Testing. I also took a moment to improve test coverage a bit for the XML recorder.
1 parent ec2bbcb commit dcb61b8

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ extension Event.JUnitXMLRecorder {
218218
">"
219219
case "&":
220220
"&"
221-
case _ where !character.isASCII:
221+
case _ where !character.isASCII || character.isNewline:
222222
character.unicodeScalars.lazy
223223
.map(\.value)
224224
.map { "&#\($0);" }

Tests/TestingTests/EventRecorderTests.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,32 @@ struct EventRecorderTests {
360360
}
361361
#endif
362362

363-
@Test("Recorded issues may not have associated tests")
364-
func issueWithoutTest() {
363+
@Test("HumanReadableOutputRecorder counts issues without associated tests")
364+
func humanReadableRecorderCountsIssuesWithoutTests() {
365365
let issue = Issue(kind: .unconditional, comments: [], sourceContext: .init())
366366
let event = Event(.issueRecorded(issue), testID: nil, testCaseID: nil)
367367
let context = Event.Context(test: nil, testCase: nil)
368368

369369
let recorder = Event.HumanReadableOutputRecorder()
370+
let messages = recorder.record(event, in: context)
371+
#expect(
372+
messages.map(\.stringValue).contains { message in
373+
message.contains("unknown")
374+
}
375+
)
376+
}
377+
378+
@Test("JUnitXMLRecorder counts issues without associated tests")
379+
func junitRecorderCountsIssuesWithoutTests() async throws {
380+
let issue = Issue(kind: .unconditional, comments: [], sourceContext: .init())
381+
let event = Event(.issueRecorded(issue), testID: nil, testCaseID: nil)
382+
let context = Event.Context(test: nil, testCase: nil)
383+
384+
let recorder = Event.JUnitXMLRecorder { string in
385+
if string.contains("<testsuite") {
386+
#expect(string.contains(#"failures=1"#))
387+
}
388+
}
370389
_ = recorder.record(event, in: context)
371390
}
372391
}
@@ -379,6 +398,7 @@ struct EventRecorderTests {
379398
await { () async in
380399
_ = Issue.record("Whales fail asynchronously.")
381400
}()
401+
Issue.record("Whales\nalso\nfall.")
382402
}
383403
@Test(.hidden) func expectantKangaroo() {
384404
#expect("abc" == "xyz")
@@ -449,6 +469,10 @@ struct EventRecorderTests {
449469
@Test(.hidden) func cornyUnicorn🦄() throws {
450470
throw MyDescriptiveError(description: #"🦄"#)
451471
}
472+
473+
@Test(.hidden) func burdgeoningBudgerigar() {
474+
Issue.record(#"</>& "Down\#nwe\#ngo!""#)
475+
}
452476
}
453477

454478
@Suite(.hidden) struct PredictablyFailingTests {

0 commit comments

Comments
 (0)