Skip to content
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
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ include RbConfig
require 'rake/testtask'
class UndocumentedTestTask < Rake::TestTask
def desc(*) end

def ruby(...)
env_was = ENV["JSON_COVERAGE"]
ENV["JSON_COVERAGE"] = "1"
ret = super
ENV["JSON_COVERAGE"] = env_was
ret
end
end

PKG_VERSION = File.foreach(File.join(__dir__, "lib/json/version.rb")) do |line|
Expand Down
27 changes: 20 additions & 7 deletions test/json/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
$LOAD_PATH.unshift(File.expand_path('../../../ext', __FILE__), File.expand_path('../../../lib', __FILE__))

require 'coverage'
Coverage.start
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)

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'
Expand Down
Loading