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
Fix tests failing without the fancy feature #89
base: main
Are you sure you want to change the base?
Conversation
@@ -384,6 +384,7 @@ of falling back to your own custom handler. | |||
Usage is like so: | |||
|
|||
```rust | |||
#[cfg(feature = "fancy")] |
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.
I don't think this is the right thing to do. If someone were to copy-paste this snippet, they would be conditionalizing their set_hook based on their own fancy
feature, not miette
's.
I think the fix for this is trickier than we're thinking and tbh I'm not opposed to the fix being "tests don't work without --all-features"
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.
Good point! I'm not sure about this, since I don't think theres a better way to fix this error, but on the other hand I also think it'd be great if tests would pass regardless of the feature flags. Maybe we could add a comment explaining that the attribute is only there so tests pass? If you don't think this needs to be changed, feel free to close the issue and PR :D
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.
I also ran into this error. One way to do it is to remove the #[cfg(feature = "fancy")]
in lib.rs
#[cfg(feature = "fancy")]
pub use handler::*;
and to spread it in handler.rs
to have a MietteHandlerOpts available without the fancy
feature and be able to configure the footer
and context_lines
when building a NarratableReportHandler
.
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.
That seems like a better idea!
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 seems like that implementation would require a bunch of changes around miette. I'm also not sure how clean that would be, as it would require about 16 cfg attributes in handler.rs. Also, we'd probably have to make some dependencies that are currently only needed on the fancy feature be always required.
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.
Here are some ways that may lead to less cfg attributes:
- Create guarded impl blocks
- remove the
pub(crate)
from the members ofMietteHandlerOpts
- split the
impl MietteHandlerOpts
with on one sidefooter
andcontext_lines
and the other one guarded by a#[cfg(feature = "fancy")]
- now for
build
:- create
build_narrated
and abuild_graphical
functions. The second one going in the guarded impl bloc - spread/duplicate
build
in 2 impl blocks one guarded and one whenfancy
is not active that calls the 2 new functions
- create
- Delegate the builders to Narrated and Graphical and have
MietteHandlerOpts
just be a facade.
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.
@LordMZTE do you still work on this one ?
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.
Well, I'm not sure how to continue with this, or if this is something we should even worry about.
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.
#[cfg(feature = "fancy")] | |
# #[cfg(feature = "fancy")] |
Would hide the cfg
attribute in the generated documentation, avoiding the copy/paste issue. Still results in the test being silently ignored when the fancy
feature isn't enabled, which I'm not sure is desirable, since set_hook
is available either way.
If we go the route of "tests don't work without --all-features" , it would be nice if there was a clearer indication of why the tests are failing. When I first started looking at this project, I was definitely confused by the failing tests, and it took a bit to find the relevant part in CONTRIBUTING.md
that explained it.
Something like this:
#[cfg(all(test, not(feature = "fancy")))]
compile_error!("Tests only work with the 'fancy' feature enabled. Try 'cargo test --features fancy'.");
92a28b7
to
b045321
Compare
Also adds a CI step to run tests without the fancy feature. Closes #88