xd009642/tarpaulin

`cargo build` doesn't produce cargo tarpaulin extension

Closed this issue · 4 comments

Hello lovely tarpaulin maintainers, I've just started using Rust for production purposes, which makes me run into things I haven't used before. tarpaulin does exactly what I would like from it (except maybe for covering macro expanded stuff, but I can see that this is hard). I ran into creating a Dockerfile that uses tarpauling for enforcing test coverage.

I'm not sure if there's an easy fix for this issue, or even whether this is the right place for it.

Describe the bug
cargo build --release does not appear to install the cargo tarpaulin extension. This isn't quite what I expected. I need to run cargo install cargo-tarpaulin even though I have listed cargo-tarpaulin under [dev-dependencies] in Cargo.toml. But cargo install cargo-tarpaulin isn't quite reproducible unless I specify which version

To Reproduce

mkdir -p /tmp/proj1 && cd $_
cargo new --lib my_project
cd my_project
cargo add --dev cargo-tarpaulin

mkdir -p /tmp/proj2/my_project && cd $_
# Simulate docker `COPY Cargo.toml Cargo.lock ./`
cp /tmp/proj1/my_project/Cargo.* .
mkdir src
touch src/lib.rs
cargo build --release
cargo tarpaulin

output:

error: no such command: `tarpaulin`

Expected behavior
cargo running tarpaulin: it's specified in the dev-dependencies

Aha so cargo add --dev cargo-tarpaulin would just add tarpaulin as a library it won't add the dependency, you need to do cargo install tarpaulin for that.

As to why tarpaulin has a library interface - it was initially so I could embed parts of it into other sandbox programs to test/experiment on things, but it does have at least one user who has it as part of a service and didn't want to exec another process

@xd009642 thanks for your quick reply.
So there's no "easy" way around this, I gather? I'd probably have to do something like

cargo install cargo-tarpaulin --version=$(grep cargo-tarpaulin Cargo.toml | cut -d '"' -f 2)

Is this correct?

Do you actually need tarpaulin as a library? If not I'd just do cargo install cargo-tarpaulin --version=$VERSION and avoid the grep stuff. But yeah that's correct

Thank you!!!