Skip to content

Commit

Permalink
Update test-echo.R (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbarbone committed Jan 15, 2024
1 parent 538daad commit fc6815f
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions tests/testthat/test-echo.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
test_that("echo() works", {
res <- utils::capture.output(echo({ print(1) }, level = 0)) # nolint: brace_linter, line_length_linter.
expect_identical(
substr(res, 23, nchar(res)),
c("[EXP] print(1)", "[OUT] #> [1] 1")
)
# nolint next: brace_linter
res <- utils::capture.output(echo({ print(1) }, level = 0))
obj <- substr(res, 23, nchar(res))
exp <- c("[EXP] print(1)", "[OUT] #> [1] 1")
expect_identical(obj, exp)

expect_error(
echo(
exprs = {
print(NULL)
invisible(1)
message("message")
warning("warning")
stop("error")
},
log = NULL
expect_output(
expect_message(
echo(
expr = {
print(NULL)
invisible(1)
message("message")
warning("warning")
stop("error")
},
log = NULL
)
)
)
)

Expand All @@ -27,4 +31,9 @@ test_that("echo() works", {
echo({ 1 }, file = tempfile()), # nolint: brace_linter.
"must be missing"
)

# progress still produces outputs
exprs <- expression(print(1), print(2))
expect_silent(echo(exprs = exprs, level = "NUL", progress = FALSE))
expect_output(echo(exprs = exprs, level = "NUL", progress = TRUE))
})

0 comments on commit fc6815f

Please sign in to comment.