From 645703a7fb1a692f0b8ee32fcaa65a306a1dd51f Mon Sep 17 00:00:00 2001 From: Kasumi Hanazuki Date: Fri, 17 Jun 2016 18:27:43 +0900 Subject: [PATCH 1/2] Add test cases for merge_helpers Proper merging of a file which is only available on one of the two merged resultset --- spec/merge_helpers_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/merge_helpers_spec.rb b/spec/merge_helpers_spec.rb index a9fa5f65..af971ac4 100644 --- a/spec/merge_helpers_spec.rb +++ b/spec/merge_helpers_spec.rb @@ -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 = { @@ -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 @@ -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 From cfab71d0a7d890f1d79feef04c73111232de0991 Mon Sep 17 00:00:00 2001 From: Kasumi Hanazuki Date: Fri, 17 Jun 2016 18:53:56 +0900 Subject: [PATCH 2/2] Fix merger of coverage when a file is not available in all of the resultsets --- lib/simplecov/merge_helpers.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/simplecov/merge_helpers.rb b/lib/simplecov/merge_helpers.rb index d3577922..095e3469 100644 --- a/lib/simplecov/merge_helpers.rb +++ b/lib/simplecov/merge_helpers.rb @@ -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