Skip to content

Commit

Permalink
Fix test snapshots with both old and new cli
Browse files Browse the repository at this point in the history
R 3.6.x uses older cli now on GHA.
  • Loading branch information
gaborcsardi committed Aug 6, 2024
1 parent e61bf67 commit 3f9af6d
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 93 deletions.
89 changes: 0 additions & 89 deletions tests/testthat/_snaps/err-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,6 @@
! This failed
Type .Last.error to see the more details.

# simple error with cli and colors

Code
cat(out$stderr)
Output
Error in `f()` at script.R:5:5:
! This failed
---
Backtrace:
1. base::source("script.R")
2. | base::withVisible(eval(ei, envir))
3. | base::eval(ei, envir)
4. | base::eval(ei, envir)
5. global f() at script.R:5:5
6. processx:::throw("This failed") at script.R:4:10
Execution halted

---

Code
cat(out$stdout)
Output
Error in `f()` at script.R:6:5:
! This failed
Type .Last.error to see the more details.

# chain_error

Code
Expand Down Expand Up @@ -161,42 +135,6 @@
21. | processx:::throw_error(err, parent = e)
Execution halted

---

Code
cat(out$stderr)
Output
Error in `do()` at script.R:19:14:
! Failed to base64 encode
Caused by error in `do2()` at script.R:15:13:
! something is wrong here
Caused by error in `do3()` at script.R:12:13:
! because of this
---
Backtrace:
 1. base::source("script.R")
 2. | base::withVisible(eval(ei, envir))
 3. | base::eval(ei, envir)
 4. | base::eval(ei, envir)
 5. global f() at script.R:20:9
 6. global g() at script.R:17:14
 7. global h() at script.R:18:14
 8. global do() at script.R:19:14
 9. processx:::chain_error(do2(), "Failed to base64 encode") at script.R:15:13
