File: test-suppress.R

package info (click to toggle)
r-cran-cli 3.6.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,288 kB
  • sloc: ansic: 16,412; cpp: 37; sh: 13; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 499 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

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)
})