-
Notifications
You must be signed in to change notification settings - Fork 339
Closed
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behaviorexpectation 🙀
Description
With all testthat expect_*
functions, the tests keep running even after a failed check.
However I've noticed that this is not the case if the first argument of expect_vector
is NULL
. Instead a vctrs_error_scalar_type
condition is thrown and the test terminates immediately.
For example, the following prints the two failed assertions:
test_that("expect_true", {
expect_true(FALSE)
expect_true(FALSE)
})
Whereas the test below aborts after the first line:
test_that("expect_vector", {
expect_vector(NULL)
expect_vector(NULL)
})
<vctrs_error_scalar_type/vctrs_error/rlang_error/error/condition>
Error in `expect_vector(NULL)`: `NULL` must be a vector, not `NULL`.
Backtrace:
▆
1. └─testthat::expect_vector(NULL) at ../../foo.R:7:3
2. ├─base::tryCatch(...)
3. │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
4. │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
5. │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
6. └─vctrs::vec_assert(act$val, ptype = ptype, size = size, arg = act$lab)
7. └─vctrs:::stop_scalar_type(x, arg, call = call)
8. └─vctrs:::stop_vctrs(...)
9. └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = call)
Error:
! Test failed
Run `rlang::last_trace()` to see where the error occurred.
vec_assert
is documented to throw either a vctrs_error_scalar_type
or a vctrs_error_assert
, but expect_vector
only catches the latter. Catching both kinds should be enough to fix this behaviour I imagine.
Metadata
Metadata
Assignees
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behaviorexpectation 🙀