【发布时间】:2020-03-13 08:09:01
【问题描述】:
我有一个想要添加可选功能的包。我在 Cargo.toml 中添加了适当的部分:
[features]
foo = []
我为cfg!宏的基本功能写了一个实验测试:
#[test]
fn testing_with_foo() {
assert!(cfg!(foo));
}
看起来我可以在测试期间通过--features 或--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
不过,cargo test --features foo testing_with_foo 和 cargo test --all-features testing_with_foo 都不起作用。
这样做的正确方法是什么?
【问题讨论】:
-
你试过
cargo test -- --features foo testing_with_foo(注意--)。
标签: unit-testing testing rust conditional-compilation