From 107c493d798da959239585c722409162af7ba0c8 Mon Sep 17 00:00:00 2001 From: Gabor Csardi Date: Thu, 21 Aug 2014 22:43:04 -0400 Subject: [PATCH] Teardown files for test_dir --- R/test-files.r | 4 +++- man/test_dir.Rd | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/R/test-files.r b/R/test-files.r index 1a31629f1..f6e52f740 100644 --- a/R/test-files.r +++ b/R/test-files.r @@ -15,7 +15,8 @@ test_env <- function() { #' #' Test files start with \code{test} and are executed in alphabetical order #' (but they shouldn't have dependencies). Helper files start with -#' \code{helper} and loaded before any tests are run. +#' \code{helper} and loaded before any tests are run. Teardown files +#' start with \code{teardown} and are loaded and run after the tests. #' #' @param path path to tests #' @param reporter reporter to use @@ -32,6 +33,7 @@ test_dir <- function(path, filter = NULL, reporter = "summary", reporter <- MultiReporter$new(reporters = list(current_reporter, lister)) source_dir(path, "^helper.*\\.[rR]$", env = env) + on.exit(source_dir(path, "^teardown.*\\.[rR]$", env = env), add = TRUE) files <- dir(path, "^test.*\\.[rR]$") if (!is.null(filter)) { diff --git a/man/test_dir.Rd b/man/test_dir.Rd index 9a2e0a089..ea7154b6a 100644 --- a/man/test_dir.Rd +++ b/man/test_dir.Rd @@ -22,6 +22,7 @@ a data frame of the summary of test results \description{ Test files start with \code{test} and are executed in alphabetical order (but they shouldn't have dependencies). Helper files start with -\code{helper} and loaded before any tests are run. +\code{helper} and loaded before any tests are run. Teardown files +start with \code{teardown} and are loaded and run after the tests. }