|
| 1 | +// |
| 2 | +// This source file is part of the Swift.org open source project |
| 3 | +// |
| 4 | +// Copyright (c) 2025 Apple Inc. and the Swift project authors |
| 5 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 6 | +// |
| 7 | +// See https://swift.org/LICENSE.txt for license information |
| 8 | +// See https://swift.org/CONTRIBUTORS.txt for Swift project authors |
| 9 | +// |
| 10 | + |
| 11 | +extension Event { |
| 12 | + /// An experimental console output recorder that provides enhanced test result |
| 13 | + /// display capabilities. |
| 14 | + /// |
| 15 | + /// This recorder is currently experimental and must be enabled via the |
| 16 | + /// `SWT_ENABLE_EXPERIMENTAL_CONSOLE_OUTPUT` environment variable. |
| 17 | + struct AdvancedConsoleOutputRecorder: Sendable { |
| 18 | + /// Configuration options for the advanced console output recorder. |
| 19 | + struct Options: Sendable { |
| 20 | + /// Base console output recorder options to inherit from. |
| 21 | + var base: Event.ConsoleOutputRecorder.Options |
| 22 | + |
| 23 | + init() { |
| 24 | + self.base = Event.ConsoleOutputRecorder.Options() |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + /// The options for this recorder. |
| 29 | + let options: Options |
| 30 | + |
| 31 | + /// The write function for this recorder. |
| 32 | + let write: @Sendable (String) -> Void |
| 33 | + |
| 34 | + /// The fallback console recorder for standard output. |
| 35 | + private let _fallbackRecorder: Event.ConsoleOutputRecorder |
| 36 | + |
| 37 | + /// Initialize the advanced console output recorder. |
| 38 | + /// |
| 39 | + /// - Parameters: |
| 40 | + /// - options: Configuration options for the recorder. |
| 41 | + /// - write: A closure that writes output to its destination. |
| 42 | + init(options: Options = Options(), writingUsing write: @escaping @Sendable (String) -> Void) { |
| 43 | + self.options = options |
| 44 | + self.write = write |
| 45 | + self._fallbackRecorder = Event.ConsoleOutputRecorder(options: options.base, writingUsing: write) |
| 46 | + } |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +extension Event.AdvancedConsoleOutputRecorder { |
| 51 | + /// Record an event by processing it and generating appropriate output. |
| 52 | + /// |
| 53 | + /// Currently this is a skeleton implementation that delegates to |
| 54 | + /// ``Event/ConsoleOutputRecorder``. |
| 55 | + /// |
| 56 | + /// - Parameters: |
| 57 | + /// - event: The event to record. |
| 58 | + /// - eventContext: The context associated with the event. |
| 59 | + func record(_ event: borrowing Event, in eventContext: borrowing Event.Context) { |
| 60 | + // Skeleton implementation: delegate to ConsoleOutputRecorder |
| 61 | + _fallbackRecorder.record(event, in: eventContext) |
| 62 | + } |
| 63 | +} |
0 commit comments