Created
February 7, 2025 21:26
-
-
Save kelly-sovacool/92d2d5c1f199342b500f89ef7df6c4be to your computer and use it in GitHub Desktop.
nested warnings & messages with testthat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f <- function() { | |
warning('a warning') | |
message('a message') | |
} | |
g <- function() { | |
withCallingHandlers( | |
warning = function(cnd) { | |
message('oh no, a warning occurred') | |
}, | |
warning('a warning') | |
) | |
} | |
test_that("f() warning & message", { | |
expect_warning(expect_message(f(), 'a message'), 'a warning') | |
}) | |
test_that("g() handles warning with a message", { | |
expect_warning(expect_message(g(), 'oh no'), 'a warning') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment