-
-
Notifications
You must be signed in to change notification settings - Fork 123
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
Add option to fully disable url output (for tests) #136
Comments
You can get partway there with a wrapper diagnostic to strip the URLs #[derive(Debug, Error)]
#[error(transparent)]
struct StripDiagnosticUrl<T>(T);
impl<T: Diagnostic> Diagnostic for StripDiagnosticUrl<T> {
fn code<'a>(&'a self) -> Option<Box<dyn fmt::Display + 'a>> {
self.0.code()
}
fn severity(&self) -> Option<miette::Severity> {
self.0.severity()
}
fn help<'a>(&'a self) -> Option<Box<dyn fmt::Display + 'a>> {
self.0.help()
}
fn url<'a>(&'a self) -> Option<Box<dyn fmt::Display + 'a>> {
None
}
fn source_code(&self) -> Option<&dyn miette::SourceCode> {
self.0.source_code()
}
fn labels(&self) -> Option<Box<dyn Iterator<Item = miette::LabeledSpan> + '_>> {
self.0.labels()
}
fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn miette::Diagnostic> + 'a>> {
self.0.related()
}
} but this doesn't strip the URLs from related diagnostics, and I don't think there's a way to transform Footnotes
|
For the purpose of tests, leaking is probably fine, so here's a full interim solution: #[derive(Debug, Error)]
#[error(transparent)]
struct StripDiagnosticUrl<'a>(&'a dyn Diagnostic);
impl Diagnostic for StripDiagnosticUrl<'_> {
fn code<'a>(&'a self) -> Option<Box<dyn fmt::Display + 'a>> {
self.0.code()
}
fn severity(&self) -> Option<miette::Severity> {
self.0.severity()
}
fn help<'a>(&'a self) -> Option<Box<dyn fmt::Display + 'a>> {
self.0.help()
}
fn url<'a>(&'a self) -> Option<Box<dyn fmt::Display + 'a>> {
None
}
fn source_code(&self) -> Option<&dyn miette::SourceCode> {
self.0.source_code()
}
fn labels(&self) -> Option<Box<dyn Iterator<Item = miette::LabeledSpan> + '_>> {
self.0.labels()
}
fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn miette::Diagnostic> + 'a>> {
self.0.related().map(
|iter| -> Box<dyn Iterator<Item = &'a dyn miette::Diagnostic> + 'a> {
Box::new(
// leakage is sad but required to strip URLs from the test output [zkat/miette#136]
iter.map(|d| -> &dyn Diagnostic { Box::leak(Box::new(StripDiagnosticUrl(d))) }),
)
},
)
}
} |
As an example snapshot test:
Because I've used
#[diagnostic(url(docsrs))]
, the docsrs URL is embedded into the diagnostic, and the output is version-dependent. This means that bumping the version number will also require re-blessing all of the snapshot tests with the new version number.I'm already directly using
GraphicalReportHandler
to get (hopefully) environment-independent formatting with no ANSI codesbut it'd be nice to be able to also completely remove the URL for test purposes.
This would add a new flag to
GraphicalReportHandler
,with_urls(urls: bool)
, which would fully disable reporting ofDiagnostic::url
.The text was updated successfully, but these errors were encountered: