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

Feature request: Condition plus branch coverage #561

Open
IndrajeetPatil opened this issue Mar 7, 2024 · 1 comment
Open

Feature request: Condition plus branch coverage #561

IndrajeetPatil opened this issue Mar 7, 2024 · 1 comment

Comments

@IndrajeetPatil
Copy link

Preamble

Consider the following code and its corresponding test:

empty <- function(df) {
  (is.null(df) || nrow(df) == 0 || ncol(df) == 0)
}

test_that("empty works", {
  expect_true(empty(NULL))
})

If you use {covr} to compute code coverage for a package that contains this function, it will be 100%.
But, note that the test covers only one of the conditions from the control statement (is.null(df)); the other two are untested and may contain bugs.

FR

Is it possible for {covr} to also take into account all conditions—either on the same line or on different lines—while computing code coverage?

With such an update, in the example above, the code coverage should be 0% because the tests don't fully cover all the conditions on that line. I am not sure what should happen if the conditional statement spans multiple lines, but I can see how 0% could be reasonable in that case as well.

Related to, but still distinct from #279

@radbasa
Copy link
Contributor

radbasa commented Mar 15, 2024

This is not really distinct from #279. It's still about how R creates srcrefs. #279 (comment)

Your conditional statement is seen by R as one expression. There are no branches. Hence, covr sees it as one expression. You can try to wrap each of your conditionals with curly braces and separate them into new lines if you want.

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

2 participants