summaryrefslogtreecommitdiff
path: root/test/json/test_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/json/test_helper.rb')
-rw-r--r--test/json/test_helper.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/json/test_helper.rb b/test/json/test_helper.rb
index d849e28b9b..4c5a91a192 100644
--- a/test/json/test_helper.rb
+++ b/test/json/test_helper.rb
@@ -1,5 +1,30 @@
$LOAD_PATH.unshift(File.expand_path('../../../ext', __FILE__), File.expand_path('../../../lib', __FILE__))
+if ENV["JSON_COVERAGE"]
+ # This test helper is loaded inside Ruby's own test suite, so we try to not mess it up.
+ require 'coverage'
+
+ 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)
+
+ require 'simplecov'
+ 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'
+ add_filter 'test/'
+ end
+end
+
require 'json'
require 'test/unit'