Skip to content

Commit 6bded94

Browse files
robinetmillerbyroot
authored andcommitted
Add branch test coverage when available. Force track all files to prevent implicit file discovery missing files.
1 parent db89486 commit 6bded94

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

test/json/test_helper.rb

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

33
require 'coverage'
4-
Coverage.start
4+
5+
branches_supported = Coverage.respond_to?(:supported?) && Coverage.supported?(:branches)
6+
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)
511

612
begin
713
require 'simplecov'
814
rescue LoadError
915
# Don't fail Ruby's test suite
1016
else
11-
SimpleCov.start
17+
SimpleCov.start do
18+
# Enabling both coverage types to let SimpleCov know to output them together in reports
19+
enable_coverage :line
20+
enable_coverage :branch if branches_supported
21+
22+
# Can't always trust SimpleCov to find files implicitly
23+
track_files 'lib/**/*.rb'
24+
25+
add_filter 'lib/json/truffle_ruby' unless RUBY_ENGINE == 'truffleruby'
26+
end
1227
end
1328

1429
require 'json'

0 commit comments

Comments
 (0)