R/test-path.R

Defines functions test_path

Documented in test_path

#' Locate file in testing directory.
#'
#' This function is designed to work both interactively and during tests,
#' locating files in the `tests/testthat` directory
#'
#' @param ... Character vectors giving path component.
#' @return A character vector giving the path.
#' @export
test_path <- function(...) {
  if (is_testing() && !isTRUE(getOption("testthat_interactive"))) {
    if (missing(...)) {
      "."
    } else {
      file.path(...)
    }
  } else {
    base <- "tests/testthat"
    if (!dir.exists(base)) {
      abort("Can't find `tests/testthat/` in current directory.")
    }
    file.path(base, ...)
  }
}

Try the testthat package in your browser

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

testthat documentation built on Dec. 11, 2021, 9:40 a.m.