Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit489df3f

Browse files
committed
Switch to expect_snapshot(error = TRUE)
1 parent372bd33 commit489df3f

File tree

12 files changed

+134
-24
lines changed

12 files changed

+134
-24
lines changed

‎tests/testthat/_snaps/error.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@
7777

7878
#error behavior can be set using option
7979

80+
Code
81+
callr::r(function() 1 + "A")
82+
Condition
83+
Error:
84+
! in callr subprocess.
85+
Caused by error:
86+
! non-numeric argument to binary operator
87+
88+
---
89+
8090
Code
8191
r_process()
8292
Output
@@ -90,6 +100,20 @@
90100
! non-numeric argument to binary operator
91101
Type .Last.error to see the more details.
92102

103+
---
104+
105+
Code
106+
r(function() {
107+
f <- (function() g())
108+
g <- (function() 1 + "A")
109+
f()
110+
})
111+
Condition
112+
Error:
113+
! in callr subprocess.
114+
Caused by error:
115+
! non-numeric argument to binary operator
116+
93117
---
94118

95119
Code

‎tests/testthat/_snaps/eval.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#errors are printed on stderr
2+
3+
Code
4+
r(f, stdout = out <- tempfile(), stderr = err <- tempfile())
5+
Condition
6+
Error:
7+
! in callr subprocess.
8+
Caused by error:
9+
! send to stderr 2
10+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#errors
2+
3+
Code
4+
load_client_lib()
5+
Condition
6+
Error in `sofile_in_processx()`:
7+
! Cannot find client file
8+
9+
#errors 2
10+
11+
Code
12+
load_client_lib(sofile)
13+
Condition
14+
Error in `dyn.load()`:
15+
! after ooops
16+

‎tests/testthat/_snaps/options.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#error for unknown options
2+
3+
Code
4+
r_process_options(func = function() { }, foo = "bar")
5+
Condition
6+
Error:
7+
! Unknown optioncharacter(0):'foo'
8+
9+
---
10+
11+
Code
12+
r_process_options(func = function() { }, foo = "bar", bar = "foo")
13+
Condition
14+
Error:
15+
! Unknown options:'foo' and 'bar'
16+

‎tests/testthat/_snaps/r-bg.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#r_bg can be killed
2+
3+
Code
4+
x$get_result()
5+
Condition
6+
Error:
7+
! callr subprocess failed: could not start R, exited with non-zero status, has crashed or was killed
8+
9+
#r_bg can get the error back
10+
11+
Code
12+
x$get_result()
13+
Condition
14+
Error:
15+
! in callr subprocess.
16+
Caused by error:
17+
! non-numeric argument to binary operator
18+

‎tests/testthat/_snaps/r-session.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#run throws
2+
3+
Code
4+
rs$run(function() stop("foobar"))
5+
Condition
6+
Error:
7+
! in callr subprocess.
8+
Caused by error:
9+
! foobar
10+
11+
#traceback
12+
13+
Code
14+
rs$run(do)
15+
Condition
16+
Error:
17+
! in callr subprocess.
18+
Caused by error:
19+
! oops
20+
21+
#error in the load hook
22+
23+
Code
24+
local({
25+
rs <- r_session$new(opts)
26+
on.exit(rs$kill(), add = TRUE)
27+
})
28+
Condition
29+
Error:
30+
! callr subprocess failed: Failed to start R session
31+

‎tests/testthat/test-error.R‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@ test_that("error behavior can be set using option", {
3333
skip_if_not_installed("withr")
3434

3535
withr::local_options(list("callr.error"="error"))
36-
expect_error(callr::r(function()1+"A"))
36+
expect_snapshot(error=TRUE,callr::r(function()1+"A"))
3737

3838
expect_r_process_snapshot({
3939
options(callr.error="error")
4040
callr::r(function()1+"A")
4141
})
4242

4343
withr::local_options(callr.error="stack")
44-
expect_error(
44+
expect_snapshot(error=TRUE, {
4545
r(
4646
function() {
4747
f<-function() g()
4848
g<-function()1+"A"
4949
f()
5050
}
5151
)
52-
)
52+
})
5353

5454
expect_r_process_snapshot({
5555
options(callr.error="stack")

‎tests/testthat/test-eval.R‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ test_that("errors are printed on stderr", {
159159
stop("send to stderr 2")
160160
}
161161

162-
expect_error(
162+
expect_snapshot(error=TRUE, {
163163
r(f,stdout=out<- tempfile(),stderr=err<- tempfile())
164-
)
164+
})
165165
on.exit(unlink(c(out,err),recursive=TRUE),add=TRUE)
166166

167167
expect_false(any(grepl("send to stderr", readLines(out))))

‎tests/testthat/test-load-client.R‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ test_that("load_client_lib", {
1515
test_that("errors", {
1616
skip_if_not_installed("mockery")
1717
mockery::stub(load_client_lib,"system.file","")
18-
expect_error(
19-
load_client_lib(),
20-
"Cannot find client file"
21-
)
18+
expect_snapshot(error=TRUE, load_client_lib())
2219
})
2320

2421
test_that("errors 2", {
@@ -30,7 +27,7 @@ test_that("errors 2", {
3027
package="processx"
3128
)
3229
mockery::stub(load_client_lib,"dyn.load",function(...) stop("ooops"))
33-
expect_error(load_client_lib(sofile))
30+
expect_snapshot(error=TRUE,load_client_lib(sofile))
3431
})
3532

3633
test_that("base64", {

‎tests/testthat/test-options.R‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
test_that("error for unknown options", {
2-
expect_error(
2+
expect_snapshot(error=TRUE, {
33
r_process_options(
44
func=function() {
55
},
66
foo="bar"
7-
),
8-
"Unknown option"
9-
)
7+
)
8+
})
109

11-
expect_error(
10+
expect_snapshot(error=TRUE, {
1211
r_process_options(
1312
func=function() {
1413
},
1514
foo="bar",
1615
bar="foo"
17-
),
18-
"Unknown options"
19-
)
16+
)
17+
})
2018

2119
gc()
2220
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp