Source-based code coverage busted?

I'm trying to work through the code coverage example at GitHub - marco-c/rust-code-coverage-sample: Example of code coverage instrumentation in Rust. Everything "runs" fine, but when I examine the coverage report, it says 0% coverage.

I'm running an Intel Mac on OS 10.15.6, Rust 1.54.0 nightly (cargo 070e459c2 2021-05-11).

Is this a known issue?

Any suggested workarounds? Same happens in my own real project and is making dev work more difficult.

Never mind. Added this to my Makefile and all is well now:

test-with-coverage: rust-nightly
	rm -rf ./coverage/*.profraw
	RUSTFLAGS="-Z instrument-coverage" LLVM_PROFILE_FILE="./coverage/%p.profraw" cargo +nightly test
	# The LLVM_PROFILE_FILE trick is necessary; otherwise, the
	# .profraw files wind up in a last-writer-wins race which often
	# (always?) results in a report showing 0% coverage.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.