tests/testthat/test-doctest-onetime_do.R

# Generated by doctest: do not edit by hand
# Please edit file in R/onetime.R

test_that("Doctest: onetime_do", {
  # Created from @doctest for `onetime_do`
  # Source file: R/onetime.R
  # Source line: 39
  oo <- options(onetime.dir = tempdir(check = TRUE))
  id <- sample(10000L, 1L)
  for (n in 1:3) {
    expect_output(onetime_do(print("printed once"), id = id), regexp = if (n == 1L) "once" else NA)
  }
  id2 <- sample(10000L, 1L)
  expiry <- as.difftime(1, units = "secs")
  onetime_do(print("Expires quickly, right?"), id = id2, expiry = expiry)
  Sys.sleep(2)
  expect_silent(onetime_do(print("This won't be shown..."), id = id2))
  expect_output(onetime_do(print("... but this will"), id = id2, expiry = expiry), "but this will")
  onetime_reset(id = id)
  onetime_reset(id = id2)
  options(oo)
})

Try the onetime package in your browser

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

onetime documentation built on Sept. 3, 2023, 9:06 a.m.