17 lines
626 B
Swift
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)) }
|
|
}
|
|
}
|