-
Notifications
You must be signed in to change notification settings - Fork 29
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
has_name now always returns a single logical value #60
Conversation
} | ||
on_failure(has_name) <- function(call, env) { | ||
paste0(deparse(call$x), " does not have name ", eval(call$which, env)) | ||
out_names <- paste0("'", paste0(eval(call$which, env), collapse = "', '"), "'") | ||
paste0(deparse(call$x), " does not have all of these name(s): ", out_names) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because of the possibility that call$which
is a vector with length greater than 1, I had to do this paste0()
stuff to avoid getting
Error in stop(assertError(attr(res, "msg"))) : bad error message
@@ -141,7 +142,7 @@ on_failure(is.date) <- function(call, env) { | |||
#' see_if(mean %has_args% "y") | |||
has_args <- function(f, args, exact = FALSE) { | |||
assert_that(is.function(f)) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I have my RStudio set to trim trailing whitespace when I save a file. Let me know if you'd like me to revert all of these
@@ -6,3 +6,11 @@ test_that("assert_that handles long false assertions gracefully", { | |||
"^isTRUE\\(.* [.]{3} is not TRUE$" | |||
) | |||
}) | |||
|
|||
test_that("assert_that handles has_name failures with multiple missing names", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added this test to catch the condition I mentioned above, where failures with a call$which
that has length > 1 could produce a bad error message
Thanks! |
Per discussion in #59 . In #46 I made
has_name()
throw an error if you tried to check multiple names in one call, e.g.Four packages on CRAN have code (covered by tests) that uses
has_name()
with multiple names, and all of them do this:Instead of breaking their code, I think the spirit of #46 (all assertions return exactly one
TRUE
/FALSE
) can still be accomplished by using anall()
insidehas_name()
! That is what I've proposed in this PR.