R/example.R

Defines functions testthat_example testthat_examples

Documented in testthat_example testthat_examples

#' Retrieve paths to built-in example test files
#'
#' `testthat_examples()` retrieves path to directory of test files,
#' `testthat_example()` retrieves path to a single test file.
#'
#' @keywords internal
#' @param filename Name of test file
#' @export
#' @examples
#' dir(testthat_examples())
#' testthat_example("success")
testthat_examples <- function() {
  system.file("examples", package = "testthat")
}

#' @export
#' @rdname testthat_examples
testthat_example <- function(filename) {
  system.file(
    "examples", paste0("test-", filename, ".R"),
    package = "testthat",
    mustWork = TRUE
  )
}

Try the testthat package in your browser

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

testthat documentation built on Jan. 21, 2022, 1:10 a.m.