Skip to content

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

Closed

Description

@ksmurphy

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.

Activity

  1. danishsatkut commented on Jan 12, 2016

    @danishsatkut

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

  2. chriskottom commented on Feb 17, 2016

    @chriskottom

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

  3. rdunlop commented on Mar 11, 2016

    @rdunlop

    I suspect that this is fixed by #441

  4. fighterii commented on Mar 24, 2016

    @fighterii

    I can confirm that the fix suggested did it for me

  5. added a commit that references this issue on Jul 25, 2016
  6. PragTob commented on Jan 29, 2017

    @PragTob
    Collaborator

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

  7. added theissue type on May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions