Project

General

Profile

Actions

Bug #15980

closed

Coverage shows while/until after raise if/unless as uncovered line

Added by jeremyevans0 (Jeremy Evans) over 4 years ago. Updated about 3 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.7.0dev (2019-07-03) [x86_64-openbsd6.5]
[ruby-core:93508]

Description

The following code shows line 2 (while true) as uncovered:

raise if 1 == 2
while true
  break
end

Coverage reports the following for this file: [1, 0, 1, nil]. Note that true isn't important, any while condition will work. However, if you change line 1 to raise if false, line 1 shows nil coverage, and line 2 shows as covered ([nil, 1, 1, nil]). That leads me to believe this issue is related to the optimizer.

I bisected this to 100bf2757468439106775a7d95a791a8c10b874a, which certainly appears related.

This is not a theoretical case, it affected three lines in Sequel. While not a major problem, I do think a fix should be backported to 2.6.

Note that this only affects line coverage. Branch coverage shows:

{"file.rb"=>
  {:branches=>
    {[:if, 0, 1, 0, 1, 15]=>
      {[:then, 1, 1, 0, 1, 5]=>0, [:else, 2, 1, 0, 1, 15]=>1},
     [:while, 3, 2, 0, 4, 3]=>{[:body, 4, 3, 2, 3, 7]=>1}}}}

If you run with both branch and line coverage, line coverage shows correctly.

This affects while/until after a line with raise ... if ... or raise ... unless .... If you switch to if ...; raise ...; end, then line coverage shows correctly.


Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Bug #16397: Line coverage is broken for until and while after guard clauseClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0