-
Notifications
You must be signed in to change notification settings - Fork 136
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
Introduce new public Reporter
trait that is used from CLI types to report file status
#309
Conversation
The `Querier` is a reusable type that should not assume it is used in a console output where printing things is okay. This change ensures all output is reported to the reporter only.
Performance SummaryComparing base 134b7bc with head 0fcb846 on typescript_benchmark benchmark. For details see workflow artifacts. Note that performance is tested on the last commits with changes in Before
After
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Left a couple of optional suggestions
use crate::CancellationFlag; | ||
|
||
use super::util::reporter::ConsoleReporter; | ||
use super::util::reporter::Level; | ||
use super::util::CLIFileReporter; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I would suggest not having both crate
references and super
references — can you change these to crate::util::[etc]
? (Unless there's a reason for the super
references that I missed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is a good suggestion. Perhaps VSCode does this automatically? At least I don't remember doing this inpurpose.
@@ -373,7 +398,8 @@ impl TestArgs { | |||
filter: &dyn Filter, | |||
success: bool, | |||
cancellation_flag: &dyn CancellationFlag, | |||
) -> anyhow::Result<()> { | |||
) -> anyhow::Result<Vec<String>> { | |||
let mut outputs = Vec::with_capacity(3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like outputs
is only ever used by joining the string elements into a larger string delimited by newlines. Is it worth building up a single already-joined String
here? String
implements std::fmt::Write
, so all of your outputs.push(format!(...))
calls would turn into write!(&mut output, ...)
.
That said, this suggestion might be premature optimization, since this code path is only called when running our test suite.
/// | ||
/// For each file, either | ||
/// - [`skipped`] is called once, or | ||
/// - [`started`] and one of [`succeeded`], [`failed`], or [`canceled`] are called. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"and one" ⇒ "and then one" to describe the required ordering of calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's better!
Does this need a changelog entry? |
Performance SummaryComparing base 134b7bc with head 0fcb846 on typescript_benchmark benchmark. For details see workflow artifacts. Note that performance is tested on the last commits with changes in Before
After
|
Fixes #307 by introducing a public
Reporter
trait that users can implement for custom logging.Approach
File status is reported through a
Reporter
trait. To keep the burden on implementors limited, we require a predicatable way of calling reporters:skipped
, orstarted
and on of (succeeded
,failed
, orcanceled
).Implementation
A
ConsoleReporter
type is provided that prints to the console and allows control over what is logged.The implementations if
Indexer
andQuerier
take some short-cuts, and violate this protocol. That is solved by theCLIFileLogger
utility class, that retains that part of the logic from the oldLogger
implementation.The
Querier
has also been updated to use the reporter for all its output. Previously, it was still printing directly to the console in some cases.