testit icon indicating copy to clipboard operation
testit copied to clipboard

covr does not correctly interact with testit multiple line check

Open tomasruizt opened this issue 4 years ago • 1 comments

Hi, not sure if this is really an error, but it seems to me like testit would intend to support this common setup:

  • testthat for unit tests
  • testit for runtime assertions in functions
  • covr for code coverage

The setup works well unless I use testit::assert on several lines, like in the testit README file

Example: file R/myfuncs.R

failFunc <- function() {
    assert("Foo", {
        (FALSE == TRUE)
        (TRUE == TRUE)
    })
}

test file tests/testthat/test.myfuncs.R

test_that("failFunc fails", {
     expect_error(failFunc())
})

when running devtools:test() the test passes as expected. However, with the command covr::package_coverage() the test does not pass, apparently because the first assertion (FALSE == TRUE) is not evaluated. Changing the function fixes this, but is not in the spirit of testit:

failFunc <- function() {
    assert("Foo", {
        (FALSE == TRUE) &&
        (TRUE == TRUE)
    })
}

Not sure if this is related to the way covr works or is part of the testit internals.

tomasruizt avatar Jun 30 '20 09:06 tomasruizt

This is far beyond my expertise, so I don't know. Sorry.

yihui avatar Jun 30 '20 19:06 yihui