allow skipping (unreachable) branch coverage only
akostadinov opened this issue · 10 comments
Hello, I would like to be able to skip some unreachable branches but I only see full coverage skipping with nocov
.
For example the following code will report the else
is never run but it is unreachable:
match = match = /^(\d+)([abc])$/.match(str)
raise unless match
case match[2]
when "a"
...
when "b"
...
when "c"
...
end
Is there another tag or can such be implemented that will only ignore branch coverage?
You can ignore that implicit branch like this:
case match[2]
when "a"
...
when "b"
...
when "c"
...
else
:nocov:
nil
:nocov:
end
Ok, thank you! Somehow not ideal but also I don't see any better way :)
Yep, you also can actually cover that branch if you want 👍
What do you mean with cover? raise
or cover as in tests?
I mean you may write a unit test where that normally unreachable branch is tested (and it may contain something like raise "Invalid something whatever"
.
I can't reach it because it will not match the RE
and will fail earlier than the case
statement.
Is syntax for skipping branch correct??
:nocov:
nil
:nocov:
or am I missing something here?
My bad, its
# :nocov:
nil
# :nocov:
Any thoughts of allowing # :nocov:
as a suffix to a line?
case match[2]
...
else
nil # :nocov:
end
or even
case match[2]
...
else nil # :nocov:
end
This would be great to have because then there's not extra lines of code just to mark a case as unreachable. If interested, I could spend some time developing a patch for this.