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

Erroneous red flagging of blank lines when merging covered file results with uncovered file results #444

Closed
ksmurphy opened this issue Jan 8, 2016 · 5 comments

Comments

@ksmurphy
Copy link

ksmurphy commented Jan 8, 2016

SimpleCov 0.11.1: This error occurs when using rspec and cucumber in two different runs and expecting them to be properly merged and an accurate map displayed. I'm confident it occurs in similar situations as well.

To reproduce:

  1. Run rspec tests using SimpleCov such that it will flag some of the lines in a ruby file as having been executed.
  2. Run cucumber using SimpleCov such that that same ruby file is covered, but no lines in it are actually executed.
  3. Note that in .resultset.json the rspec section for this ruby file consists of nil, 0 and 1 values, while the cucumber section for this file consists of all 0's.
  4. Note that the resultant report, showing the merged results, highlights all non-executed lines of code in red, including blank and comment lines. Obviously the file and project test coverage stats are also wrong.

I believe this is because of faulty logic in line 7 of lib/simplecov/merge_helpers.rb. It reads
if element.nil? && new_array[i].nil?
when it should read
if element.nil? || new_array[i].nil?

The original logic (see context) allows a 0 to wipe out the nil which serves as a comment indicator, erroneously replacing it with a 0, resulting in erroneous red highlighting of comments and blank lines.

You can create a logic table to see why the original code is faulty and this fix corrects it.

When I make this change the error goes away.

If I get time I'll make this correction and submit a PR. But I wanted others to know about this in case they need a quick fix before I can get to it.

You can just edit the code in place for a quick fix. You can do a "gem which simplecov" on your console to find the code location.

@danishsatkut
Copy link

This is definitely an issue and the provided solution works. Thanks 💯

@chriskottom
Copy link

+1 for this fix. It seems to have worked in my env - Ruby 2.2.3, SimpleCov 0.11.2.

@rdunlop
Copy link

rdunlop commented Mar 11, 2016

I suspect that this is fixed by #441

@fighterii
Copy link

I can confirm that the fix suggested did it for me

iNecas added a commit to iNecas/foreman that referenced this issue May 2, 2016
To get the results, one needs to:

for x in test:units test:lib test:functionals test:integration; do
   export SIMPLE_COV_NAME=$x; bundle exec rake $x;
end

We need to use older simplecov, as newer one has issue when merging
the coverage results simplecov-ruby/simplecov#444
jwworth added a commit to hashrocket/hr-til that referenced this issue Jul 25, 2016
@PragTob
Copy link
Collaborator

PragTob commented Jan 29, 2017

Seems this was fixed by #441 - thanks! :)

@PragTob PragTob closed this as completed Jan 29, 2017
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

6 participants