We have tests that are broken on macOS for some reason and they are to be investigated when the time is right as they're in the backlog. Currently, they're disabled with
#[cfg(not(target_os = "macos"))]
However, this has the horrible side effect that enabling all these tests will require doing it one by one, which is very inconvenient and makes testing the side effects of other changes much harder.
Please note that using the #[ignore]
modifier for these tests isn't really an option because there are many other ignored tests for other reasons (let's say for the right reasons, such as they're heavy and shouldn't be run regularly).
In C++, I would just wrap them in an #ifdef
macro and just comment/uncomment a line in cmake to control whether these tests will be run.
In Rust, as far as I understand, the feature
feature is the right way to do this. I'm very close to getting this to work, so now above every one of these tests I have
#[cfg(not(feature = "no-mac-tcp-tests"))]
and in Cargo.toml of the relevant crate:
[features]
no-mac-tcp-tests = []
This has the intended side-effect, except that I can't tell cargo to, by default, disable this for mac. I tried
[target.'cfg(target_os = "macos")'.features]
no-mac-tcp-tests = []
but that doesn't work. I know that doesn't work as intended because changing macos to windows doesn't really do anything on my mac machine.
How can I achieve my goal, namely, disable a bunch of tests based on a flag in the crate's Cargo.toml depending on the OS?