simplecov-ruby / simplecov

Code coverage for Ruby with a powerful configuration library and automatic merging of coverage across test suites
MIT License
4.74k stars 550 forks source link

Simplecov collate not work as expect #980

Open kewudu opened 3 years ago

kewudu commented 3 years ago

I have my own test framework in my project, when I use simplecov to get coverage in the same machine, I can not merge the coverage result, the merged result is empty!

Operation step: (1) run test1 with simplecov, get the following .resultset.json

{
  "pid_34884": {
    "coverage": {
      "C:/aaa/aa/aa.rb": {
        "lines": [
          1,
******
    "timestamp": 1615973314
  }

(2) run test2 with simplecov, get the following .resultset.json

{
  "pid_35136": {
    "coverage": {
      "C:/bb/bb/b.rb": {
        "lines": [
          1,
          1,
********** 
    "timestamp": 1615973421
  }
}

(3) then I put the these two result in two directory: --coverage1     |-- asserts     |-- .last_run.json     |-- .resultset.json     |-- .resultset.json.locl     |-- index.html --coverage2     |-- asserts     |--.last_run.json     |-- .resultset.json     |-- .resultset.json.locl     |-- index.html

(4) in ruby run SimpleCov.collate Dir["coverage*/.resultset.json"], it print: Coverage report generated for pid_34884, pid_35136 to D:/merge/coverage. 0 / 0 LOC (100.0%) covered.

a new coverage directoy created, but the .resultset.json is empty like below:

{
  "pid_34884, pid_35136": {
    "coverage": {
    },
    "timestamp": 1616051300
  }
}

ruby version: ruby 2.6.3p62 (2019-04-16 revision 67580) [x64-mingw32] simplecov: simplecov (0.21.2) simplecov-html (0.12.3, 0.10.2) simplecov_json_formatter (0.1.2)

So, is anything wrong in my operation? or I am misunderstand the SimpleCov.collate usage?

jviney commented 3 years ago

Make sure the code is available in the same location as when the individual coverage reports were generated.

It would be nice if simplecov warned you about this.

danie1Lin commented 3 years ago

I encounter this problem too. The path you run SimpleCov.collate must equal to paths in .result.json of other coverages.

ddieulivol commented 11 months ago

Make sure the code is available in the same location as when the individual coverage reports were generated.

@jviney Is this really the only solution? Isn't there a way to just merge the .resultset.json files without having to have the entire codebase available?

aziflaj commented 1 month ago

@ddieulivol did you eventually find a workaround for having the code in the same location?

ddieulivol commented 1 month ago

@ddieulivol did you eventually find a workaround for having the code in the same location?

Sadly no 😢

PragTob commented 3 weeks ago

:wave:

It's likely to be the only solution, yes.

The reasoning is that collate - if I recall correctly - does also do out of the post processing. The individual files are missing things like ignores and the simplecov configuration - and so it needs access to them for this.

A warning about this may be nice, I agree.