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 coverage rate of the parallel_tests #441

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions lib/simplecov/merge_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ module ArrayMergeHelper
def merge_resultset(array)
new_array = dup
array.each_with_index do |element, i|
if element.nil? && new_array[i].nil?
new_array[i] = nil
else
local_value = element || 0
other_value = new_array[i] || 0
new_array[i] = local_value + other_value
end
pair = [element, new_array[i]]
new_array[i] = if pair.any?(&:nil?) && pair.map(&:to_i).all?(&:zero?)
Copy link
Collaborator

Choose a reason for hiding this comment

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

so, the change is

- result is `nil` if the element in both sets is nil
+ result is `nil` if either set contains nil AND both are each one of either nil, zero, or some non-integer?

and then the merge result is (LHS || 0) + (RHS || 0)

as the test shows

result1      = [nil,   0, nil, 0]
result2      = [nil, nil,   0, 0]
merge_result = [nil, nil, nil, 0]

nil
else
element.to_i + new_array[i].to_i
end
end
new_array
end
Expand Down
6 changes: 6 additions & 0 deletions spec/merge_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
source_fixture("app/models/user.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
source_fixture("app/controllers/sample_controller.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
source_fixture("resultset1.rb") => [1, 1, 1, 1],
source_fixture("parallel_tests.rb") => [nil, 0, nil, 0],
}.extend(SimpleCov::HashMergeHelper)

@resultset2 = {
source_fixture("sample.rb") => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil],
source_fixture("app/models/user.rb") => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil],
source_fixture("app/controllers/sample_controller.rb") => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil],
source_fixture("resultset2.rb") => [nil, 1, 1, nil],
source_fixture("parallel_tests.rb") => [nil, nil, 0, 0],
}
end

Expand Down Expand Up @@ -43,6 +45,10 @@
it "has proper results for resultset2.rb" do
expect(subject[source_fixture("resultset2.rb")]).to eq([nil, 1, 1, nil])
end

it "has proper results for parallel_tests.rb" do
expect(subject[source_fixture("parallel_tests.rb")]).to eq([nil, nil, nil, 0])
end
end

# See Github issue #6
Expand Down