Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow skipping (unreachable) branch coverage only #1055

Open
akostadinov opened this issue Mar 28, 2023 · 10 comments
Open

allow skipping (unreachable) branch coverage only #1055

akostadinov opened this issue Mar 28, 2023 · 10 comments

Comments

@akostadinov
Copy link

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?

@tycooon
Copy link

tycooon commented Mar 28, 2023

You can ignore that implicit branch like this:

case match[2]
when "a"
...
when "b"
...
when "c"
...
else
  :nocov:
  nil
  :nocov:
end

@akostadinov
Copy link
Author

Ok, thank you! Somehow not ideal but also I don't see any better way :)

@tycooon
Copy link

tycooon commented Mar 28, 2023

Yep, you also can actually cover that branch if you want 👍

@akostadinov
Copy link
Author

What do you mean with cover? raise or cover as in tests?

@tycooon
Copy link

tycooon commented Mar 28, 2023

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".

@akostadinov
Copy link
Author

I can't reach it because it will not match the RE and will fail earlier than the case statement.

@sudeeptarlekar
Copy link

Is syntax for skipping branch correct??

:nocov:
nil
:nocov:

or am I missing something here?

@sudeeptarlekar
Copy link

My bad, its

# :nocov:
nil
# :nocov:

@win93
Copy link

win93 commented Dec 17, 2023

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.

@tycooon
Copy link

tycooon commented Dec 18, 2023

@win93 there is a PR for that #1068.
Unfortunately, maintainers have been mostly inactive lately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants