-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a8c9ee
commit d1ed428
Showing
7 changed files
with
101 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
library(testthat) | ||
library(callr) | ||
|
||
Sys.unsetenv("R_TESTS") | ||
|
||
test_check("callr") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
context("errors") | ||
|
||
test_that("error is propagated", { | ||
expect_error( | ||
r_eval(function() 1 + "A"), | ||
"non-numeric argument to binary operator" | ||
) | ||
}) | ||
|
||
test_that("error object is passed", { | ||
err <- NULL | ||
tryCatch( | ||
r_eval(function() 1 + "A"), | ||
error = function(e) err <<- e | ||
) | ||
expect_true("call" %in% names(err)) | ||
expect_true(inherits(err, "error")) | ||
}) | ||
|
||
test_that("error stack is passed", { | ||
err <- NULL | ||
tryCatch( | ||
r_eval( | ||
function() { | ||
f <- function() g() | ||
g <- function() 1 + "A" | ||
f() | ||
}, | ||
error = "stack" | ||
), | ||
error = function(e) err <<- e | ||
) | ||
|
||
expect_true("call" %in% names(err)) | ||
expect_true(inherits(err, "error")) | ||
expect_true(inherits(err, "callrError")) | ||
expect_equal(length(err$stack), 3) | ||
}) | ||
|
||
test_that("debugger is called", { | ||
|
||
called <- FALSE | ||
|
||
with_mock( | ||
`utils::debugger` = function(...) called <<- TRUE, | ||
r_eval(function() { 1 + "A" }, error = "debugger") | ||
) | ||
|
||
expect_true(called) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
context("r_eval") | ||
|
||
test_that("basic r_eval", { | ||
expect_equal(r_eval(function() 1 + 1), 2) | ||
expect_equal(r_eval(function(x) 1 + x, list(5)), 6) | ||
}) | ||
|
||
test_that("the same R version is called", { | ||
expect_equal(r_eval(function() R.version), R.version) | ||
}) | ||
|
||
test_that("standard output", { | ||
tmp <- tempfile() | ||
on.exit(unlink(tmp), add = TRUE) | ||
r_eval(function() cat("hello\n"), stdout = tmp) | ||
expect_equal(readLines(tmp), "hello") | ||
}) | ||
|
||
test_that("standard error", { | ||
tmp <- tempfile() | ||
on.exit(unlink(tmp), add = TRUE) | ||
r_eval(function() message("hello"), stderr = tmp) | ||
expect_equal(readLines(tmp), "hello") | ||
}) | ||
|
||
test_that("cmdargs argument", { | ||
o1 <- tempfile() | ||
o2 <- tempfile() | ||
on.exit(unlink(c(o1, o2)), add = TRUE) | ||
|
||
r_eval(ls, stdout = o1) | ||
r_eval(ls, stdout = o2, cmdargs = character()) | ||
|
||
expect_true(length(readLines(o2)) > length(readLines(o1))) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
context("utils") | ||
|
||
test_that("set_var with empty list", { | ||
expect_equal( | ||
with_envvar(c(), Sys.getenv()), | ||
Sys.getenv() | ||
) | ||
}) |
This file was deleted.
Oops, something went wrong.