summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compile.c5
-rw-r--r--test/coverage/test_coverage.rb30
2 files changed, 34 insertions, 1 deletions
diff --git a/compile.c b/compile.c
index f6d8964fbb..7bfca53055 100644
--- a/compile.c
+++ b/compile.c
@@ -6310,14 +6310,17 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popp
}
case NODE_PRELUDE:{
const rb_compile_option_t *orig_opt = ISEQ_COMPILE_DATA(iseq)->option;
+ VALUE orig_cov = ISEQ_COVERAGE(iseq);
+ rb_compile_option_t new_opt = *orig_opt;
if (node->nd_orig) {
- rb_compile_option_t new_opt = *orig_opt;
rb_iseq_make_compile_option(&new_opt, node->nd_orig);
ISEQ_COMPILE_DATA(iseq)->option = &new_opt;
}
+ if (!new_opt.coverage_enabled) ISEQ_COVERAGE_SET(iseq, Qfalse);
CHECK(COMPILE_POPPED(ret, "prelude", node->nd_head));
CHECK(COMPILE_(ret, "body", node->nd_body, popped));
ISEQ_COMPILE_DATA(iseq)->option = orig_opt;
+ ISEQ_COVERAGE_SET(iseq, orig_cov);
break;
}
case NODE_LAMBDA:{
diff --git a/test/coverage/test_coverage.rb b/test/coverage/test_coverage.rb
index 0753ccddc5..0fa8f9bd63 100644
--- a/test/coverage/test_coverage.rb
+++ b/test/coverage/test_coverage.rb
@@ -119,4 +119,34 @@ class TestCoverage < Test::Unit::TestCase
end
assert_include Coverage.result, "<compiled>"
end
+
+ def test_eval
+ bug13305 = '[ruby-core:80079] [Bug #13305]'
+ loaded_features = $".dup
+
+ Dir.mktmpdir {|tmp|
+ Dir.chdir(tmp) {
+ File.open("test.rb", "w") do |f|
+ f.puts 'REPEATS = 400'
+ f.puts 'def add_method(target)'
+ f.puts ' REPEATS.times do'
+ f.puts ' target.class_eval(<<~RUBY, __FILE__, __LINE__ + 1)'
+ f.puts ' def foo'
+ f.puts ' #{"\n" * rand(REPEATS)}'
+ f.puts ' end'
+ f.puts ' 1'
+ f.puts ' RUBY'
+ f.puts ' end'
+ f.puts 'end'
+ end
+
+ Coverage.start
+ require tmp + '/test.rb'
+ add_method(Class.new)
+ assert_equal Coverage.result[tmp + "/test.rb"], [1, 1, 1, 400, nil, nil, nil, nil, nil, nil, nil], bug13305
+ }
+ }
+ ensure
+ $".replace loaded_features
+ end
end unless ENV['COVERAGE']