Skip to content

Commit

Permalink
Re-signal unexpected snapshot errors (#1910)
Browse files Browse the repository at this point in the history
Fixes #1906
  • Loading branch information
hadley authored Nov 29, 2023
1 parent 0af8cc4 commit 04519fe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# testthat (development version)

* Unexpected errors in `expect_snapshot()` now behave like regular errors;
i.e. they terminate evaluation of the entire test and get a traceback
(#1906).

* `local_mocked_bindings()` can now mock any object, not just functions
(#1896).

Expand Down
2 changes: 1 addition & 1 deletion R/snapshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ expect_snapshot <- function(x,
if (error) {
expect(FALSE, msg, trace = state$error[["trace"]])
} else {
exp_signal(expectation("error", msg, trace = state$error[["trace"]]))
cnd_signal(state$error)
}
return()
}
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-snapshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ test_that("errors and warnings are folded", {
expect_snapshot(error = TRUE, f())
})

# I don't know how to test this automatically; wrapping it in another
# snapshot doesn't capture the behaviour I expected, presumably due to the
# way that errors bubble up
# test_that("errors in snapshots behave like regular errors", {
# f <- function() g()
# g <- function() h()
# h <- function() abort("!")
#
# expect_snapshot(f())
# expect_snapshot(1 + 1)
# })

test_that("hint is informative", {
local_reproducible_output(crayon = TRUE, hyperlinks = TRUE, rstudio = TRUE)

Expand Down

0 comments on commit 04519fe

Please sign in to comment.