Skip to content

Instantly share code, notes, and snippets.

@kelly-sovacool
Created February 7, 2025 21:26
Show Gist options
  • Save kelly-sovacool/92d2d5c1f199342b500f89ef7df6c4be to your computer and use it in GitHub Desktop.
Save kelly-sovacool/92d2d5c1f199342b500f89ef7df6c4be to your computer and use it in GitHub Desktop.
nested warnings & messages with testthat
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