summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Miller <robin@tenjin.ca>2025-09-13 16:11:20 -0600
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2025-09-19 19:30:10 +0900
commit77cd19658903a4b6b0e69ffb0a6d0860b9fa3cbd (patch)
treec91873140cf7dfcedcc2c54225f028311c336526
parent3faf2a31fb49ed56bd550ff4c10d538b9882c099 (diff)
[ruby/json] Add branch test coverage when available. Force track all files to prevent implicit file discovery missing files.
https://github.com/ruby/json/commit/6bded942c4
-rw-r--r--test/json/test_helper.rb19
1 files changed, 17 insertions, 2 deletions
diff --git a/test/json/test_helper.rb b/test/json/test_helper.rb
index a788804dde..24d98170bb 100644
--- a/test/json/test_helper.rb
+++ b/test/json/test_helper.rb
@@ -1,14 +1,29 @@
$LOAD_PATH.unshift(File.expand_path('../../../ext', __FILE__), File.expand_path('../../../lib', __FILE__))
require 'coverage'
-Coverage.start
+
+branches_supported = Coverage.respond_to?(:supported?) && Coverage.supported?(:branches)
+
+# Coverage module must be started before SimpleCov to work around the cyclic require order.
+# Track both branches and lines, or else SimpleCov misleadingly reports 0/0 = 100% for non-branching files.
+Coverage.start(lines: true,
+ branches: branches_supported)
begin
require 'simplecov'
rescue LoadError
# Don't fail Ruby's test suite
else
- SimpleCov.start
+ SimpleCov.start do
+ # Enabling both coverage types to let SimpleCov know to output them together in reports
+ enable_coverage :line
+ enable_coverage :branch if branches_supported
+
+ # Can't always trust SimpleCov to find files implicitly
+ track_files 'lib/**/*.rb'
+
+ add_filter 'lib/json/truffle_ruby' unless RUBY_ENGINE == 'truffleruby'
+ end
end
require 'json'