Skip to content

Multi-line statements not being counted accurately #394

Closed

Description

@adampope

I'm using 0.10 on a Rails 4.2 project with ruby 2.0.0-p643. I'm seeing lots of occurrences of statements that span multiple lines not being counted as covered, or only 1 or the multiple lines being counted. For example, I have a concern which is completely tested but reports as 77%.

screen shot 2015-06-11 at 10 12 41

If I simply reformat the code onto single lines I get 100% coverage.

screen shot 2015-06-11 at 10 19 09

Activity

  1. bf4 commented on Jun 11, 2015

    @bf4
    Collaborator

    so that we can reproduce this, can you provide a small snippet of the code and tests that create this bug? It would be of great help.

  2. adampope commented on Jun 18, 2015

    @adampope
    Author

    @bf4 I've created a repo with the code to reproduce this in (https://github.com/adampope/simplecov-multi-line-repro). In doing so I've found the cause. We are using the following snippet in test_helper.rb (from #16) to make sure that all files are loaded:

      all_files = Dir['**/*.rb']
      base_result = {}
      all_files.each do |file|
        absolute = File::expand_path(file)
        lines = File.readlines(absolute, :encoding => 'UTF-8')
        base_result[absolute] = lines.map do |l|
          l.strip!
          l.empty? || l =~ /^else$/ || l =~ /^end$/ || l[0] == '#' ? nil : 0
        end
      end
    
      SimpleCov.at_exit do
        merged = SimpleCov::Result.new(Coverage.result).original_result.merge_resultset(base_result)
        result = SimpleCov::Result.new(merged)
        result.format!
      end
    

    With that code multi-line statements do not get counted correctly.

    With

    screen shot 2015-06-18 at 09 59 44

    Without

    screen shot 2015-06-18 at 09 59 18

    Any ideas on ways to modify this to correctly handle the multi-line statements?

  3. adampope commented on Jun 18, 2015

    @adampope
    Author

    We found a better way of solving the problem of tracking all files, I've added a comment to #16 so I'll close this ticket.

  4. mudit-1996 commented on May 19, 2018

    @mudit-1996

    @bf4 @adampope Hey. What is the final fix for multi line statements. Please help.

  5. 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