在我的货运项目中,我定义了两个二进制目标。如何从集成测试访问二进制文件中定义的函数?
[package]
name = "passman"
version = "0.1.0"
edition = "2018"
[[bin]]
name = "passmand"
path = "src/daemon/main.rs"
[[bin]]
name = "passman"
path = "src/cli/main.rs"
.
├── Cargo.lock
├── Cargo.toml
├── README.md
├── src
│ ├── cli
│ │ ├── argument
│ │ │ └── mod.rs
│ │ └── main.rs
│ └── daemon
│ ├── entry_value.rs
│ ├── main.rs
│ ├── passman_crypto.rs
│ ├── passman.service
│ └── password_file.rs <- i want to access functions defined in this
└── tests
├── password_file_tests.rs <- this is my integration test
└── test.py
我尝试使用以下方式访问该文件extern crate passmand;
,但 Cargo 只是抱怨:
--> tests/password_file_tests.rs:6:1
|
6 | extern crate passmand;
| ^^^^^^^^^^^^^^^^^^^^^^ can't find crate
就我而言,以下代码可以解决问题。
#[path = "../src/bin/some_bin.rs"]
mod some_bin;
use some_bin::XXX;
#[test]
fn func_test() {
// ...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)