tests/testthat/test-logger.R

context("logger")
withr::with_options(list(DataPackageR_verbose = TRUE),{
  test_that(".multilog_setup", {
    expect_null(DataPackageR:::.multilog_setup(file.path(tempdir(), "test.log")))
  })
  test_that(".multilog_threshold", {
    expect_null(DataPackageR:::.multilog_thresold(INFO, TRACE))
  })
  test_that(".multilog_info", {
    expect_output(DataPackageR:::.multilog_info("message"), "INFO .* message")
    expect_true(file_test("-f", file.path(tempdir(), "test.log")))
  })
  test_that(".multilog_error", {
    expect_output(DataPackageR:::.multilog_error("message"), "ERROR .* message")
  })
  test_that(".multilog_trace", {
    expect_silent(DataPackageR:::.multilog_trace("message"))
    expect_true(length(grep(pattern = "TRACE",
                            readLines(file.path(tempdir(),
                                                "test.log")))) > 0)
  })
  test_that(".multilog_warn", {
    expect_output(DataPackageR:::.multilog_warn("message"), "WARN")
  })
  test_that(".multilog_debug", {
    expect_silent(DataPackageR:::.multilog_debug("message"))
    expect_true(length(grep(pattern = "DEBUG",
                            readLines(file.path(tempdir(),
                                                "test.log")))) > 0)
  })
})

Try the DataPackageR package in your browser

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

DataPackageR documentation built on May 29, 2024, 9:15 a.m.