Skip to content

Commit 696d9b9

Browse files
authored
Fix crash in ConsoleOutputRecorder when an issue has a comment with an empty string (#1091)
This fixes a crash which can occur when recording an issue with a comment whose string is empty. It also adds some test coverage of this scenario and other "uncommon" comment examples. ### 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. Fixes rdar://149482060
1 parent 534d781 commit 696d9b9

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ extension Event.ConsoleOutputRecorder {
323323
// text instead of just the symbol. Details may be multi-line messages,
324324
// so split the message on newlines and indent all lines to align them
325325
// to the indentation provided by the symbol.
326-
var lines = message.stringValue.split(whereSeparator: \.isNewline)
326+
var lines = message.stringValue.split(omittingEmptySubsequences: false, whereSeparator: \.isNewline)
327327
lines = CollectionOfOne(lines[0]) + lines.dropFirst().map { line in
328328
"\(padding) \(line)"
329329
}

Tests/TestingTests/EventRecorderTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,30 @@ struct EventRecorderTests {
257257
}
258258
#endif
259259

260+
@Test(
261+
"Uncommonly-formatted comments",
262+
.bug("rdar://149482060"),
263+
arguments: [
264+
"", // Empty string
265+
"\n\n\n", // Only newlines
266+
"\nFoo\n\nBar\n\n\nBaz\n", // Newlines interspersed with non-empty strings
267+
]
268+
)
269+
func uncommonComments(text: String) async throws {
270+
let stream = Stream()
271+
272+
var configuration = Configuration()
273+
configuration.eventHandlingOptions.isWarningIssueRecordedEventEnabled = true
274+
let eventRecorder = Event.ConsoleOutputRecorder(writingUsing: stream.write)
275+
configuration.eventHandler = { event, context in
276+
eventRecorder.record(event, in: context)
277+
}
278+
279+
await Test {
280+
Issue.record(Comment(rawValue: text) /* empty */)
281+
}.run(configuration: configuration)
282+
}
283+
260284
@available(_regexAPI, *)
261285
@Test("Issue counts are omitted on a successful test")
262286
func issueCountOmittedForPassingTest() async throws {

0 commit comments

Comments
 (0)