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

Multi-line statements not being counted accurately #394

Closed
adampope opened this issue Jun 11, 2015 · 4 comments
Closed

Multi-line statements not being counted accurately #394

adampope opened this issue Jun 11, 2015 · 4 comments

Comments

@adampope
Copy link

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

@bf4
Copy link
Collaborator

bf4 commented Jun 11, 2015

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.

@adampope
Copy link
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?

@adampope
Copy link
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.

@mudit-1996
Copy link

mudit-1996 commented May 19, 2018

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

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

3 participants