Skip to content

Commit

Permalink
Load helpers in test_file.
Browse files Browse the repository at this point in the history
Fixes #350
  • Loading branch information
hadley committed Feb 26, 2016
1 parent 7f39309 commit 326a52c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# testthat 0.11.0.9000

* `test_file()` now loads helpers in the test directory before running
the tests (#350).

* `test_path()` makes it possible to create paths to files in `tests/testthat`
that work interactively and when called from tests (#345).

Expand Down
17 changes: 14 additions & 3 deletions R/test-files.r
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ test_files <- function(paths, reporter = "summary",
current_reporter <- find_reporter(reporter)
with_reporter(
reporter = current_reporter,
results <- lapply(paths, test_file, env = env,
reporter = current_reporter, start_end_reporter = FALSE)
results <- lapply(
paths,
test_file,
env = env,
reporter = current_reporter,
start_end_reporter = FALSE,
load_helpers = FALSE
)
)

results <- unlist(results, recursive = FALSE)
Expand Down Expand Up @@ -85,13 +91,18 @@ find_test_scripts <- function(path, filter = NULL, invert = FALSE, ...) {
#' @param path path to file
#' @param reporter reporter to use
#' @param env environment in which to execute the tests
#' @param load_helpers Source helper files before running the tests?
#' @inheritParams with_reporter
#' @return the results as a "testthat_results" (list)
#' @export
test_file <- function(path, reporter = "summary", env = test_env(),
start_end_reporter = TRUE) {
start_end_reporter = TRUE, load_helpers = TRUE) {
reporter <- find_reporter(reporter)

if (load_helpers) {
source_test_helpers(dirname(path), env = env)
}

lister <- ListReporter$new()
if (!is.null(reporter)) {
reporter <- MultiReporter$new(reporters = list(reporter, lister))
Expand Down
4 changes: 3 additions & 1 deletion man/test_file.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 326a52c

Please sign in to comment.