R/roclet_clean.roclet_tests.R

Defines functions roclet_clean.roclet_tests

Documented in roclet_clean.roclet_tests

#'
#' Delete Unit Test Files Generated by @tests Tags
#'
#' Delete unit test files generated by @tests tags. Activated when
#' calling \code{roxygenize} with \code{clean = TRUE}.
#'
#' @param x A \code{roclet} object.
#'
#' @param base_path Path to root of source package.
#'
#' @return NULL  If found, files created by \code{roxut} will be deleted.
#'
#' @author Bryan A. Hanson
#' @importFrom stats na.omit
#' @export
#'

roclet_clean.roclet_tests <- function(x, base_path) {

  # To stay close to roxygen2, we can't include a "framework" argument,
  # so we'll clean all possibilites
  ut_testthat <- dir(file.path(base_path, "tests/testthat"), full.names = TRUE)
  ut_tinytest <- dir(file.path(base_path, "inst/tinytest"), full.names = TRUE)
  ut <- c(ut_testthat, ut_tinytest)
  ut <- ut[!file.info(ut)$isdir]
  remove <- NA_character_
  for (i in 1:length(ut)) {
    line1 <- readLines(ut[i], n = 1)
    if (grepl("# File created by roxut;", line1)) remove <- c(remove, ut[i])
  }
  unlink(na.omit(remove))
}

Try the roxut package in your browser

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

roxut documentation built on Aug. 23, 2021, 1:10 a.m.