|
1 | | -testthat::test_that("", { |
2 | | - q <- qenv() |
3 | | - q1 <- eval_code(q, expression(iris, mtcars)) |
4 | | - testthat::expect_identical( |
5 | | - get_outputs(q1), |
6 | | - list(iris, mtcars) |
7 | | - ) |
| 1 | +testthat::describe("get_output", { |
| 2 | + testthat::it("returns an empty list if nothing is printed", { |
| 3 | + q <- qenv() |
| 4 | + q1 <- eval_code(q, expression(a <- 1L, b <- 2L)) |
| 5 | + testthat::expect_identical(get_outputs(q1), list()) |
| 6 | + }) |
| 7 | + |
| 8 | + testthat::it("implicitly printed objects are returned asis in a list", { |
| 9 | + q <- qenv() |
| 10 | + q1 <- eval_code(q, expression(a <- 1L, a, b <- 2L, b)) |
| 11 | + testthat::expect_identical(get_outputs(q1), list(1L, 2L)) |
| 12 | + }) |
| 13 | + |
| 14 | + testthat::it("explicitly printed objects are returned as console-output-string in a list", { |
| 15 | + q <- qenv() |
| 16 | + q1 <- eval_code(q, expression(a <- 1L, print(a), b <- 2L, print(b))) |
| 17 | + testthat::expect_identical(get_outputs(q1), list("[1] 1\n", "[1] 2\n")) |
| 18 | + }) |
| 19 | + |
| 20 | + testthat::it("printed plots are returned as recordedplot in a list", { |
| 21 | + q <- qenv() |
| 22 | + q1 <- eval_code(q, expression(a <- 1L, plot(a))) |
| 23 | + testthat::expect_true(inherits(get_outputs(q1)[[1]], "recordedplot")) |
| 24 | + }) |
| 25 | + |
| 26 | + testthat::it("warnings are returned asis in a list", { |
| 27 | + q <- qenv() |
| 28 | + q1 <- eval_code(q, expression(warning("test"))) |
| 29 | + expected <- simpleWarning("test") |
| 30 | + expected["call"] <- NULL |
| 31 | + testthat::expect_identical(get_outputs(q1), list(expected)) |
| 32 | + }) |
| 33 | + |
| 34 | + testthat::it("messages are returned asis in a list", { |
| 35 | + q <- qenv() |
| 36 | + q1 <- eval_code(q, expression(message("test"))) |
| 37 | + expected <- simpleMessage("test\n", call = quote(message("test"))) |
| 38 | + testthat::expect_identical(get_outputs(q1), list(expected)) |
| 39 | + }) |
8 | 40 | }) |
0 commit comments