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 for: Merging two resultsets marks uncovered line as irrelevant #518

Closed
wants to merge 3 commits into from
Closed
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
8 changes: 3 additions & 5 deletions lib/simplecov/merge_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module SimpleCov
module ArrayMergeHelper
# Merges an array of coverage results with self
def merge_resultset(array)
return array if empty?
new_array = dup
array.each_with_index do |element, i|
pair = [element, new_array[i]]
Expand All @@ -22,14 +23,11 @@ module HashMergeHelper
def merge_resultset(hash)
new_resultset = {}
(keys + hash.keys).each do |filename|
new_resultset[filename] = nil
new_resultset[filename] = []
end

new_resultset.each_key do |filename|
result1 = self[filename]
result2 = hash[filename]
new_resultset[filename] =
(result1 && result2) ? result1.extend(ArrayMergeHelper).merge_resultset(result2) : (result1 || result2).dup
new_resultset[filename] = (self[filename] || []).extend(SimpleCov::ArrayMergeHelper).merge_resultset(hash[filename] || [])
end
new_resultset
end
Expand Down
35 changes: 35 additions & 0 deletions spec/merge_helpers_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
require "helper"

describe "merge helpers" do
describe SimpleCov::ArrayMergeHelper do
before { SimpleCov.use_merging true }

def merge(values_1, values_2)
values_1.extend(SimpleCov::ArrayMergeHelper).merge_resultset(values_2)
end

context "numbers get added" do
it { expect(merge([0], [0])).to eq [0] }
it { expect(merge([1], [0])).to eq [1] }
it { expect(merge([0], [1])).to eq [1] }
it { expect(merge([1], [1])).to eq [2] }
it { expect(merge([9], [9])).to eq [9 + 9] }
end
context "numbers and nil" do
it { expect(merge([0], [nil])).to eq [nil] }
it { expect(merge([1], [nil])).to eq [1] }
it { expect(merge([2], [nil])).to eq [2] }
it { expect(merge([nil], [0])).to eq [nil] }
it { expect(merge([nil], [1])).to eq [1] }
it { expect(merge([nil], [2])).to eq [2] }
end
context "numbers and empty" do
it { expect(merge([nil], [])).to eq [nil] }
it { expect(merge([0], [])).to eq [0] }
it { expect(merge([1], [])).to eq [1] }
it { expect(merge([2], [])).to eq [2] }

it { expect(merge([], [nil])).to eq [nil] }
it { expect(merge([], [0])).to eq [0] }
it { expect(merge([], [1])).to eq [1] }
it { expect(merge([], [2])).to eq [2] }
end
end

describe "with two faked coverage resultsets" do
before do
SimpleCov.use_merging true
Expand Down