Skip to content

Commit d5daa23

Browse files
committed
Add coverage of adding srcref info to traceback
1 parent 80a3a1d commit d5daa23

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

tests/testthat/_snaps/hooks.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
ERROR non-numeric argument to binary operator
3030
Code
3131
writeLines(eval_outside("log_errors(traceback = TRUE)",
32-
"f<-function() stop(\"TEST\"); f()"))
32+
"source(\"helper.R\", keep.source = TRUE)", "function_that_fails()"))
3333
Output
34-
ERROR TEST
34+
ERROR I'm failing
3535
ERROR Traceback:
36-
ERROR 2: stop("TEST")
37-
ERROR 1: f()
36+
ERROR 2: stop("I'm failing") at helper.R #41
37+
ERROR 1: function_that_fails()
3838

3939
# shiny input initialization is detected
4040

tests/testthat/helper.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ eval_outside <- function(...) {
3535
suppressWarnings(system2(path, input, stdout = TRUE, stderr = TRUE))
3636
readLines(output)
3737
}
38+
39+
# This function is needed to test traceback logging
40+
function_that_fails <- function() {
41+
stop("I'm failing")
42+
}

tests/testthat/test-hooks.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test_that("log_errors", {
1515
writeLines(eval_outside("log_errors()", "stop(42)"))
1616
writeLines(eval_outside("log_errors()", "foobar"))
1717
writeLines(eval_outside("log_errors()", 'f<-function(x) {42 * "foobar"}; f()'))
18-
writeLines(eval_outside("log_errors(traceback = TRUE)", 'f<-function() stop("TEST"); f()'))
18+
writeLines(eval_outside("log_errors(traceback = TRUE)", 'source("helper.R", keep.source = TRUE)', "function_that_fails()"))
1919
})
2020
})
2121

0 commit comments

Comments
 (0)