Skip to content

Commit

Permalink
Add snapshot test/suppress message
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley authored and jimhester committed Sep 8, 2021
1 parent 6db1a7b commit 7725d4a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 9 additions & 0 deletions tests/testthat/_snaps/defer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# defer()'s global env facilities work

Code
defer(print("howdy"), envir = globalenv())
Message <simpleMessage>
Setting deferred event(s) on global environment.
* Execute (and clear) with `withr::deferred_run()`.
* Clear (without executing) with `withr::deferred_clear()`.

7 changes: 2 additions & 5 deletions tests/testthat/test-defer.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down

0 comments on commit 7725d4a

Please sign in to comment.