File: has_tests.R

package info (click to toggle)
r-cran-pkgload 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,164 kB
  • sloc: sh: 13; cpp: 9; ansic: 8; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 681 bytes parent folder | download | duplicates (3)
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
#' 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
}