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

Fix unloaded files merge #436

Closed

Conversation

hugopeixoto
Copy link
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
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!

@@ -25,7 +25,7 @@
end

it "has proper results for sample.rb" do
expect(subject[source_fixture("sample.rb")]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil])
expect(subject[source_fixture("sample.rb")]).to eq([nil, nil, 2, 2, nil, nil, 2, 2, nil, nil])
Copy link
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

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

None yet

4 participants