iseq.c (finish_iseq_build): fix coverage leakage [Bug #14191]

Before this change, coverage.so had failed to measure some multiple-line
code fragments.  This is because removing trace instructions (#14104)
changed TracePoint's lineno (new lineno), and coverage counter array was
based on old lineno.
This change initializes coverage counter array based on new lineno.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2017-12-18 02:44:36 +00:00
parent fb6db414a1
commit 2e24a66b88
3 changed files with 52 additions and 11 deletions

View file

@ -201,6 +201,39 @@ class TestCoverage < Test::Unit::TestCase
}
end
def test_line_coverage_for_multiple_lines
result = {
:lines => [nil, 1, nil, nil, nil, 1, nil, nil, nil, 1, nil, 1, nil, nil, nil, nil, 1, 1, nil, 1, nil, nil, nil, nil, 1]
}
assert_coverage(<<~"end;", { lines: true }, result) # Bug #14191
FOO = [
{ foo: 'bar' },
{ bar: 'baz' }
]
'some string'.split
.map(&:length)
some =
'value'
Struct.new(
:foo,
:bar
).new
class Test
def foo(bar)
{
foo: bar
}
end
end
Test.new.foo(Object.new)
end;
end
def test_branch_coverage_for_if_statement
result = {
:branches => {