From 7725d4a36e3b6fe28b4001fdd0c224b876a67602 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 7 Sep 2021 14:40:35 -0500 Subject: [PATCH] Add snapshot test/suppress message --- tests/testthat/_snaps/defer.md | 9 +++++++++ tests/testthat/test-defer.R | 7 ++----- 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 tests/testthat/_snaps/defer.md diff --git a/tests/testthat/_snaps/defer.md b/tests/testthat/_snaps/defer.md new file mode 100644 index 00000000..ddc51cc1 --- /dev/null +++ b/tests/testthat/_snaps/defer.md @@ -0,0 +1,9 @@ +# defer()'s global env facilities work + + Code + defer(print("howdy"), envir = globalenv()) + Message + Setting deferred event(s) on global environment. + * Execute (and clear) with `withr::deferred_run()`. + * Clear (without executing) with `withr::deferred_clear()`. + diff --git a/tests/testthat/test-defer.R b/tests/testthat/test-defer.R index 3c444abd..df0b87db 100644 --- a/tests/testthat/test-defer.R +++ b/tests/testthat/test-defer.R @@ -21,10 +21,7 @@ test_that("defer()'s global env facilities work", { expect_null(get_handlers(globalenv())) Sys.setenv(abcdefg = "abcdefg") - expect_message( - defer(print("howdy"), envir = globalenv()), - "Setting deferred event" - ) + expect_snapshot(defer(print("howdy"), envir = globalenv())) expect_message( local_envvar(c(abcdefg = "tuvwxyz"), .local_envir = globalenv()), NA @@ -37,7 +34,7 @@ test_that("defer()'s global env facilities work", { expect_output(deferred_run(globalenv()), "howdy") expect_equal(Sys.getenv("abcdefg"), "abcdefg") - defer(print("never going to happen"), envir = globalenv()) + expect_message(defer(print("never going to happen"), envir = globalenv())) deferred_clear(globalenv()) h <- get_handlers(globalenv())