From 7e50f2437baf8bf7dcbccaa2eb092964980614a5 Mon Sep 17 00:00:00 2001 From: OKURA Masafumi Date: Tue, 23 Apr 2024 02:06:27 +0900 Subject: [PATCH] Add spec to the result of Coverage lib for `begin` Ref: https://github.com/jruby/jruby/issues/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. --- library/coverage/fixtures/code_with_begin.rb | 3 +++ library/coverage/result_spec.rb | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 library/coverage/fixtures/code_with_begin.rb diff --git a/library/coverage/fixtures/code_with_begin.rb b/library/coverage/fixtures/code_with_begin.rb new file mode 100644 index 0000000000..9a6384e337 --- /dev/null +++ b/library/coverage/fixtures/code_with_begin.rb @@ -0,0 +1,3 @@ +begin + 'coverage with begin' +end diff --git a/library/coverage/result_spec.rb b/library/coverage/result_spec.rb index 33276778e8..54a3249e45 100644 --- a/library/coverage/result_spec.rb +++ b/library/coverage/result_spec.rb @@ -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 @@ -16,6 +17,7 @@ $LOADED_FEATURES.delete(@class_file) $LOADED_FEATURES.delete(@config_file) $LOADED_FEATURES.delete(@eval_code_file) + $LOADED_FEATURES.delete(@with_begin_file) Coverage.result if Coverage.running? end @@ -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