tests/testthat/test-validate_survey_files.R

test_that("validate_survey_files accepts existing files", {
  survey_files <- tempfile(
    pattern = "survey_",
    fileext = ".rds"
  )

  file.create(survey_files)
  on.exit(unlink(survey_files), add = TRUE)

  expect_true(validate_survey_files(survey_files))
})


test_that("validate_survey_files rejects missing files", {
  missing_file <- tempfile(fileext = ".rds")

  expect_error(
    validate_survey_files(missing_file),
    "The following files were not found:",
    fixed = TRUE
  )
})


test_that("validate_survey_files reports actual missing file paths", {
  missing_file <- tempfile(fileext = ".rds")

  expect_error(
    validate_survey_files(missing_file),
    missing_file,
    fixed = TRUE
  )
})


test_that("validate_survey_files handles mixed file availability", {
  existing_file <- tempfile(fileext = ".rds")
  missing_file <- tempfile(fileext = ".rds")

  file.create(existing_file)
  on.exit(unlink(existing_file), add = TRUE)

  expect_error(
    validate_survey_files(c(existing_file, missing_file)),
    paste0("The following files were not found: ", missing_file),
    fixed = TRUE
  )
})


test_that("validate_survey_files accepts multiple existing files", {
  survey_files <- tempfile(
    pattern = rep("survey_", 3),
    fileext = ".rds"
  )

  file.create(survey_files)
  on.exit(unlink(survey_files), add = TRUE)

  expect_true(validate_survey_files(survey_files))
})


test_that("validate_survey_files accepts an empty character vector", {
  expect_true(validate_survey_files(character(0)))
})

Try the retroharmonize package in your browser

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

retroharmonize documentation built on Nov. 29, 2026, 5:06 p.m.