diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-14 06:34:02 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-14 06:34:02 +0000 |
commit | aed655c0969baeb48f1f683ba4426ec7b7f466bb (patch) | |
tree | 937c7ce31662e9851188f3fb9088e8b045d72500 /test/coverage | |
parent | d3aa6514b455835220212298a4b189db28300c19 (diff) |
merge revision(s) 66670,66676: [Backport #15476]
compile.c: support branch coverage for `a&.foo = 1`
[Bug #15476]
compile.c (iseq_set_sequence): fix branch coverage table
Not only TRACE_ELEMENT but also INSN_ELEMENT may have events.
The old pc2branchindex was created using only events of TRACE_ELEMENTs.
This change uses events of INSN_ELEMENTs too for pc2branchindex table.
[Bug #15476]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@66813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/coverage')
-rw-r--r-- | test/coverage/test_coverage.rb | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/test/coverage/test_coverage.rb b/test/coverage/test_coverage.rb index d2a2d018a9..6a58706440 100644 --- a/test/coverage/test_coverage.rb +++ b/test/coverage/test_coverage.rb @@ -167,6 +167,20 @@ class TestCoverage < Test::Unit::TestCase end; end + def test_coverage_optimized_branch + result = { + :branches => { + [:"&.", 0, 1, 0, 1, 8] => { + [:then, 1, 1, 0, 1, 8] => 1, + [:else, 2, 1, 0, 1, 8] => 0, + }, + }, + } + assert_coverage(<<~"end;", { branches: true }, result) # Bug #15476 + nil&.foo + end; + end + def assert_coverage(code, opt, stdout) stdout = [stdout] unless stdout.is_a?(Array) stdout = stdout.map {|s| s.to_s } @@ -348,15 +362,22 @@ class TestCoverage < Test::Unit::TestCase def test_branch_coverage_for_safe_method_invocation result = { :branches=>{ - [:"&.", 0, 3, 0, 3, 6] => {[:then, 1, 3, 0, 3, 6]=>1, [:else, 2, 3, 0, 3, 6]=>0}, - [:"&.", 3, 4, 0, 4, 6] => {[:then, 4, 4, 0, 4, 6]=>0, [:else, 5, 4, 0, 4, 6]=>1}, + [:"&.", 0, 6, 0, 6, 6] => {[:then, 1, 6, 0, 6, 6]=>1, [:else, 2, 6, 0, 6, 6]=>0}, + [:"&.", 3, 7, 0, 7, 6] => {[:then, 4, 7, 0, 7, 6]=>0, [:else, 5, 7, 0, 7, 6]=>1}, + [:"&.", 6, 8, 0, 8, 10] => {[:then, 7, 8, 0, 8, 10]=>1, [:else, 8, 8, 0, 8, 10]=>0}, + [:"&.", 9, 9, 0, 9, 10] => {[:then, 10, 9, 0, 9, 10]=>0, [:else, 11, 9, 0, 9, 10]=>1}, } } assert_coverage(<<~"end;", { branches: true }, result) - a = 10 + class Dummy; def foo; end; def foo=(x); end; end + a = Dummy.new b = nil - a&.abs - b&.hoo + c = Dummy.new + d = nil + a&.foo + b&.foo + c&.foo = 1 + d&.foo = 1 end; end |