tests/testthat/test-config.R

test_that("get_config - inexistent config", {
  mock_config_dir <- tempfile("test", fileext = "/")
  local_mocked_bindings(
    R_user_dir = function(package, which) mock_config_dir,
    .package = "myownrobs"
  )
  result <- get_config("test_config")
  expect_null(result)
})

test_that("set_config - write a common config", {
  mock_config_dir <- tempfile("test", fileext = "/")
  local_mocked_bindings(
    R_user_dir = function(package, which) mock_config_dir,
    .package = "myownrobs"
  )
  result <- set_config("test_config", "TRUE")
  expected <- readLines(paste0(mock_config_dir, "/test_config"))
  expect_equal("TRUE", expected)
})

test_that("set_config & get_config - write and read a common config", {
  mock_config_dir <- tempfile("test", fileext = "/")
  local_mocked_bindings(
    R_user_dir = function(package, which) mock_config_dir,
    .package = "myownrobs"
  )
  set_config("test_config", "FALSE")
  expected <- get_config("test_config")
  expect_equal("FALSE", expected)
})

Try the myownrobs package in your browser

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

myownrobs documentation built on Nov. 5, 2025, 5:52 p.m.