Don't reset line coverage for evaled code. (#8330)

* Add failing test.
This commit is contained in:
Samuel Williams 2023-09-04 13:31:25 +12:00 committed by GitHub
parent 40ab77eb3d
commit 7e0f5df2f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
Notes: git 2023-09-04 01:31:46 +00:00
Merged-By: ioquatix <samuel@codeotaku.com>
2 changed files with 14 additions and 1 deletions

View File

@ -2336,7 +2336,8 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor)
!(rb_get_coverage_mode() & COVERAGE_TARGET_ONESHOT_LINES)) {
int line = iobj->insn_info.line_no - 1;
if (line >= 0 && line < RARRAY_LEN(ISEQ_LINE_COVERAGE(iseq))) {
RARRAY_ASET(ISEQ_LINE_COVERAGE(iseq), line, INT2FIX(0));
if (RARRAY_AREF(ISEQ_LINE_COVERAGE(iseq), line) == Qnil)
RARRAY_ASET(ISEQ_LINE_COVERAGE(iseq), line, INT2FIX(0));
}
}
if (ISEQ_BRANCH_COVERAGE(iseq) && (events & RUBY_EVENT_COVERAGE_BRANCH)) {

View File

@ -181,6 +181,18 @@ class TestCoverage < Test::Unit::TestCase
end;
end
def test_eval_coverage_repeated
assert_in_out_err(%w[-rcoverage], <<-"end;", ["[3]"], [])
Coverage.start(eval: true, lines: true)
3.times do
eval("Object.new", nil, "test.rb")
end
p Coverage.result["test.rb"][:lines]
end;
end
def test_coverage_supported
assert Coverage.supported?(:lines)
assert Coverage.supported?(:oneshot_lines)