tests/testthat/test-timed.R

test_that("interruption of long evaluations works", {
  foo <- function(x) {
    for (i in 1:10) Sys.sleep(x / 10)
    return(x)
  }
  expect_error(
    timed(foo(0.5), "1"),
    "Assertion on 'seconds' failed: Must be of type 'number', not 'character'."
  )
  expect_equal(
    timed(foo(0.5), 5),
    0.5
  )
  expect_null(
    timed(foo(5), 1, "silent")
  )
  expect_warning(
    timed(foo(5), 1, "warning"),
    "time limit exceeded"
  )
  expect_error(
    timed(foo(5), 1, "error"),
    "time limit exceeded"
  )
})

Try the oeli package in your browser

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

oeli documentation built on Oct. 16, 2024, 5:08 p.m.