R/has_tests.R

Defines functions pkgtest has_tests

Documented in has_tests pkgtest

#' Was devtools installed with tests?
#'
#' @keywords internal
#' @export
has_tests <- function() {
  system.file("tests", package = "pkgload") != ""
}

#' Return the path to one of the packages in the devtools test dir
#'
#' devtools comes with some simple packages for testing. This function
#' returns the path to them.
#'
#' @param package Name of the test package.
#' @keywords internal
#' @examples
#' if (has_tests()) {
#' pkgtest("testData")
#' }
#' @export
pkgtest <- function(package) {
  stopifnot(has_tests())

  path <- system.file(package = "pkgload", "tests", "testthat", package)
  if (path == "") {
    cli::cli_abort("Can't find {.pkg {package}}.")
  }

  path
}
r-pkgs/pkgload documentation built on Feb. 5, 2024, 5:43 a.m.