Skip to content

Add experimental AdvancedConsoleOutputRecorder skeleton framework #1253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
8831664
feat: Add advanced hierarchical console output recorder for Swift Tes…
tienquocbui Jul 7, 2025
1786cbf
Merge remote-tracking branch 'upstream/main'
tienquocbui Jul 7, 2025
b067a9a
Merge branch 'swiftlang:main' into main
tienquocbui Jul 8, 2025
73a60ae
Add advanced console output recorder with progress bar and hierarchic…
tienquocbui Jul 11, 2025
87425d9
Merge branch 'swiftlang:main' into feature/advanced-console-output-re…
tienquocbui Jul 24, 2025
bea236d
Implementing progress bar with live update
tienquocbui Jul 24, 2025
fd9a811
Merge pull request #1 from tienquocbui/kelvin/new-console-output
tienquocbui Jul 24, 2025
042438f
Fix: Signal Handling System and Live Failure Reporting
tienquocbui Jul 24, 2025
699459c
Add skeleton AdvancedConsoleOutputRecorder framework
tienquocbui Aug 1, 2025
6a1c6db
Merge main branch with latest upstream changes
tienquocbui Aug 1, 2025
f6c46fa
Fix trailing newline in AdvancedConsoleOutputRecorder
tienquocbui Aug 1, 2025
ef8252b
Align experimental integration with upstream patterns
tienquocbui Aug 1, 2025
c82be0b
Add experimental AdvancedConsoleOutputRecorder skeleton
tienquocbui Aug 6, 2025
7eb599a
Merge upstream/main into gsoc-development
tienquocbui Aug 6, 2025
16e581a
Fix Environment.flag optional unwrapping in EntryPoint.swift
tienquocbui Aug 8, 2025
3c80e1b
Fix skeleton implementation based on code review feedback
tienquocbui Aug 13, 2025
0a496ac
Remove LiveUpdatingLine.swift and its CMakeLists.txt reference
tienquocbui Aug 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions Sources/Testing/ABI/EntryPoints/EntryPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,29 @@ func entryPoint(passing args: __CommandLineArguments_v0?, eventHandler: Event.Ha
#if !SWT_NO_FILE_IO
// Configure the event recorder to write events to stderr.
if configuration.verbosity > .min {
let eventRecorder = Event.ConsoleOutputRecorder(options: .for(.stderr)) { string in
try? FileHandle.stderr.write(string)
}
configuration.eventHandler = { [oldEventHandler = configuration.eventHandler] event, context in
eventRecorder.record(event, in: context)
oldEventHandler(event, context)
// Check for experimental console output flag
if Environment.flag(named: "SWT_ENABLE_EXPERIMENTAL_CONSOLE_OUTPUT") == true {
// Use experimental AdvancedConsoleOutputRecorder
var advancedOptions = Event.AdvancedConsoleOutputRecorder.Options()
advancedOptions.base = .for(.stderr)

let eventRecorder = Event.AdvancedConsoleOutputRecorder(options: advancedOptions) { string in
try? FileHandle.stderr.write(string)
}

configuration.eventHandler = { [oldEventHandler = configuration.eventHandler] event, context in
eventRecorder.handle(event, in: context)
oldEventHandler(event, context)
}
} else {
// Use the standard console output recorder (default behavior)
let eventRecorder = Event.ConsoleOutputRecorder(options: .for(.stderr)) { string in
try? FileHandle.stderr.write(string)
}
configuration.eventHandler = { [oldEventHandler = configuration.eventHandler] event, context in
eventRecorder.record(event, in: context)
oldEventHandler(event, context)
}
}
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions Sources/Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ add_library(Testing
Attachments/Attachment.swift
Events/Clock.swift
Events/Event.swift
Events/Recorder/Event.AdvancedConsoleOutputRecorder.swift
Events/Recorder/Event.ConsoleOutputRecorder.swift
Events/Recorder/Event.HumanReadableOutputRecorder.swift
Events/Recorder/Event.JUnitXMLRecorder.swift
Expand Down Expand Up @@ -82,6 +83,7 @@ add_library(Testing
Support/GetSymbol.swift
Support/Graph.swift
Support/JSON.swift
Support/LiveUpdatingLine.swift
Support/Locked.swift
Support/Locked+Platform.swift
Support/Versions.swift
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
//

extension Event {
/// An experimental console output recorder that provides enhanced test result
/// display capabilities.
///
/// This recorder is currently experimental and must be enabled via the
/// `SWT_ENABLE_EXPERIMENTAL_CONSOLE_OUTPUT` environment variable.
///
/// Future capabilities will include:
/// - Hierarchical test result display with tree visualization
/// - Live progress indicators during test execution
/// - Enhanced SF Symbols integration on supported platforms
struct AdvancedConsoleOutputRecorder: Sendable {
/// Configuration options for the advanced console output recorder.
struct Options: Sendable {
/// Base console output recorder options to inherit from.
var base: Event.ConsoleOutputRecorder.Options

/// Whether to enable experimental hierarchical output display.
/// Currently unused - reserved for future PR #2.
var useHierarchicalOutput: Bool

/// Whether to show successful tests in the output.
/// Currently unused - reserved for future PR #2.
var showSuccessfulTests: Bool

init() {
self.base = Event.ConsoleOutputRecorder.Options()
self.useHierarchicalOutput = true
self.showSuccessfulTests = true
}
}

/// The options for this recorder.
let options: Options

/// The write function for this recorder.
let write: @Sendable (String) -> Void

/// The fallback console recorder for standard output.
private let _fallbackRecorder: Event.ConsoleOutputRecorder

/// Initialize the advanced console output recorder.
///
/// - Parameters:
/// - options: Configuration options for the recorder.
/// - write: A closure that writes output to its destination.
init(options: Options = Options(), writingUsing write: @escaping @Sendable (String) -> Void) {
self.options = options
self.write = write
self._fallbackRecorder = Event.ConsoleOutputRecorder(options: options.base, writingUsing: write)
}
}
}

extension Event.AdvancedConsoleOutputRecorder {
/// Handle an event by processing it and generating appropriate output.
///
/// Currently this is a skeleton implementation that delegates to the
/// standard ConsoleOutputRecorder.
///
/// - Parameters:
/// - event: The event to handle.
/// - eventContext: The context associated with the event.
func handle(_ event: borrowing Event, in eventContext: borrowing Event.Context) {
// Skeleton implementation: delegate to standard recorder
// Future PRs will add enhanced functionality here
_fallbackRecorder.record(event, in: eventContext)
}
}
31 changes: 31 additions & 0 deletions Sources/Testing/Support/LiveUpdatingLine.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
//

/// Prints a string to the console by overwriting the current line without creating a new line.
/// This is ideal for creating single-line, live-updating progress bars or status indicators.
///
/// - Parameter text: The text to display on the current line
///
/// ## Technical Details
/// - Uses carriage return (`\r`) to move cursor to beginning of current line
/// - Uses ANSI escape code (`\u{001B}[2K`) to clear the entire line
/// - Does not append a newline character, allowing the line to be overwritten again
///
/// ## Example Usage
/// ```swift
/// printLiveUpdatingLine("Processing... 25%")
/// // Later...
/// printLiveUpdatingLine("Processing... 50%")
/// // Later...
/// printLiveUpdatingLine("Processing... 100%")
/// ```
public func printLiveUpdatingLine(_ text: String) {
print("\r\u{001B}[2K\(text)", terminator: "")
}