【发布时间】:2017-11-02 01:17:22
【问题描述】:
我想编译一个运行特定测试子集的二进制文件。当我运行以下命令时,它可以工作:
ubuntu@ubuntu-xenial:/ox$ cargo test hash::vec
Finished dev [unoptimized + debuginfo] target(s) in 0.11 secs
Running target/debug/deps/ox-824a031ff1732165
running 9 tests
test hash::vec::test_hash_entry::test_get_offset_tombstone ... ok
test hash::vec::test_hash_entry::test_get_offset_value ... ok
test hash::vec::test_hash_table::test_delete ... ok
test hash::vec::test_hash_table::test_delete_and_set ... ok
test hash::vec::test_hash_table::test_get_from_hash ... ok
test hash::vec::test_hash_table::test_get_non_existant_from_hash ... ok
test hash::vec::test_hash_table::test_override ... ok
test hash::vec::test_hash_table::test_grow_hash ... ok
test hash::vec::test_hash_table::test_set_after_filled_with_tombstones ... ok
test result: ok. 9 passed; 0 failed; 0 ignored; 0 measured; 8 filtered out
当我尝试运行 target/debug/deps/ox-824a031ff1732165 时,它会运行我的所有测试,而不仅仅是 hash::vec 中指定的 9。
我尝试运行cargo rustc --test hash::vec,但我得到了
error: no test target namedhash::vec.cargo rustc -- --testworks, but creates a binary that runs all tests. If I trycargo rustc -- --test hash::vec`,我明白了:
Compiling ox v0.1.0 (file:///ox)
error: multiple input filenames provided
error: Could not compile `ox`.
cargo rustc -h 说您可以使用 --test 标志 (--test NAME Build only the specified test target) 传递 NAME,所以我想知道“NAME”是什么以及如何传递它,所以我得到一个只运行指定的二进制文件hash::vec 中的 9 个测试。
【问题讨论】:
标签: unit-testing testing rust rust-cargo