4 ms·
I find this pretty nice in D. You add unittest{} blocks which you compile into or out of your binary with a compiler flag. If you add some appropriately formatt
by jordigh 8y ago
I find this pretty nice in D. You add unittest{} blocks which you compile into or out of your binary with a compiler flag. If you add some appropriately formatted comments, ddoc also turns those into docstrings with the test as example usage.
https://dlang.org/spec/unittest.html https://dlang.org/spec/unittest.html
- skolemtotem 8y agoRust takes a similar approach. For unit tests, you use the #[cfg(test)] attribute (/ pragma / directive) for conditional compilation, and #[test] to mark a function that is a unit test, which is run whenever you run the `cargo test` command. Also, any Rust code in Markdown fences in documentation is, by default, also run by `cargo test`, which you can disable for an individual code block by marking it as `rust,norun` instead of `rust`.
- mlindner 8y agoI've seen two different posts come on to this thread to comment about D. It makes me wonder what's going on if they need come in and say 'But wait D is good too!' whenever Rust is talked about.
- erichdongubler 8y agoShameless plug: you can have D-ish testing blocks with a macro I published on https://crates.io https://crates.io as `adhesion`: https://github.com/erichdongubler/adhesion-rs https://github.com/erichdongubler/adhesion-rs