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

Don't use a restart to handle stop_on_error = 2L #232

Merged
merged 16 commits into from
Jan 8, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add some test about render error and backtrace showing
cderv committed Dec 19, 2024

Verified

This commit was signed with the committer’s verified signature.
thojou Thomas Joußen
commit 8774fe287643e56fd2b0f850cf375a78dccc2d4f
12 changes: 12 additions & 0 deletions tests/testthat/_snaps/conditions/abort-error.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


processing file: with-abort-error.Rmd
cderv marked this conversation as resolved.
Show resolved Hide resolved
Error in `h()`:
! !
Backtrace:
1. global f()
2. global g()
3. global h()

Quitting from lines 11-15 [unnamed-chunk-2] (with-abort-error.Rmd)
Execution halted
12 changes: 12 additions & 0 deletions tests/testthat/_snaps/conditions/stop-error.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


processing file: with-stop-error.Rmd
Error in `h()`:
! !
Backtrace:
1. global f()
2. global g()
3. global h()

Quitting from lines 11-15 [unnamed-chunk-2] (with-stop-error.Rmd)
Execution halted
17 changes: 17 additions & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
@@ -2,3 +2,20 @@ expect_output_types <- function(x, types) {
output_types <- vapply(x, output_type, character(1))
expect_equal(output_types, types)
}

quick_install <- function(package, lib, quiet = TRUE) {
opts <- c(
"--data-compress=none",
"--no-byte-compile",
"--no-data",
"--no-demo",
"--no-docs",
"--no-help",
"--no-html",
"--no-libs",
"--use-vanilla",
sprintf("--library=%s", lib),
package
)
invisible(callr::rcmd("INSTALL", opts, show = !quiet, fail_on_status = TRUE))
}
15 changes: 15 additions & 0 deletions tests/testthat/ressources/with-abort-error.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: document with error
---

```{r}
rlang::global_entrace()
options(rlang_backtrace_on_error_report = "full")
cderv marked this conversation as resolved.
Show resolved Hide resolved
```

```{r}
f <- function() g()
g <- function() h()
h <- function() rlang::abort("!")
f()
```
15 changes: 15 additions & 0 deletions tests/testthat/ressources/with-stop-error.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: document with error
---

```{r}
rlang::global_entrace()
options(rlang_backtrace_on_error_report = "full")
```

```{r}
f <- function() g()
g <- function() h()
h <- function() stop("!")
f()
```
21 changes: 21 additions & 0 deletions tests/testthat/test-conditions.R
Original file line number Diff line number Diff line change
@@ -136,3 +136,24 @@ test_that("errors during printing are captured", {
ev <- evaluate("a")
expect_output_types(ev, c("source", "error"))
})

test_that("Entraced error does not loose their backtrace when render errors", {
skip_if_not_installed("rlang")
skip_if_not_installed("rmarkdown")
skip_if_not_installed("callr")
skip_on_cran()
# install dev version of package in temp directory
withr::local_temp_libpaths()
quick_install(pkgload::pkg_path("."), lib = .libPaths()[1])

out <- withr::local_tempfile(fileext = "txt")

rscript <- withr::local_tempfile(fileext = "R")
writeLines(sprintf("rmarkdown::render(%s)", dQuote(test_path("ressources/with-stop-error.Rmd"), FALSE)), con = rscript)
callr::rscript(rscript, fail_on_status = FALSE, show = FALSE, stderr = out)
expect_snapshot_file(out, name = 'stop-error.txt')

writeLines(sprintf("rmarkdown::render(%s)", dQuote(test_path("ressources/with-abort-error.Rmd"), FALSE)), con = rscript)
callr::rscript(rscript, fail_on_status = FALSE, show = FALSE, stderr = out)
expect_snapshot_file(out, name = 'abort-error.txt')
})