I have a package I want to add an optional feature to. I've added an appropriate section to my Cargo.toml:
[features]
foo = []
I wrote an experimental test for the basic functionality of the cfg!
macro:
#[test]
fn testing_with_foo() {
assert!(cfg!(foo));
}
It looks as though I can activate features during testing via either of the options --features
or --all-features
:
(master *=) $ cargo help test
cargo-test
Execute all unit and integration tests and build examples of a local package
USAGE:
cargo test [OPTIONS] [TESTNAME] [-- <args>...]
OPTIONS:
-q, --quiet Display one character per test instead of one line
...
--features <FEATURES>... Space-separated list of features to activate
--all-features Activate all available features
Neither cargo test --features foo testing_with_foo
nor cargo test --all-features testing_with_foo
works, though.
What is the proper way to do this?
cargo test -- --features foo testing_with_foo
(note the--
). – Higley