From 50dfd09558c78ab46bd232d41b8c70a79127d6f0 Mon Sep 17 00:00:00 2001 From: Scott Yang Date: Tue, 6 Feb 2024 09:23:51 -0800 Subject: [PATCH] ignore nil branches during combine --- lib/simplecov/combine/files_combiner.rb | 5 ++++- spec/combine/results_combiner_spec.rb | 14 +++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/simplecov/combine/files_combiner.rb b/lib/simplecov/combine/files_combiner.rb index 32df1184..06dfbf61 100644 --- a/lib/simplecov/combine/files_combiner.rb +++ b/lib/simplecov/combine/files_combiner.rb @@ -16,7 +16,10 @@ module FilesCombiner # def combine(coverage_a, coverage_b) combination = {"lines" => Combine.combine(LinesCombiner, coverage_a["lines"], coverage_b["lines"])} - combination["branches"] = Combine.combine(BranchesCombiner, coverage_a["branches"], coverage_b["branches"]) if SimpleCov.branch_coverage? + if SimpleCov.branch_coverage? + branches = Combine.combine(BranchesCombiner, coverage_a["branches"], coverage_b["branches"]) + combination["branches"] = branches unless branches.nil? + end combination end end diff --git a/spec/combine/results_combiner_spec.rb b/spec/combine/results_combiner_spec.rb index 05e1b55e..3b10e6b5 100644 --- a/spec/combine/results_combiner_spec.rb +++ b/spec/combine/results_combiner_spec.rb @@ -75,31 +75,31 @@ end it "has proper results for sample_controller.rb" do - expect(subject[source_fixture("app/controllers/sample_controller.rb")]["lines"]).to eq([nil, 4, 2, 1, nil, nil, 2, 0, nil, nil]) + expect(subject[source_fixture("app/controllers/sample_controller.rb")]).to eq({"lines" => [nil, 4, 2, 1, nil, nil, 2, 0, nil, nil]}) end it "has proper results for resultset1.rb" do - expect(subject[source_fixture("resultset1.rb")]["lines"]).to eq([1, 1, 1, 1]) + expect(subject[source_fixture("resultset1.rb")]).to eq({"lines" => [1, 1, 1, 1]}) end it "has proper results for resultset2.rb" do - expect(subject[source_fixture("resultset2.rb")]["lines"]).to eq([nil, 1, 1, nil]) + expect(subject[source_fixture("resultset2.rb")]).to eq({"lines" => [nil, 1, 1, nil]}) end it "has proper results for parallel_tests.rb" do - expect(subject[source_fixture("parallel_tests.rb")]["lines"]).to eq([nil, nil, nil, 0]) + expect(subject[source_fixture("parallel_tests.rb")]).to eq({"lines" => [nil, nil, nil, 0]}) end it "has proper results for conditionally_loaded_1.rb" do - expect(subject[source_fixture("conditionally_loaded_1.rb")]["lines"]).to eq([nil, 0, 1]) + expect(subject[source_fixture("conditionally_loaded_1.rb")]).to eq({"lines" => [nil, 0, 1]}) end it "has proper results for conditionally_loaded_2.rb" do - expect(subject[source_fixture("conditionally_loaded_2.rb")]["lines"]).to eq([nil, 0, 1]) + expect(subject[source_fixture("conditionally_loaded_2.rb")]).to eq({"lines" => [nil, 0, 1]}) end it "has proper results for three.rb" do - expect(subject[source_fixture("three.rb")]["lines"]).to eq([nil, 3, 7]) + expect(subject[source_fixture("three.rb")]).to eq({"lines" => [nil, 3, 7]}) end end end