10. | base::withCallingHandlers({ ...
11. global do2()
12. processx:::chain_error(do3(), "something is wrong here") at script.R:12:13
13. | base::withCallingHandlers({ ...
14. global do3()
15. processx:::throw("because of this") at script.R:9:13
16. | base::signalCondition(cond)
17. | (function (e) ...
18. | processx:::throw_error(err, parent = e)
19. | base::signalCondition(cond)
20. | (function (e) ...
21. | processx:::throw_error(err, parent = e)
Execution halted

# chain_error with stop()

Code
Expand Down Expand Up @@ -361,30 +299,3 @@
11. | processx:::throw_error(err, parent = e)
Execution halted

---

Code
cat(out$stderr)
Output
Error in `eval(ei, envir)`:
! failed to run external program
Caused by error in `processx::run(px, c("return", "1"))` at script.R:9:9:
! System command 'px' failed
---
Exit status: 1
Stderr: <empty>
---
Backtrace:
 1. base::source("script.R")
 2. | base::withVisible(eval(ei, envir))
 3. | base::eval(ei, envir)
 4. | base::eval(ei, envir)
 5. processx:::chain_error(processx::run(px, c("return", "1")), "failed to r... at script.R:9:9
 6. | base::withCallingHandlers({ ...
 7. processx::run(px, c("return", "1"))
 8. processx:::throw(new_process_error(res, call = sys.call(), echo = echo, ...
 9. | base::signalCondition(cond)
10. | (function (e) ...
11. | processx:::throw_error(err, parent = e)
Execution halted

89 changes: 89 additions & 0 deletions tests/testthat/_snaps/newcli/err-output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# simple error with cli and colors

Code
cat(out$stderr)
Output
Error in `f()` at script.R:5:5:
! This failed
---
Backtrace:
1. base::source("script.R")
2. | base::withVisible(eval(ei, envir))
3. | base::eval(ei, envir)
4. | base::eval(ei, envir)
5. global f() at script.R:5:5
6. processx:::throw("This failed") at script.R:4:10
Execution halted

---

Code
cat(out$stdout)
Output
Error in `f()` at script.R:6:5:
! This failed
Type .Last.error to see the more details.

# chain_error

Code
cat(out$stderr)
Output
Error in `do()` at script.R:19:14:
! Failed to base64 encode
Caused by error in `do2()` at script.R:15:13:
! something is wrong here
Caused by error in `do3()` at script.R:12:13:
! because of this
---
Backtrace:
 1. base::source("script.R")
 2. | base::withVisible(eval(ei, envir))
 3. | base::eval(ei, envir)
 4. | base::eval(ei, envir)
 5. global f() at script.R:20:9
 6. global g() at script.R:17:14
 7. global h() at script.R:18:14
 8. global do() at script.R:19:14
 9. processx:::chain_error(do2(), "Failed to base64 encode") at script.R:15:13
10. | base::withCallingHandlers({ ...
11. global do2()
12. processx:::chain_error(do3(), "something is wrong here") at script.R:12:13
13. | base::withCallingHandlers({ ...
14. global do3()
15. processx:::throw("because of this") at script.R:9:13
16. | base::signalCondition(cond)
17. | (function (e) ...
18. | processx:::throw_error(err, parent = e)
19. | base::signalCondition(cond)
20. | (function (e) ...
21. | processx:::throw_error(err, parent = e)
Execution halted

# full parent error is printed in non-interactive mode

Code
cat(out$stderr)
Output
Error in `eval(ei, envir)`:
! failed to run external program
Caused by error in `processx::run(px, c("return", "1"))` at script.R:9:9:
! System command 'px' failed
---
Exit status: 1
Stderr: <empty>
---
Backtrace:
 1. base::source("script.R")
 2. | base::withVisible(eval(ei, envir))
 3. | base::eval(ei, envir)
 4. | base::eval(ei, envir)
 5. processx:::chain_error(processx::run(px, c("return", "1")), "failed to r... at script.R:9:9
 6. | base::withCallingHandlers({ ...
 7. processx::run(px, c("return", "1"))
 8. processx:::throw(new_process_error(res, call = sys.call(), echo = echo, ...
 9. | base::signalCondition(cond)
10. | (function (e) ...
11. | processx:::throw_error(err, parent = e)
Execution halted

89 changes: 89 additions & 0 deletions tests/testthat/_snaps/oldcli/err-output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# simple error with cli and colors

Code
cat(out$stderr)
Output
Error in `f()` at script.R:5:5:
! This failed
---
Backtrace:
1. base::source("script.R")
2. | base::withVisible(eval(ei, envir))
3. | base::eval(ei, envir)
4. | base::eval(ei, envir)
5. global f() at script.R:5:5
6. processx:::throw("This failed") at script.R:4:10
Execution halted

---

Code
cat(out$stdout)
Output
Error in `f()` at script.R:6:5:
! This failed
Type .Last.error to see the more details.

# chain_error

Code
cat(out$stderr)
Output
Error in `do()` at script.R:19:14:
! Failed to base64 encode
Caused by error in `do2()` at script.R:15:13:
! something is wrong here
Caused by error in `do3()` at script.R:12:13:
! because of this
---
Backtrace:
 1. base::source("script.R")
 2. | base::withVisible(eval(ei, envir))
 3. | base::eval(ei, envir)
 4. | base::eval(ei, envir)
 5. global f() at script.R:20:9
 6. global g() at script.R:17:14
 7. global h() at script.R:18:14
 8. global do() at script.R:19:14
 9. processx:::chain_error(do2(), "Failed to base64 encode") at script.R:15:13
10. | base::withCallingHandlers({ ...
11. global do2()
12. processx:::chain_error(do3(), "something is wrong here") at script.R:12:13
13. | base::withCallingHandlers({ ...
14. global do3()
15. processx:::throw("because of this") at script.R:9:13
16. | base::signalCondition(cond)
17. | (function (e) ...
18. | processx:::throw_error(err, parent = e)
19. | base::signalCondition(cond)
20. | (function (e) ...
21. | processx:::throw_error(err, parent = e)
Execution halted

# full parent error is printed in non-interactive mode

Code
cat(out$stderr)
Output
Error in `eval(ei, envir)`:
! failed to run external program
Caused by error in `processx::run(px, c("return", "1"))` at script.R:9:9:
! System command 'px' failed
---
Exit status: 1
Stderr: <empty>
---
Backtrace:
 1. base::source("script.R")
 2. | base::withVisible(eval(ei, envir))
 3. | base::eval(ei, envir)
 4. | base::eval(ei, envir)
 5. processx:::chain_error(processx::run(px, c("return", "1")), "failed to r... at script.R:9:9
 6. | base::withCallingHandlers({ ...
 7. processx::run(px, c("return", "1"))
 8. processx:::throw(new_process_error(res, call = sys.call(), echo = echo, ...
 9. | base::signalCondition(cond)
10. | (function (e) ...
11. | processx:::throw_error(err, parent = e)
Execution halted

12 changes: 8 additions & 4 deletions tests/testthat/test-err-output.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ test_that("simple error with cli", {

test_that("simple error with cli and colors", {

cli <- if (packageVersion("cli") >= "3.6.3") "newcli" else "oldcli"
out <- run_script({
library(cli)
options(cli.num_colors = 256)
f <- function() processx:::throw("This failed")
f()
})
expect_snapshot(cat(out$stderr))
expect_snapshot(cat(out$stderr), variant = cli)

out <- run_script({
library(cli)
Expand All @@ -50,7 +51,7 @@ test_that("simple error with cli and colors", {
f <- function() processx:::throw("This failed")
f()
})
expect_snapshot(cat(out$stdout))
expect_snapshot(cat(out$stdout), variant = cli)
})

test_that("chain_error", {
Expand Down Expand Up @@ -96,7 +97,8 @@ test_that("chain_error", {
list(o = quote({library(cli); options(cli.num_colors = 256)}), c = expr)
)
out <- run_script(quoted = expr2)
expect_snapshot(cat(out$stderr), transform = scrub_srcref)
cli <- if (packageVersion("cli") >= "3.6.3") "newcli" else "oldcli"
expect_snapshot(cat(out$stderr), transform = scrub_srcref, variant = cli)
})

test_that("chain_error with stop()", {
Expand Down Expand Up @@ -205,8 +207,10 @@ test_that("full parent error is printed in non-interactive mode", {
list(o = quote({library(cli); options(cli.num_colors = 256)}), c = expr)
)
out <- run_script(quoted = expr2)
cli <- if (packageVersion("cli") >= "3.6.3") "newcli" else "oldcli"
expect_snapshot(
cat(out$stderr),
transform = function(x) scrub_px(scrub_srcref(x))
transform = function(x) scrub_px(scrub_srcref(x)),
variant = cli
)
})

0 comments on commit 3f9af6d

Please sign in to comment.