From bc7f9046a1f8d06dd63736eb5db00d8be83d5606 Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Tue, 17 Sep 2024 16:51:47 -0400 Subject: [PATCH 1/3] Preserve `verbosity` argument in `HumanReadableOutputRecorder.record()`. This PR restores/undeprecates the `verbosity` argument to `HumanReadableOutputRecorder.record()` that was deprecated in #677. We still need to be able to override the command-line-specified value in the event stream. --- .../ABI/v0/ABIv0.Record+Streaming.swift | 2 +- .../Event.HumanReadableOutputRecorder.swift | 29 ++++++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Sources/Testing/ABI/v0/ABIv0.Record+Streaming.swift b/Sources/Testing/ABI/v0/ABIv0.Record+Streaming.swift index 3bb334742..0d93f70bc 100644 --- a/Sources/Testing/ABI/v0/ABIv0.Record+Streaming.swift +++ b/Sources/Testing/ABI/v0/ABIv0.Record+Streaming.swift @@ -79,7 +79,7 @@ extension ABIv0.Record { eventHandler(testJSON) } } else { - let messages = humanReadableOutputRecorder.record(event, in: context) + let messages = humanReadableOutputRecorder.record(event, in: context, verbosity: 0) if let eventRecord = Self(encoding: event, in: context, messages: messages) { try? JSON.withEncoding(of: eventRecord, eventHandler) } diff --git a/Sources/Testing/Events/Recorder/Event.HumanReadableOutputRecorder.swift b/Sources/Testing/Events/Recorder/Event.HumanReadableOutputRecorder.swift index 833913cde..ad4b79b8e 100644 --- a/Sources/Testing/Events/Recorder/Event.HumanReadableOutputRecorder.swift +++ b/Sources/Testing/Events/Recorder/Event.HumanReadableOutputRecorder.swift @@ -202,11 +202,27 @@ extension Event.HumanReadableOutputRecorder { /// - Parameters: /// - event: The event to record. /// - eventContext: The context associated with the event. + /// - verbosity: How verbose output should be. When the value of this + /// argument is greater than `0`, additional output is provided. When the + /// value of this argument is less than `0`, some output is suppressed. + /// If the value of this argument is `nil`, the value set for the current + /// configuration is used instead. The exact effects of this argument are + /// implementation-defined and subject to change. /// /// - Returns: An array of zero or more messages that can be displayed to the /// user. - @discardableResult public func record(_ event: borrowing Event, in eventContext: borrowing Event.Context) -> [Message] { - let verbosity = eventContext.configuration?.verbosity ?? 0 + @discardableResult public func record( + _ event: borrowing Event, + in eventContext: borrowing Event.Context, + verbosity: Int? = nil + ) -> [Message] { + let verbosity: Int = if let verbosity { + verbosity + } else if let verbosity = eventContext.configuration?.verbosity { + verbosity + } else { + 0 + } let test = eventContext.test let testName = if let test { if let displayName = test.displayName { @@ -501,12 +517,3 @@ extension Event.HumanReadableOutputRecorder { // MARK: - Codable extension Event.HumanReadableOutputRecorder.Message: Codable {} - -// MARK: - Deprecated - -extension Event.HumanReadableOutputRecorder { - @available(*, deprecated, message: "Use record(_:in:) instead. Verbosity is now controlled by eventContext.configuration.verbosity.") - @discardableResult public func record(_ event: borrowing Event, in eventContext: borrowing Event.Context, verbosity: Int) -> [Message] { - record(event, in: eventContext) - } -} From 2fc55376e279a545f853b7c21d67d9950388c464 Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Tue, 17 Sep 2024 17:11:45 -0400 Subject: [PATCH 2/3] Don't bother creating a stderr-aimed recorder in the first place if output verbosity is .min --- .../Testing/ABI/EntryPoints/EntryPoint.swift | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Sources/Testing/ABI/EntryPoints/EntryPoint.swift b/Sources/Testing/ABI/EntryPoints/EntryPoint.swift index 725ef91ff..c24750c74 100644 --- a/Sources/Testing/ABI/EntryPoints/EntryPoint.swift +++ b/Sources/Testing/ABI/EntryPoints/EntryPoint.swift @@ -51,14 +51,16 @@ func entryPoint(passing args: __CommandLineArguments_v0?, eventHandler: Event.Ha #if !SWT_NO_FILE_IO // Configure the event recorder to write events to stderr. - var options = Event.ConsoleOutputRecorder.Options() - options = .for(.stderr) - let eventRecorder = Event.ConsoleOutputRecorder(options: options) { string in - try? FileHandle.stderr.write(string) - } - configuration.eventHandler = { [oldEventHandler = configuration.eventHandler] event, context in - eventRecorder.record(event, in: context) - oldEventHandler(event, context) + if configuration.verbosity > .min { + var options = Event.ConsoleOutputRecorder.Options() + options = .for(.stderr) + let eventRecorder = Event.ConsoleOutputRecorder(options: options) { string in + try? FileHandle.stderr.write(string) + } + configuration.eventHandler = { [oldEventHandler = configuration.eventHandler] event, context in + eventRecorder.record(event, in: context) + oldEventHandler(event, context) + } } #endif From 65843e27c68d577523fe490f70cd47e294f98e69 Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Tue, 17 Sep 2024 17:19:15 -0400 Subject: [PATCH 3/3] Simplify setting up the recorder --- Sources/Testing/ABI/EntryPoints/EntryPoint.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sources/Testing/ABI/EntryPoints/EntryPoint.swift b/Sources/Testing/ABI/EntryPoints/EntryPoint.swift index c24750c74..73052b503 100644 --- a/Sources/Testing/ABI/EntryPoints/EntryPoint.swift +++ b/Sources/Testing/ABI/EntryPoints/EntryPoint.swift @@ -52,9 +52,7 @@ 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 { - var options = Event.ConsoleOutputRecorder.Options() - options = .for(.stderr) - let eventRecorder = Event.ConsoleOutputRecorder(options: options) { string in + let eventRecorder = Event.ConsoleOutputRecorder(options: .for(.stderr)) { string in try? FileHandle.stderr.write(string) } configuration.eventHandler = { [oldEventHandler = configuration.eventHandler] event, context in