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 merging of result sets for unloaded files #513

Merged
merged 2 commits into from
Jul 13, 2016
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
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