In my cargo project I have defined two binary targets. How can I access functions defined in the binary from an integration test?
[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
I tried to access the file with extern crate passmand;, but Cargo just complains:
--> tests/password_file_tests.rs:6:1
|
6 | extern crate passmand;
| ^^^^^^^^^^^^^^^^^^^^^^ can't find crate
In my case, the following codes work around.
#[path = "../src/bin/some_bin.rs"]
mod some_bin;
use some_bin::XXX;
#[test]
fn func_test() {
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With