Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

LordMZTE
Copy link

Also adds a CI step to run tests without the fancy feature. Closes #88

@@ -384,6 +384,7 @@ of falling back to your own custom handler.
Usage is like so:

```rust
#[cfg(feature = "fancy")]
Copy link
Owner

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"

Copy link
Author

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

Copy link
Contributor

@dvermd dvermd Oct 18, 2021

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.

Copy link
Owner

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!

Copy link
Author

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.

Copy link
Contributor

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:

  1. Create guarded impl blocks
  • remove the pub(crate) from the members of MietteHandlerOpts
  • split the impl MietteHandlerOpts with on one side footer and context_lines and the other one guarded by a #[cfg(feature = "fancy")]
  • now for build:
    • create build_narrated and a build_graphical functions. The second one going in the guarded impl bloc
    • spread/duplicate build in 2 impl blocks one guarded and one when fancy is not active that calls the 2 new functions
  1. Delegate the builders to Narrated and Graphical and have MietteHandlerOpts just be a facade.

Copy link
Contributor

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 ?

Copy link
Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#[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'.");

@zkat zkat force-pushed the main branch 3 times, most recently from 92a28b7 to b045321 Compare April 1, 2023 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tests in README failing without fancy feature
4 participants