tests/testthat/test-utils-file.R

skip_on_cran()

test_that("data dir", {

  dir <- withr::with_envvar(
    c(RICU_DATA_PATH = NA),
    data_dir(create = FALSE)
  )

  expect_identical(basename(dir), "ricu")

  tmp <- withr::local_tempdir()

  expect_true(dir.exists(tmp))
  expect_false(dir.exists(file.path(tmp, "foo")))

  dir <- withr::with_envvar(
    c(RICU_DATA_PATH = tmp),
    data_dir("foo")
  )

  expect_true(dir.exists(file.path(tmp, "foo")))
})

test_that("set config", {

  cfg <- list(a = 1L, b = 1L:3L, c = list(a = 1L, b = 1L:3L))
  tmp <- withr::local_tempdir()

  expect_false(file.exists(file.path(tmp, "foo.json")))
  expect_null(set_config(cfg, "foo", tmp))
  expect_true(file.exists(file.path(tmp, "foo.json")))

  res <- get_config("foo", tmp)

  expect_identical(cfg, res)
})

Try the ricu package in your browser

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

ricu documentation built on Sept. 8, 2023, 5:45 p.m.