Skip to content

Commit

Permalink
Look in inst/test and test/thatthat
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Jun 17, 2013
1 parent 7fb14f9 commit d0d73e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions NEWS
@@ -1,6 +1,8 @@
devtools 1.2.99
----------------

* `test` now looks in both `inst/test` and `tests/testthat` for unit tests.

* Files are now loaded in a way that preserves srcreferences - this means
that you will get much better locations on error messages, which should
considerably aid debugging.
Expand Down
23 changes: 14 additions & 9 deletions R/test.r
Expand Up @@ -12,13 +12,8 @@
test <- function(pkg = ".", filter = NULL, fresh = FALSE) {
pkg <- as.package(pkg)

path_test <- file.path(pkg$path, "inst", "tests")
if (!file.exists(path_test)) {
message("No tests found: inst/tests not present")
return(invisible())
}

test_files <- dir(path_test, "^test.*\\.[rR]$")
test_path <- find_test_dir(pkg$path)
test_files <- dir(test_path, "^test.*\\.[rR]$")
if (length(test_files) == 0) {
message("No tests found: no files matching pattern '^test.*\\.[rR]$'",
"found in inst/tests")
Expand All @@ -32,18 +27,28 @@ test <- function(pkg = ".", filter = NULL, fresh = FALSE) {
require("testthat", quiet = TRUE)

load_all(.(pkg$path), quiet = TRUE)
test_dir(.(path_test), filter = .(filter))
test_dir(.(test_path), filter = .(filter))
})
eval_clean(to_run)
} else {
require(testthat)
# Run tests in a child of the namespace environment, like testthat::test_package
load_all(pkg)
env <- new.env(parent = ns_env(pkg))
with_envvar(r_env_vars(), test_dir(path_test, filter = filter, env = env))
with_envvar(r_env_vars(), test_dir(test_path, filter = filter, env = env))
}
}

find_test_dir <- function(path) {
testthat <- file.path(path, "tests", "testthat")
if (file.exists(testthat)) return(testthat)

inst <- file.path(path, "inst", "tests")
if (file.exists(inst)) return(inst)

stop("No testthat directories found in ", path, call. = FALSE)
}


#' Return the path to one of the packages in the devtools test dir
#'
Expand Down

0 comments on commit d0d73e5

Please sign in to comment.