Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an invert argument to find_tests_scripts #239

Merged
merged 2 commits into from
Sep 30, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions R/test-files.r
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,24 @@ source_test_helpers <- function(path, env = globalenv()) {
#' Find the test files.
#' @param path path to tests
#' @param filter cf \code{\link{test_dir}}
#' @param invert If \sQuote{TRUE} return files which do _not_ match.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\emph{}?

#' @param ... Additional arguments passed to \code{grepl} to control filtering.
#' @return the test file paths
#' @keywords internal
#' @export
find_test_scripts <- function(path, filter = NULL, ...) {
find_test_scripts <- function(path, filter = NULL, invert = FALSE, ...) {
files <- dir(path, "^test.*\\.[rR]$", full.names = TRUE)
if (!is.null(filter)) {
test_names <- basename(files)
test_names <- gsub("^test-?", "", test_names)
test_names <- gsub("\\.[rR]", "", test_names)
files <- files[grepl(filter, test_names, ...)]

which_files <- grepl(filter, test_names, ...)

if (isTRUE(invert)) {
which_files <- !which_files
}
files <- files[which_files]
}

files
Expand Down
4 changes: 3 additions & 1 deletion man/find_test_scripts.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
\alias{find_test_scripts}
\title{Find the test files.}
\usage{
find_test_scripts(path, filter = NULL, ...)
find_test_scripts(path, filter = NULL, invert = FALSE, ...)
}
\arguments{
\item{path}{path to tests}

\item{filter}{cf \code{\link{test_dir}}}

\item{invert}{If \sQuote{TRUE} return files which do _not_ match.}

\item{...}{Additional arguments passed to \code{grepl} to control filtering.}
}
\value{
Expand Down