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
error
parameter for expect_snapshot()
#1200
Labels
Comments
hadley
added a commit
that referenced
this issue
Dec 2, 2020
7 tasks
hadley
added a commit
that referenced
this issue
Dec 4, 2020
Just a note that multiple errors can be flexibly and conveniently tested in this way: cnd_cat <- function(x) {
cat(paste0(conditionMessage(x), "\n"))
}
test_that("%|% fails with wrong types", {
expect_snapshot({
cnd_cat(expect_error(c(1L, NA) %|% 2))
cnd_cat(expect_error(c(1, NA) %|% ""))
cnd_cat(expect_error(c(1, NA) %|% call("fn")))
})
}) This prints both the code and the error message in the snapshot file. |
Easier way suggested by @hadley: test_that("%|% fails with wrong types", {
expect_snapshot({
(expect_error(c(1L, NA) %|% 2))
(expect_error(c(1, NA) %|% ""))
(expect_error(c(1, NA) %|% call("fn")))
})
}) This prints the condition objects returned invisibly by |
lionel-
added a commit
to r-lib/rlang
that referenced
this issue
Dec 16, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It might be useful to add an
error = FALSE
argument toexpect_snapshot()
. WhenTRUE
, no error is a failure. WhenFALSE
, error is a failure.NULL
would correspond to the current behaviour (no failure either way). When non-null, presence or absence of error would be checked on CRAN even whencran = FALSE
.The text was updated successfully, but these errors were encountered: