1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#' Run all tests in a package
#'
#' @description
#' * `test_local()` tests a local source package.
#' * `test_package()` tests an installed package.
#' * `test_check()` checks a package during `R CMD check`.
#'
#' See `vignette("special-files")` to learn about the various files that
#' testthat works with.
#'
#' @section `R CMD check`:
#' To run testthat automatically from `R CMD check`, make sure you have
#' a `tests/testthat.R` that contains:
#'
#' ```
#' library(testthat)
#' library(yourpackage)
#'
#' test_check("yourpackage")
#' ```
#'
#' @inherit test_dir return params
#' @inheritSection test_dir Environments
#' @param ... Additional arguments passed to [test_dir()]
#' @export
#' @rdname test_package
test_package <- function(package, reporter = check_reporter(), ...) {
test_path <- system.file("tests", "testthat", package = package)
if (test_path == "") {
inform(paste0("No installed testthat tests found for ", package))
return(invisible())
}
test_dir(
test_path,
package = package,
reporter = reporter,
...,
load_package = "installed"
)
}
#' @export
#' @rdname test_package
test_check <- function(package, reporter = check_reporter(), ...) {
require(package, character.only = TRUE)
options(cli.hyperlink = FALSE)
withr::local_envvar(TESTTHAT_IS_CHECKING = "true")
test_dir(
"testthat",
package = package,
reporter = reporter,
...,
load_package = "installed"
)
}
#' @export
#' @rdname test_package
test_local <- function(path = ".", reporter = NULL, ..., load_package = "source") {
package <- pkgload::pkg_name(path)
test_path <- file.path(pkgload::pkg_path(path), "tests", "testthat")
withr::local_envvar(NOT_CRAN = "true")
test_dir(
test_path,
package = package,
reporter = reporter,
...,
load_package = load_package
)
}
|