Skip to content

Fix unloaded files merge - #436

Closed
hugopeixoto wants to merge 2 commits into
simplecov-ruby:masterfrom
hugopeixoto:fix-unloaded-files-merge
Closed

hugopeixoto wants to merge 2 commits into
simplecov-ruby:masterfrom
hugopeixoto:fix-unloaded-files-merge

Conversation

@hugopeixoto

Copy link
Copy Markdown
Contributor

A test case and an attempt at fixing #433

When merging two test suites, it might be the case that some
files are loaded by one suite and not loaded by the other one.

Whenever this happens, the "never" lines from the test suite that
loaded the file should trump the "uncovered" lines from the test
suite that didn't.

This commit solves that by giving higher precedence to `nil` values
when merging.
@xaviershay

Copy link
Copy Markdown
Collaborator

I'm not familiar enough to review this properly - the model seems weird but this change seems reasonable without a more extensive refactoring (if that's even appropriate).

Will wait for either someone else to chime in or a confirmation that this has fixed #433 before merging.

Thank you!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change the existing behavior?
This will occur a problem when we run the tests in parallel. Because covered line become a disabled line.

@bfontaine

Copy link
Copy Markdown

Just FYI there’s a different fix for the same issue:

diff --git i/lib/simplecov/merge_helpers.rb w/lib/simplecov/merge_helpers.rb
index 339210d1..ca6b8a9f 100644
--- i/lib/simplecov/merge_helpers.rb
+++ w/lib/simplecov/merge_helpers.rb
@@ -2,6 +2,12 @@ module SimpleCov
   module ArrayMergeHelper
     # Merges an array of coverage results with self
     def merge_resultset(array)
+      # Don't merge with all-zero array to preserve nil values from actual runs.
+      if size == array.size
+        return array.dup if all? { |el| el == 0 }
+        return dup if array.all? { |el| el == 0 }
+      end
+
       new_array = dup
       array.each_with_index do |element, i|
         if element.nil? && new_array[i].nil?

See Homebrew/legacy-homebrew#48250 (comment).

@xaviershay

Copy link
Copy Markdown
Collaborator

Closing in favour of #441

@xaviershay xaviershay closed this Feb 24, 2016
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

Successfully merging this pull request may close these issues.

4 participants