xd009642 / tarpaulin

A code coverage tool for Rust projects
https://crates.io/crates/cargo-tarpaulin
Apache License 2.0
2.5k stars 180 forks source link

Allow for running non-test binaries #507

Closed xd009642 closed 3 years ago

xd009642 commented 4 years ago

If a user is using a non-cargo build system for rust but has a built and instrumented binary they should be able to collect coverage for it. This issue is for tracking that feature. I've identified two approaches that could work:

  1. Run coverage on an arbitrary binary from a path

Edit: removed some unnecessary noise

xd009642 commented 4 years ago

@DenialAdams, in develop I've added a --print-rust-flags and --print-rustdoc-flags the latter isn't relevant to this, however the former should make it possible to build you binaries with eval "export "$(cargo run -- tarpaulin --print-rust-flags)"" to set the rustflags. Then just need to sort the running the test side of things for an initial proof of concept.

I'd have liked to get the --print-rust-flags command to just print a single line however different configs can result in different rust flags so tail is just there to print out the last one printed.

Once it works like that I'll then look at refining the usage but it should be workable via a potentially ugly config file listing a call to your binary as a config.

xd009642 commented 3 years ago

Created a draft PR with my first work on this. https://github.com/xd009642/tarpaulin/pull/604 It should work fine for basic usage

Ch00k commented 3 years ago

Does the change, implemented in #604, address the scenario described here? That scenario is exactly my situation: I have a bunch of integration tests, that call the executable with process::Command. I am running tarpaulin 0.16.0, but it reports 0% coverage.

xd009642 commented 3 years ago

Ah no that's covered by https://github.com/xd009642/tarpaulin/issues/107 an older issue. Though it is something I will start working on this month it's just moderately fiddly (need to capture the process spawn, read /proc/pid, add some extra tracing logic)

xd009642 commented 3 years ago

Also, I aim to do https://github.com/xd009642/tarpaulin/issues/612 next as the relocation mode could complicate those test setups anyway and lead to failures to get any coverage data and spurious failures even if I did get it working

xd009642 commented 3 years ago

@Ch00k I've got a prototype of following process exec's on https://github.com/xd009642/tarpaulin/pull/615 if you want to try it out. So far I've just tried it on a very simple toy project so more people testing it is appreciated 😄

xd009642 commented 3 years ago

pretty sure this is now solved so just going to close it