Skip to content

Commit

Permalink
Merge pull request #513 from hanazuki/fix-merging
Browse files Browse the repository at this point in the history
Fix merging of result sets for unloaded files
  • Loading branch information
sferik authored Jul 13, 2016
2 parents e0accd6 + cfab71d commit 257e263
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/simplecov/merge_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ module HashMergeHelper
def merge_resultset(hash)
new_resultset = {}
(keys + hash.keys).each do |filename|
new_resultset[filename] = []
new_resultset[filename] = nil
end

new_resultset.each_key do |filename|
new_resultset[filename] = (self[filename] || []).extend(SimpleCov::ArrayMergeHelper).merge_resultset(hash[filename] || [])
result1 = self[filename]
result2 = hash[filename]
new_resultset[filename] =
(result1 && result2) ? result1.extend(ArrayMergeHelper).merge_resultset(result2) : (result1 || result2).dup
end
new_resultset
end
Expand Down
10 changes: 10 additions & 0 deletions spec/merge_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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],
source_fixture("conditionally_loaded_1.rb") => [nil, 0, 1], # loaded only in the first resultset
}.extend(SimpleCov::HashMergeHelper)

@resultset2 = {
Expand All @@ -18,6 +19,7 @@
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],
source_fixture("conditionally_loaded_2.rb") => [nil, 0, 1], # loaded only in the second resultset
}
end

Expand Down Expand Up @@ -49,6 +51,14 @@
it "has proper results for parallel_tests.rb" do
expect(subject[source_fixture("parallel_tests.rb")]).to eq([nil, nil, nil, 0])
end

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

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

# See Github issue #6
Expand Down

0 comments on commit 257e263

Please sign in to comment.