diff --git a/NEWS.md b/NEWS.md index 65432a2dd..9abdfcb39 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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). diff --git a/R/snapshot.R b/R/snapshot.R index b5ef5fe4c..421933f59 100644 --- a/R/snapshot.R +++ b/R/snapshot.R @@ -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() } diff --git a/tests/testthat/test-snapshot.R b/tests/testthat/test-snapshot.R index 3e0372550..ab35726b4 100644 --- a/tests/testthat/test-snapshot.R +++ b/tests/testthat/test-snapshot.R @@ -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)