How to create expectations in testthat?

A naive approach to writing custom expectations from existing expectations:

expect_between <- function (x, lo, hi) {
    expect_lte(lo, x)
    expect_lte(x, hi)
}

      

but that doesn't work with expect_failure

since it expect_failure

captures the first wait.

expect_between(0.5, 0, 1)                  # PASSES
expect_between(-99, 0, 1)                  # FAILS
expect_between(99, 0, 1)                   # FAILS
expect_failure(expect_between(-99, 0, 1))  # PASSES
expect_failure(expect_between(99, 0, 1))   # FAILS <--- the problem

      

What is the correct way to make expectations when writing custom expectations so that they still play well with expect_failure

?

+3
r testthat


source to share


No one has answered this question yet

Check out similar questions:

2474
How to make a great R reproducible example
1251
How to sort a data frame by multiple columns
629
data.table vs dplyr: can something do good and other do bad or bad?
333
How do I trim leading and trailing spaces?
18
How to set up testthat to check R CMD?
five
testthat failure using check ()
4
R tryCatch with testthat waiting
4
How do you test user expectation?
2
With Roxygen and testthat, what is the proper way to make internal helper functions available to testboxes called during R CMD validation?
1
testthat error on check () but not on test () due to ~ / .Rprofile?



All Articles
Loading...
X
Show
Funny
Dev
Pics