Skip to content

Commit 08b9eb0

Browse files
committed
Only enable test coverage when running the test suite standalone
1 parent 6bded94 commit 08b9eb0

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

Rakefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ include RbConfig
66
require 'rake/testtask'
77
class UndocumentedTestTask < Rake::TestTask
88
def desc(*) end
9+
10+
def ruby(...)
11+
env_was = ENV["JSON_COVERAGE"]
12+
ENV["JSON_COVERAGE"] = "1"
13+
ret = super
14+
ENV["JSON_COVERAGE"] = env_was
15+
ret
16+
end
917
end
1018

1119
PKG_VERSION = File.foreach(File.join(__dir__, "lib/json/version.rb")) do |line|

test/json/test_helper.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
$LOAD_PATH.unshift(File.expand_path('../../../ext', __FILE__), File.expand_path('../../../lib', __FILE__))
22

3-
require 'coverage'
3+
if ENV["JSON_COVERAGE"]
4+
# This test helper is loaded inside Ruby's own test suite, so we try to not mess it up.
5+
require 'coverage'
46

5-
branches_supported = Coverage.respond_to?(:supported?) && Coverage.supported?(:branches)
7+
branches_supported = Coverage.respond_to?(:supported?) && Coverage.supported?(:branches)
68

7-
# Coverage module must be started before SimpleCov to work around the cyclic require order.
8-
# Track both branches and lines, or else SimpleCov misleadingly reports 0/0 = 100% for non-branching files.
9-
Coverage.start(lines: true,
10-
branches: branches_supported)
9+
# Coverage module must be started before SimpleCov to work around the cyclic require order.
10+
# Track both branches and lines, or else SimpleCov misleadingly reports 0/0 = 100% for non-branching files.
11+
Coverage.start(lines: true,
12+
branches: branches_supported)
1113

12-
begin
1314
require 'simplecov'
14-
rescue LoadError
15-
# Don't fail Ruby's test suite
16-
else
1715
SimpleCov.start do
1816
# Enabling both coverage types to let SimpleCov know to output them together in reports
1917
enable_coverage :line

0 commit comments

Comments
 (0)