Skip to content

Commit 838a934

Browse files
authored
Preserve verbosity argument in HumanReadableOutputRecorder.record(). (#707)
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. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 5843e4d commit 838a934

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

Sources/Testing/ABI/EntryPoints/EntryPoint.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ func entryPoint(passing args: __CommandLineArguments_v0?, eventHandler: Event.Ha
5151

5252
#if !SWT_NO_FILE_IO
5353
// Configure the event recorder to write events to stderr.
54-
var options = Event.ConsoleOutputRecorder.Options()
55-
options = .for(.stderr)
56-
let eventRecorder = Event.ConsoleOutputRecorder(options: options) { string in
57-
try? FileHandle.stderr.write(string)
58-
}
59-
configuration.eventHandler = { [oldEventHandler = configuration.eventHandler] event, context in
60-
eventRecorder.record(event, in: context)
61-
oldEventHandler(event, context)
54+
if configuration.verbosity > .min {
55+
let eventRecorder = Event.ConsoleOutputRecorder(options: .for(.stderr)) { string in
56+
try? FileHandle.stderr.write(string)
57+
}
58+
configuration.eventHandler = { [oldEventHandler = configuration.eventHandler] event, context in
59+
eventRecorder.record(event, in: context)
60+
oldEventHandler(event, context)
61+
}
6262
}
6363
#endif
6464

Sources/Testing/ABI/v0/ABIv0.Record+Streaming.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ extension ABIv0.Record {
7979
eventHandler(testJSON)
8080
}
8181
} else {
82-
let messages = humanReadableOutputRecorder.record(event, in: context)
82+
let messages = humanReadableOutputRecorder.record(event, in: context, verbosity: 0)
8383
if let eventRecord = Self(encoding: event, in: context, messages: messages) {
8484
try? JSON.withEncoding(of: eventRecord, eventHandler)
8585
}

Sources/Testing/Events/Recorder/Event.HumanReadableOutputRecorder.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,27 @@ extension Event.HumanReadableOutputRecorder {
202202
/// - Parameters:
203203
/// - event: The event to record.
204204
/// - eventContext: The context associated with the event.
205+
/// - verbosity: How verbose output should be. When the value of this
206+
/// argument is greater than `0`, additional output is provided. When the
207+
/// value of this argument is less than `0`, some output is suppressed.
208+
/// If the value of this argument is `nil`, the value set for the current
209+
/// configuration is used instead. The exact effects of this argument are
210+
/// implementation-defined and subject to change.
205211
///
206212
/// - Returns: An array of zero or more messages that can be displayed to the
207213
/// user.
208-
@discardableResult public func record(_ event: borrowing Event, in eventContext: borrowing Event.Context) -> [Message] {
209-
let verbosity = eventContext.configuration?.verbosity ?? 0
214+
@discardableResult public func record(
215+
_ event: borrowing Event,
216+
in eventContext: borrowing Event.Context,
217+
verbosity: Int? = nil
218+
) -> [Message] {
219+
let verbosity: Int = if let verbosity {
220+
verbosity
221+
} else if let verbosity = eventContext.configuration?.verbosity {
222+
verbosity
223+
} else {
224+
0
225+
}
210226
let test = eventContext.test
211227
let testName = if let test {
212228
if let displayName = test.displayName {
@@ -501,12 +517,3 @@ extension Event.HumanReadableOutputRecorder {
501517
// MARK: - Codable
502518

503519
extension Event.HumanReadableOutputRecorder.Message: Codable {}
504-
505-
// MARK: - Deprecated
506-
507-
extension Event.HumanReadableOutputRecorder {
508-
@available(*, deprecated, message: "Use record(_:in:) instead. Verbosity is now controlled by eventContext.configuration.verbosity.")
509-
@discardableResult public func record(_ event: borrowing Event, in eventContext: borrowing Event.Context, verbosity: Int) -> [Message] {
510-
record(event, in: eventContext)
511-
}
512-
}

0 commit comments

Comments
 (0)