Skip to content

Commit 1347131

Browse files
byroothsbt
authored andcommitted
[ruby/json] Only enable test coverage when running the test suite standalone
ruby/json@08b9eb0ee6
1 parent 77cd196 commit 1347131

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

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)