tests/testthat/test-examples.R

test_that("All example scripts run with consistent output", {
  skip_if_no_quarto()
  withr::with_tempdir({
    # Copy all example scripts to the temporary working directory

    system.file("examples", package = "whirl") |>
      list.files(full.names = TRUE) |>
      file.copy(recursive = TRUE, to = ".")

    # Run all examples after in separate steps

    res <- list(list.files(pattern = "*.yaml"), list.files(pattern = "*.R$")) |>
      as.list() |>
      run(n_workers = 2) |>
      expect_no_error() |>
      expect_no_warning()

    # Unify result to only be about the status of the script and without
    # the full path to the script

    res$script <- basename(res$script)
    res <- res[c("id", "tag", "script", "status")]

    # Check that the results now are consistent
    expect_snapshot_value(res, style = "json2")
  })
})

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.