-
Notifications
You must be signed in to change notification settings - Fork 318
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
expect_warning()
does not return condition
#1371
Comments
That's because we return the return value of the expression rather than the condition, unless the return value is library(testthat)
f <- function(out) {
message("foo")
out
}
g <- function(out) {
warning("foo")
out
}
(expect_message(f(NULL)))
#> <simpleMessage in message("foo"): foo
(expect_message(f("return value")))
#> [1] "return value"
(expect_warning(g(NULL)))
#> <simpleWarning in g(NULL): foo>
(expect_warning(g("return value")))
#> [1] "return value" The difference in behaviour when the expression is |
We rely a lot on the original behavior in dm. Chances are that many other packages do too. Should we consistently return the input instead (except for I think the examples aren't representative because a warning/message is rarely the last thing that a function does. Interestingly, reprex gets it wrong here: out <- testthat::expect_message({
message("")
"out"
})
class(out)
#> [1] "character"
out
#> [1] "out" Created on 2021-05-17 by the reprex package (v2.0.0) With dev testthat, I see in the terminal:
|
I think we should consistently return the condition because it is easy to use value expectations inside condition expectation whereas it's hard to both test and capture a condition. Also returning the condition composes well with |
I have expect_equal(
expect_message(...),
expect_message(...)
) which is more difficult to transform. How about a new set of expectations instead, e.g. |
Or perhaps mark this behavior for edition 4 instead? |
This could be: expect_message(out <- ...)
expect_message(exp <- ...)
expect_equal(out, exp)
We should probably look at revdep results before considering this? |
Unlike other expectations:
Tested with 3rd edition.
The text was updated successfully, but these errors were encountered: