tests/testthat/test-whirl_r_session.R

test_that("interactive whirl R session components not tested in run", {
  skip_if_no_quarto()
  p <- whirl_r_session$new(verbosity_level = "minimal")

  p$print() |>
    expect_message() |>
    suppressMessages()

  p$get_wd() |>
    dir.exists() |>
    expect_true()

  p$get_wd() |>
    list.files() |>
    sort() |>
    expect_contains(c("dummy.qmd", "log.qmd", "summary.qmd"))

  p$call(func = Sys.sleep, args = list(time = 1)) # Sleep for 1 second

  status <- p$wait(timeout = 10)$check_status() # Timeout after 10 ms
  expect_null(status) # Still running

  status <- p$wait()$check_status()
  expect_equal(status$code, 200L) # Completed successfully

  p$call(func = \() 1 + "a") # Something with an error
  expect_error(p$wait()$check_status())

  # Test temp dir is deleted correctly
  dir <- p$get_wd()
  rm(p)
  gc()

  expect_false(dir.exists(dir))
})

Try the whirl package in your browser

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

whirl documentation built on April 16, 2025, 1:11 a.m.