diff --git a/tests/testthat/_snaps/hooks.md b/tests/testthat/_snaps/hooks.md index e0cc7f1..8635928 100644 --- a/tests/testthat/_snaps/hooks.md +++ b/tests/testthat/_snaps/hooks.md @@ -29,12 +29,12 @@ ERROR non-numeric argument to binary operator Code writeLines(eval_outside("log_errors(traceback = TRUE)", - "f<-function() stop(\"TEST\"); f()")) + "source(\"helper.R\", keep.source = TRUE)", "function_that_fails()")) Output - ERROR TEST + ERROR I'm failing ERROR Traceback: - ERROR 2: stop("TEST") - ERROR 1: f() + ERROR 2: stop("I'm failing") at helper.R #41 + ERROR 1: function_that_fails() # shiny input initialization is detected diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 6d1ca91..bbe6170 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -35,3 +35,8 @@ eval_outside <- function(...) { suppressWarnings(system2(path, input, stdout = TRUE, stderr = TRUE)) readLines(output) } + +# This function is needed to test traceback logging +function_that_fails <- function() { + stop("I'm failing") +} diff --git a/tests/testthat/test-hooks.R b/tests/testthat/test-hooks.R index fd6e992..3efd77f 100644 --- a/tests/testthat/test-hooks.R +++ b/tests/testthat/test-hooks.R @@ -15,7 +15,7 @@ test_that("log_errors", { writeLines(eval_outside("log_errors()", "stop(42)")) writeLines(eval_outside("log_errors()", "foobar")) writeLines(eval_outside("log_errors()", 'f<-function(x) {42 * "foobar"}; f()')) - writeLines(eval_outside("log_errors(traceback = TRUE)", 'f<-function() stop("TEST"); f()')) + writeLines(eval_outside("log_errors(traceback = TRUE)", 'source("helper.R", keep.source = TRUE)', "function_that_fails()")) }) })