Skip to content

Commit

Permalink
Add spec to the result of Coverage lib for begin
Browse files Browse the repository at this point in the history
Ref: jruby/jruby#8173
This commit is intended to make sure `Coverage` library behaves
the same for the code with `begin`. JRuby had an issue so this
change will help JRuby and other implementations to avoid it.
  • Loading branch information
okuramasafumi committed Jun 23, 2024
1 parent 1afa2ea commit b7a55d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions library/coverage/fixtures/code_with_begin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
begin
'coverage with begin'
end
14 changes: 14 additions & 0 deletions library/coverage/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@class_file = fixture __FILE__, 'some_class.rb'
@config_file = fixture __FILE__, 'start_coverage.rb'
@eval_code_file = fixture __FILE__, 'eval_code.rb'
@with_begin_file = fixture __FILE__, 'code_with_begin.rb'
end

before :each do
Expand All @@ -16,6 +17,7 @@
$LOADED_FEATURES.delete(@class_file)
$LOADED_FEATURES.delete(@config_file)
$LOADED_FEATURES.delete(@eval_code_file)
$LOADED_FEATURES.delete(@file)

Coverage.result if Coverage.running?
end
Expand Down Expand Up @@ -354,4 +356,16 @@

Coverage.peek_result.should == result
end

it 'covers 100% lines with begin' do
Coverage.start
require @with_begin_file.chomp('.rb')
result = Coverage.result

result.should == {
@with_begin_file => [
nil, 1, nil
]
}
end
end

0 comments on commit b7a55d3

Please sign in to comment.