tests/testthat/test-utils-logging.R

test_that("logging", {

  withr::local_envvar(
    BLOCKR_LOG_LEVEL = "",
    BLOCKR_LOG_MEM = "",
    BLOCKR_LOG_TIME = "",
    BLOCKR_LOGGER = ""
  )

  withr::with_options(
    list(blockr.log_level = "info"),
    {
      expect_identical(get_log_level(), info_log_level)
      expect_silent(log_debug("abc"))
      expect_output(log_warn("abc"), " abc$")
      expect_output(log_warn("abc"), "^\\[WARN\\]")
    }
  )

  withr::with_options(
    list(
      blockr.log_level = "info",
      blockr.log_mem = TRUE,
      blockr.log_time = TRUE
    ),
    {
      expect_true(blockr_option("log_time", FALSE))
      expect_true(blockr_option("log_mem", FALSE))
      expect_output(log_info("abc"), "\\]\\[.+B\\] ")
      expect_output(log_info("abc"), "\\]\\[.+\\]\\[")
    }
  )

  withr::with_options(
    list(
      blockr.log_level = "info",
      blockr.logger = cnd_logger
    ),
    {
      expect_message(log_info("abc"))
      expect_warning(log_warn("abc"))
      expect_warning(log_error("abc"))
      expect_error(log_fatal("abc"))
    }
  )
})

Try the blockr.core package in your browser

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

blockr.core documentation built on June 8, 2025, 1:43 p.m.