Skip to content

Commit

Permalink
apply simplecov fix in an overlay patch
Browse files Browse the repository at this point in the history
  • Loading branch information
p committed Jan 7, 2025
1 parent 2fcde66 commit a8513c3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
if (ENV['SKIP_SIMPLECOV'] != '1') && !RSpec.configuration.files_to_run.all? { |path| path.include?('/benchmark/') }
# +SimpleCov.start+ must be invoked before any application code is loaded
require 'simplecov'
require 'support/simplecov_fix'
SimpleCov.start do
formatter SimpleCov::Formatter::SimpleFormatter
end
Expand Down
30 changes: 30 additions & 0 deletions spec/support/simplecov_fix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Overlay patch fix for https://github.com/simplecov-ruby/simplecov/pull/972.
#
# simplecov supports branch coverage only on some Ruby runtimes (for example,
# not on JRuby). However, when merging coverage reports across runs,
# simplecov assumes that branch coverage is always present.
# This causes merging to fail when the runs are on different Ruby runtimes
# as well as when merging on JRuby.
#
# Upstream has not fixed the issue in 3+ years (PR opened in 2021).
#
# dd-trace-rb has been using a fork of simplecov with this fix, however
# this is awkward because bundler insists on constantly installing the fork
# even though nothing in it or related to it changed.
#
# This file now brings the patch into our tree, permitting us to use any
# released version of simplecov and removing the need to reference a fork.

module SimpleCovCombineFix
def combine(coverage_a, coverage_b)
super.tap do |result|
if SimpleCov.branch_coverage?
result['branches'] ||= {}
end
end
end
end

class << SimpleCov::Combine::FilesCombiner
prepend(SimpleCovCombineFix)
end

0 comments on commit a8513c3

Please sign in to comment.