mozilla / grcov

Rust tool to collect and aggregate code coverage data for multiple source files
Mozilla Public License 2.0
1.17k stars 148 forks source link

src/producer.rs:544: No input files found #1087

Open J4CKVVH173 opened 1 year ago

J4CKVVH173 commented 1 year ago

I try to configurate gitlab ci-cd for rust and I would like to have a test's coverage. I used the instruction from grcov but when I try to run grcov target/coverage --binary-path target/debug -s . -o target/coverage --keep-only 'src/*' --output-types html,cobertura I get this rust's panic message: A panic occurred at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/grcov-0.8.19/src/producer.rs:544: No input files found. I can't understand where I messed up.

Full gitlab-ci sript body

  variables:
    LLVM_PROFILE_FILE: "target/coverage/%p-%m.profraw"
  script:
    - apt update
    - apt upgrade -y
    - apt install -y pkg-config libssl-dev
    - cargo test

    - mkdir target/coverage
    - cargo install grcov
    - grcov target/coverage --binary-path target/debug -s . -o target/coverage --keep-only 'src/*' --output-types html,cobertura
    # Extract just the top-level coverage number from the XML report.
    - xmllint --xpath "concat('Coverage:\ ', 100 * string(//coverage/@line-rate), '%')" target/coverage/cobertura.xml
ktbrennan28 commented 11 months ago

Hey, I am having the same issue with a Windows environment. Were you able to resolve this?

richard-mck commented 11 months ago

I found I need to follow the full set of instructions not just the gitlab-specific elements.

I'm using an image with grcov pre-installed. My CI job works as expected, here's what it looks like:

cargo coverage:
  stage: test
  variables:
    CARGO_TEST_OPTS: "--workspace"
    TEST_BIN_ARGS: ""
    LLVM_PROFILE_FILE: "target/coverage/%p-%m.profraw"
    RUSTFLAGS: "-Cinstrument-coverage"
  script:
    - mkdir -p target/coverage
    - rustup component add llvm-tools-preview
    - cargo build
    - cargo test ${CARGO_TEST_OPTS} -- ${TEST_BIN_ARGS}
    - grcov target/coverage -b target/debug -o target/coverage --output-types cobertura
  artifacts:
    paths:
      - target/coverage
    reports:
      coverage_report:
        coverage_format: cobertura
        path: target/coverage/cobertura.xml

Without the build step, the profraw files weren't getting generated.

J4CKVVH173 commented 11 months ago

I've found out that it's important to add extra keys to rust test runner and after this grcov worked

LLVM_PROFILE_FILE='target/coverage/%p-%m.profraw' RUSTFLAGS='-C instrument-coverage' cargo test - test runner for Docker rust:1.71