tests/testthat/test-suppress.R

test_that("suppress output", {
  if (getRversion() >= "4.0.0") {
    cnd <- NULL
    tryCatch(
      suppressMessages(cli_text("foo"), "cliMessage"),
      message = function(cnd2) cnd <<- cnd2
    )
    expect_null(cnd)
  }

  mysuppress <- function(expr) {
    withCallingHandlers(
      expr,
      cliMessage = function(msg) invokeRestart("muffleMessage")
    )
  }

  cnd <- NULL
  tryCatch(
    mysuppress(cli_text("foo")),
    message = function(cnd2) cnd <<- cnd2
  )
  expect_null(cnd)
})

Try the cli package in your browser

Any scripts or data that you put into this service are public.

cli documentation built on March 31, 2023, 9:04 p.m.