-
-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coverage for executables #252
Comments
One comment: It might be possible to have tests which execute the binary under /// Get name of the binary
fn bin() -> path::PathBuf {
let root = env::current_exe()
.unwrap()
.parent()
.unwrap()
.parent()
.unwrap()
.to_path_buf();
if cfg!(target_os = "windows") {
root.join("my-binary.exe")
} else {
root.join("my-binary")
}
}
#[test]
fn test_my_binary() {
let mut cmd = process::Command::new(bin());
cmd.arg(...);
match cmd.status() {
Err(e) => {
println!("Error: {}.", e);
panic!();
}
Ok(status) => {
println!("Exited with code {:?}.", status.code());
assert!(!status.success());
}
}
} but |
I now have support running tarpaulin on benchmarks and examples in the develop branch, running on arbitrary binaries is still unsupported but something I'm actively working towards |
I'm working on a application server project where we have a few unit tests but a lot of integration tests. The tests are written in Python and simply run against the Rust server running on localhost. It would be great if we could track coverage of the server binary ( |
How does one run tests for project with multiple binaries? |
There's a WIP PR for this if people want to test it, or comment on the UI I put in the comment #604 |
Also as per my last comment on this repo the benchmark and example stuff changed... I realised the semantics of |
You can now do this via So feel free to try in 0.16.0 and if there are any issues if you comment on this more recent issue #507 😄 |
Thanks @xd009642! Excited to test this! My integration test suite is written in Python. It simply does calls against the main binary being run (a WebSocket server). If I understand things correctly, I would run tarpaulin with When running tarpaulin both with |
@dbrgn Yeah I guess you'd have to modify it for a close message. There is a [py_tests]
command = "build"
[rust_tests]
command = "test" |
@dbrgn oh another thought is that you can use the more verbose logging to get the test PID and send the SIGINT to the test itself bypassing tarpaulin. Then with I need to figure out some smarter semantics for the signalling stuff... I've opened #622 to track any work on it |
I now just shut down the server with |
@xd009642 after some more thought, maybe tarpaulin could allow running a custom shell command (hooks?) before the binary has been started, after it has been started and after it has been stopped? Maybe even with the PID being passed to the hooks. That way, the integration tests could automatically be started after the binary was started, and if the testsuite has access to the PID it could send a signal after it's done. |
Maybe I'd have to think about it, feel free to open an issue for the feature where we can always discuss it further 😄 |
Done! #623 |
In the case where the crate is for a binary,
cargo tarpaulin
will run all the tests within the crate, but is it possible to test the executable itself (with arguments)? Or similarly, handling library with associated binaries (insrc/bin/main.rs
)?Effectively, this would be in analogy to
cargo run -- <args>
, perhaps ascargo tarpaulin --run -- <args>
or maybe a different commandcargo tarpaulin-run -- <args>
?The text was updated successfully, but these errors were encountered: