Skip to content

Commit 04519fe

Browse files
authored
Re-signal unexpected snapshot errors (#1910)
Fixes #1906
1 parent 0af8cc4 commit 04519fe

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# testthat (development version)
22

3+
* Unexpected errors in `expect_snapshot()` now behave like regular errors;
4+
i.e. they terminate evaluation of the entire test and get a traceback
5+
(#1906).
6+
37
* `local_mocked_bindings()` can now mock any object, not just functions
48
(#1896).
59

R/snapshot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ expect_snapshot <- function(x,
9494
if (error) {
9595
expect(FALSE, msg, trace = state$error[["trace"]])
9696
} else {
97-
exp_signal(expectation("error", msg, trace = state$error[["trace"]]))
97+
cnd_signal(state$error)
9898
}
9999
return()
100100
}

tests/testthat/test-snapshot.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,18 @@ test_that("errors and warnings are folded", {
142142
expect_snapshot(error = TRUE, f())
143143
})
144144

145+
# I don't know how to test this automatically; wrapping it in another
146+
# snapshot doesn't capture the behaviour I expected, presumably due to the
147+
# way that errors bubble up
148+
# test_that("errors in snapshots behave like regular errors", {
149+
# f <- function() g()
150+
# g <- function() h()
151+
# h <- function() abort("!")
152+
#
153+
# expect_snapshot(f())
154+
# expect_snapshot(1 + 1)
155+
# })
156+
145157
test_that("hint is informative", {
146158
local_reproducible_output(crayon = TRUE, hyperlinks = TRUE, rstudio = TRUE)
147159

0 commit comments

Comments
 (0)