Skip to content

Preserve verbosity argument in HumanReadableOutputRecorder.record(). #707

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 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 8 additions & 8 deletions Sources/Testing/ABI/EntryPoints/EntryPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ 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 {
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: 1 addition & 1 deletion Sources/Testing/ABI/v0/ABIv0.Record+Streaming.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor Author

@grynspan grynspan Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't use the Elvis operator (??) with borrowed values (yet.)

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 {
Expand Down Expand Up @@ -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)
}
}