max-heller / tested-trait

Associate tests with Rust traits
Apache License 2.0
7 stars 0 forks source link

"+ style" trait bounds #9

Open cscherrer opened 6 months ago

cscherrer commented 6 months ago

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 and Trait2, and I want some test for Trait1 + Trait2. As I understand, this currently requires adding some Trait_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] to Trait1 + 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:

max-heller commented 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:

cscherrer commented 6 months ago

Thanks @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.