Skip to content

Commit

Permalink
Add coverage of adding srcref info to traceback
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Jan 24, 2025
1 parent 80a3a1d commit d5daa23
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 4 additions & 4 deletions tests/testthat/_snaps/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 1 addition & 1 deletion tests/testthat/test-hooks.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()"))

Check warning on line 18 in tests/testthat/test-hooks.R

View workflow job for this annotation

GitHub Actions / lint

file=tests/testthat/test-hooks.R,line=18,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 127 characters.
})
})

Expand Down

0 comments on commit d5daa23

Please sign in to comment.