frondeus / test-case

Rust procedural macro attribute for adding test cases easily
MIT License
614 stars 39 forks source link

Add with-assert-override #110

Open luke-biel opened 1 year ago

luke-biel commented 1 year ago

Closes https://github.com/frondeus/test-case/issues/109 Closes https://github.com/frondeus/test-case/issues/84

luke-biel commented 1 year ago

Yeah, it's clunky, however there's no better way without providing custom test harness. So far we can consider crate level, module level and test level configurations. Crate level require something that can be guaranteed in static context, and this is best solution I could think of. Module level would require to have written custom macro with module harness, and this is way to big of a task to do it now. For test level I've already shown few workarounds with using, with or simply doing assertion comparison by yourself.

As for assert being present - as I mentioned, we need something generic over different possible assertion crates. It's optional to override assert, as shown in tests.

vriesk commented 1 year ago

crate level would certainly be most user-friendly, with a possible module-level override option (not my use case, but I imagine this being useful).

luke-biel commented 1 year ago

I'm gonna fix tests in this and push it then.

I'd really avoid feature flags, as they tend to break when workspaces are at play, plus it would anyway introduce dependency on pretty-assertions, one that shouldn't break easily, but I had enough bad experience with insta and broken transitive deps to avoid depending on other crates at all cost. I don't really see a better option without using nightly or forcing a custom test harness. Maybe in the future I can replace this once something new shows up in rust. For time being unfortunately it has to be lib.rs level macro.