Skip to content
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

Grcov create a sub-folder inside the same previous output folder when the output type is html #1020

Open
FirelightFlagboy opened this issue Apr 22, 2023 · 7 comments

Comments

@FirelightFlagboy
Copy link

FirelightFlagboy commented Apr 22, 2023

Tools version

$ cargo --version
cargo 1.68.2 (6feb7c9cf 2023-03-26)
$ grcov --version                                                                            
grcov 0.8.18

Replication steps

  1. Create an example project:

    cargo new --lib
  2. Generate coverage data using example tests:

    RUSTFLAGS="-C instrument-coverage -C codegen-units=1" cargo test
  3. Generate coverage report in HTML:

    grcov --output-path=html/ --output-type=html --binary-path=target/debug/deps .
  4. List output directory:

    $ tree html                                                                     
    html
    ├── badges
    │   ├── flat_square.svg
    │   ├── flat.svg
    │   ├── for_the_badge.svg
    │   ├── plastic.svg
    │   └── social.svg
    ├── coverage.json
    └── index.html
    
    2 directories, 7 files
  5. Re-generate coverage report

    grcov --output-path=html/ --output-type=html --binary-path=target/debug/deps .
  6. List output directory

    $ tree html                                                                     
    html
    ├── badges
    │   ├── flat_square.svg
    │   ├── flat.svg
    │   ├── for_the_badge.svg
    │   ├── plastic.svg
    │   └── social.svg
    ├── coverage.json
    ├── html
    │   ├── badges
    │   │   ├── flat_square.svg
    │   │   ├── flat.svg
    │   │   ├── for_the_badge.svg
    │   │   ├── plastic.svg
    │   │   └── social.svg
    │   ├── coverage.json
    │   └── index.html
    └── index.html
    
    4 directories, 14 files

    Note here the folder html inside the folder of the same name.

Expected result

I was expected grcov to not create another folder html in the output folder html and to just reuse the folder html by overwriting files that need to be.

@hartwork
Copy link

hartwork commented Jun 5, 2023

I found out that -o html/ (with slash) and -o html (without slash) behave differently: With slash will get you two layers of html, without slash will not. Not ideal, but might be good to know.

@detly
Copy link
Contributor

detly commented Aug 23, 2023

This caught me out, and I was not using a trailing /. Thought I was losing my mind because the coverage numbers wouldn't change no matter what I did.

@qsantos
Copy link

qsantos commented Nov 22, 2023

Same here. Using a trailing slash changes nothing.

$ grcov . -s . --binary-path target/debug -t html -o ./target/debug/coverage/
$ ls ./target/debug/coverage
badges  src  tests  coverage.json  index.html
$ grcov . -s . --binary-path target/debug -t html -o ./target/debug/coverage/
$ ls ./target/debug/coverage
badges  html  src  tests  coverage.json  index.html
$ grcov . -s . --binary-path target/debug -t html -o ./target/debug/coverage
$ ls ./target/debug/coverage
badges  src  tests  coverage.json  index.html
$ grcov . -s . --binary-path target/debug -t html -o ./target/debug/coverage
$ ls ./target/debug/coverage
badges  html  src  tests  coverage.json  index.html

@hartwork
Copy link

@qsantos that path does not end in html. Try with and without trailing slash and ending in html. I have proof for grcov 0.8.18 at https://github.com/hartwork/rust-for-it/actions/runs/6906333800 for that very case.

@qsantos
Copy link

qsantos commented Nov 23, 2023

Hello @hartwork, thank for the suggestion! Unfortunately, I still get the same behavior:

$ rm -Rf target/debug/coverage
$ grcov . -s . --binary-path target/debug -t html --branch -o ./target/debug/coverage/html
$ ls ./target/debug/coverage/html
badges  src  tests  coverage.json  index.html
$ grcov . -s . --binary-path target/debug -t html --branch -o ./target/debug/coverage/html
$ ls ./target/debug/coverage/html
badges  html  src  tests  coverage.json  index.html
$ grcov --version
grcov 0.8.19

In your GitHub workflow, I only a single call to grcov with -o target/coverage/html. Since this is running in a CI, wouldn't the fact that you do not get target/coverage/html/html be explained by the fact that the directory target/coverage/html is not kept between runs?

@qsantos
Copy link

qsantos commented Nov 23, 2023

By the way, my own solution is to just mkdir -p ./target/debug/coverage/ before running grcov to always have the same behavior on consecutive local runs.

@hartwork
Copy link

@qsantos thanks for sharing these details! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants