diff --git a/tests/testthat/_snaps/stacks-deep.md b/tests/testthat/_snaps/stacks-deep.md index 0b7ca14c8..88f66f947 100644 --- a/tests/testthat/_snaps/stacks-deep.md +++ b/tests/testthat/_snaps/stacks-deep.md @@ -144,10 +144,10 @@ : doTryCatch : tryCatchOne : tryCatchList - : doTryCatch - : tryCatchOne - : tryCatchList : tryCatch + : doWithOneRestart + : withOneRestart + : withRestarts : test_code : test_that : eval [test-stacks-deep.R#XXX] @@ -156,10 +156,10 @@ : doTryCatch : tryCatchOne : tryCatchList - : doTryCatch - : tryCatchOne - : tryCatchList : tryCatch + : doWithOneRestart + : withOneRestart + : withRestarts : test_code : source_file : FUN @@ -212,10 +212,10 @@ : doTryCatch : tryCatchOne : tryCatchList - : doTryCatch - : tryCatchOne - : tryCatchList : tryCatch + : doWithOneRestart + : withOneRestart + : withRestarts : test_code : test_that : eval [test-stacks-deep.R#XXX] @@ -224,10 +224,10 @@ : doTryCatch : tryCatchOne : tryCatchList - : doTryCatch - : tryCatchOne - : tryCatchList : tryCatch + : doWithOneRestart + : withOneRestart + : withRestarts : test_code : source_file : FUN @@ -281,10 +281,10 @@ : doTryCatch : tryCatchOne : tryCatchList - : doTryCatch - : tryCatchOne - : tryCatchList : tryCatch + : doWithOneRestart + : withOneRestart + : withRestarts : test_code : test_that : eval [test-stacks-deep.R#XXX] @@ -293,10 +293,10 @@ : doTryCatch : tryCatchOne : tryCatchList - : doTryCatch - : tryCatchOne - : tryCatchList : tryCatch + : doWithOneRestart + : withOneRestart + : withRestarts : test_code : source_file : FUN @@ -335,10 +335,10 @@ : doTryCatch : tryCatchOne : tryCatchList - : doTryCatch - : tryCatchOne - : tryCatchList : tryCatch + : doWithOneRestart + : withOneRestart + : withRestarts : test_code : test_that : eval [test-stacks-deep.R#XXX] @@ -347,10 +347,10 @@ : doTryCatch : tryCatchOne : tryCatchList - : doTryCatch - : tryCatchOne - : tryCatchList : tryCatch + : doWithOneRestart + : withOneRestart + : withRestarts : test_code : source_file : FUN diff --git a/tests/testthat/_snaps/stacks.md b/tests/testthat/_snaps/stacks.md index beab4eac6..e57a2c35f 100644 --- a/tests/testthat/_snaps/stacks.md +++ b/tests/testthat/_snaps/stacks.md @@ -3,16 +3,32 @@ Code df Output - num call loc - 1 68 A [test-stacks.R#3] - 2 67 B [test-stacks.R#7] - 3 66 [test-stacks.R#11] - 4 44 C - 5 43 renderTable [test-stacks.R#18] - 6 42 func - 7 41 force - 8 40 withVisible - 9 39 withCallingHandlers + num call loc + 1 68 A [test-stacks.R#3] + 2 67 B [test-stacks.R#7] + 3 66 [test-stacks.R#11] + 4 44 C + 5 43 renderTable [test-stacks.R#18] + 6 42 func + 7 41 force + 8 40 withVisible + 9 39 withCallingHandlers + 10 38 domain$wrapSync + 11 37 promises::with_promise_domain + 12 36 captureStackTraces + 13 32 tryCatch + 14 31 do + 15 30 hybrid_chain + 16 29 renderFunc + 17 28 renderTable({ C() }, server = FALSE) + 18 10 isolate + 19 9 withCallingHandlers [test-stacks.R#16] + 20 8 domain$wrapSync + 21 7 promises::with_promise_domain + 22 6 captureStackTraces + 23 2 tryCatch + 24 1 try + 25 0 causeError [test-stacks.R#14] --- @@ -91,4 +107,5 @@ 69 3 tryCatchList 70 2 tryCatch 71 1 try + 72 0 causeError [test-stacks.R#14] diff --git a/tests/testthat/test-stacks-deep.R b/tests/testthat/test-stacks-deep.R index 86a365deb..6988edaa4 100644 --- a/tests/testthat/test-stacks-deep.R +++ b/tests/testthat/test-stacks-deep.R @@ -91,6 +91,10 @@ describe("deep stack trace filtering", { }) test_that("deep stack capturing", { + # base::tryCatch internals changed in 4.5.2 + skip_unless_r(">= 4.5.2") + skip_if_not_installed("testthat", "3.3.0") + `%...>%` <- promises::`%...>%` `%...!%` <- promises::`%...!%` finally <- promises::finally diff --git a/tests/testthat/test-stacks.R b/tests/testthat/test-stacks.R index c7bbd0d4a..31f551d78 100644 --- a/tests/testthat/test-stacks.R +++ b/tests/testthat/test-stacks.R @@ -26,8 +26,8 @@ causeError <- function(full) { suppressMessages(df <- extractStackTrace(conditionStackTrace(cond), full = full)) df$loc <- cleanLocs(df$loc) # Compensate for this test being called from different call sites; - # whack the - df <- head(df, -sys.nframe()) + # whack the top n frames off using the `num` frame column + df <- df[df$num >= sys.nframe(), ] df$num <- df$num - sys.nframe() df } @@ -84,12 +84,18 @@ extractStackTrace <- function(calls, score[callnames == "..stacktraceon.."] <- 1 toShow <- (1 + cumsum(score)) > 0 & !(callnames %in% c("..stacktraceon..", "..stacktraceoff..", "..stacktracefloor..")) - # doTryCatch, tryCatchOne, and tryCatchList are not informative--they're - # just internals for tryCatch - toShow <- toShow & !(callnames %in% c("doTryCatch", "tryCatchOne", "tryCatchList")) + toShow <- + toShow & + # doTryCatch, tryCatchOne, and tryCatchList are not informative--they're + # just internals for tryCatch + !(callnames %in% c("doTryCatch", "tryCatchOne", "tryCatchList")) & + # doWithOneRestart and withOneRestart are not informative--they're + # just internals for withRestarts + !(callnames %in% c("withOneRestart", "doWithOneRestart")) } calls <- calls[toShow] + calls <- rev(calls) # Show in traceback() order index <- rev(which(toShow)) width <- floor(log10(max(index))) + 1