Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-signal unexpected snapshot errors #1910

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading