From fc6815fb3b04493555cc7ae9d4983244fd966487 Mon Sep 17 00:00:00 2001 From: Jordan Mark Barbone Date: Sun, 14 Jan 2024 20:32:18 -0500 Subject: [PATCH] Update test-echo.R (#2) --- tests/testthat/test-echo.R | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/tests/testthat/test-echo.R b/tests/testthat/test-echo.R index 23f319f..c3e3a3f 100644 --- a/tests/testthat/test-echo.R +++ b/tests/testthat/test-echo.R @@ -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 + ) + ) ) ) @@ -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)) })