I have a crate that provides a cross-platform abstraction using a trait, but then also has specific structs for each platform that also publically exposes additional functionality. In this way consumers of my library can use either the cross-platform API or a platform-specific API depending on what functionality they need.
I’m having trouble with tests and examples that are platform-specific. I’ve broken up my library so the platform-specific code live in individual files with
lib.rs providing the cross-platform abstractions. I was planning to write my tests and examples such that the platform-specific code are in entire files. But if I put a
#![cfg(unix)] at the top of an example, running
cargo test on Windows will result in an
error: main function not found.
So it’s not clear to me what the current best practices are for examples or tests that are platform-specific when trying to
cargo test on other platforms as I would’ve expected the above setup to be the “best”.
Has anyone solved this problem to their satisfaction?