Open cscherrer opened 6 months ago
Thanks for the feature request!
This seems rather tricky given the current design of the crate and I don't see an obvious way to implement it. The approach you describe--defining a new trait that has both traits as supertraits--should work, although I agree it's clunky.
A couple thoughts:
where Self: Trait2
bound to test functions for Trait1
(or vice versa), similar to how the example tests use where Self: Default
. This is more restrictive for implementers, since it means they have to implement both traits to instantiate the tests. Perhaps there should be a way to instantiate only the tests with trait bounds compatible with the implementing type, although then there should be an obvious way to tell which tests are being run and which are being ignored.trait_tests
implements the definition half of this approachThanks @max-heller for the helpful response. Of your two bullets, I think we have cases of each. I haven't seen trait_tests
before, I'll check it out.
Hi, thank you for your work on this package! I think this can really help with increasing test coverage and decreasing redundancy.
One thing that I found a little tricky to work around is when you want tests associated with some trait bound, instead of just a single trait.
Say I have
Trait1
andTrait2
, and I want some test forTrait1 + Trait2
. As I understand, this currently requires adding someTrait_1_and_2: Trait1 + Trait2
and then making sure implementations are marked explicitly. After this, the package applies as usual.This works, but it seems like a lot of boilerplate. It would be cleaner if we could somehow apply
#[tested_trait]
toTrait1 + Trait2
, and then similarly for#[test_impl]
.I'm new to Rust macros, so I don't have a sense of how involved this would be, or what syntax would be appropriate. Or even better would be if you've already thought of this and might have an approach you've found to work well. I'd appreciate any advice on this.
Thanks again :smile: