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

Merged
merged 17 commits into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all 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.record(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
1 change: 1 addition & 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// 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.
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

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

/// 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 {
/// Record an event by processing it and generating appropriate output.
///
/// Currently this is a skeleton implementation that delegates to
/// ``Event/ConsoleOutputRecorder``.
///
/// - Parameters:
/// - event: The event to record.
/// - eventContext: The context associated with the event.
func record(_ event: borrowing Event, in eventContext: borrowing Event.Context) {
// Skeleton implementation: delegate to ConsoleOutputRecorder
_fallbackRecorder.record(event, in: eventContext)
}
}