Files
helder/Tests/HelderServicesTests/Support/LineLog.swift
T
2026-10-30 13:21:45 +01:00

17 lines
626 B
Swift

import Foundation
/// Collects streamed output lines from any thread, for tests of `stream` and `execute`.
final class LineLog: @unchecked Sendable {
private let lock = NSLock()
private var recorded: [(text: String, isError: Bool)] = []
var lines: [(text: String, isError: Bool)] { lock.withLock { recorded } }
var texts: [String] { lines.map(\.text) }
var errors: [String] { lines.filter(\.isError).map(\.text) }
var outputs: [String] { lines.filter { !$0.isError }.map(\.text) }
func append(_ text: String, _ isError: Bool) {
lock.withLock { recorded.append((text, isError)) }
}
}