diff --git a/Sources/Testing/Events/Recorder/Event.ConsoleOutputRecorder.swift b/Sources/Testing/Events/Recorder/Event.ConsoleOutputRecorder.swift index ea48e7ad1..80e68c609 100644 --- a/Sources/Testing/Events/Recorder/Event.ConsoleOutputRecorder.swift +++ b/Sources/Testing/Events/Recorder/Event.ConsoleOutputRecorder.swift @@ -323,7 +323,7 @@ extension Event.ConsoleOutputRecorder { // text instead of just the symbol. Details may be multi-line messages, // so split the message on newlines and indent all lines to align them // to the indentation provided by the symbol. - var lines = message.stringValue.split(whereSeparator: \.isNewline) + var lines = message.stringValue.split(omittingEmptySubsequences: false, whereSeparator: \.isNewline) lines = CollectionOfOne(lines[0]) + lines.dropFirst().map { line in "\(padding) \(line)" } diff --git a/Tests/TestingTests/EventRecorderTests.swift b/Tests/TestingTests/EventRecorderTests.swift index 8ac7f6728..690fd416f 100644 --- a/Tests/TestingTests/EventRecorderTests.swift +++ b/Tests/TestingTests/EventRecorderTests.swift @@ -257,6 +257,30 @@ struct EventRecorderTests { } #endif + @Test( + "Uncommonly-formatted comments", + .bug("rdar://149482060"), + arguments: [ + "", // Empty string + "\n\n\n", // Only newlines + "\nFoo\n\nBar\n\n\nBaz\n", // Newlines interspersed with non-empty strings + ] + ) + func uncommonComments(text: String) async throws { + let stream = Stream() + + var configuration = Configuration() + configuration.eventHandlingOptions.isWarningIssueRecordedEventEnabled = true + let eventRecorder = Event.ConsoleOutputRecorder(writingUsing: stream.write) + configuration.eventHandler = { event, context in + eventRecorder.record(event, in: context) + } + + await Test { + Issue.record(Comment(rawValue: text) /* empty */) + }.run(configuration: configuration) + } + @available(_regexAPI, *) @Test("Issue counts are omitted on a successful test") func issueCountOmittedForPassingTest() async throws {