Skip to content

Commit a08c239

Browse files
committed
explicitely ignore testdata-raw as well as testdata when running test_all()
refactoring, doc
1 parent c2bbe0b commit a08c239

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

R/test_subdir.R

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
#' @export
4747
test_subdir <- function(subdir, base_path = '.', ...){
4848

49-
find_test_dir_mock <- function (path)
50-
{
49+
find_test_dir_mock <- function (path){
5150
testthat <- file.path(path, "tests", "testthat", subdir)
5251
if (dir.exists(testthat))
5352
return(testthat)
@@ -105,7 +104,9 @@ test_manual <- function(base_path = '.', ...){
105104

106105

107106

108-
#' `test_all()` Runs the tests in \file{tests/testthat} and its (first-level) subdirectories
107+
108+
#' `test_all()` Runs the tests in \file{tests/testthat} and all its
109+
#' subdirectories (except \file{testdata} and \file{testdata-raw}).
109110
#' @rdname test_subdir
110111
#' @export
111112
test_all <- function(
@@ -126,10 +127,31 @@ test_all <- function(
126127

127128
testthat::with_mock(
128129
devtools::test(reporter = reporter),
129-
`testthat::find_test_scripts` = function (path, filter = NULL, invert = FALSE, ...) {
130-
files <- dir(path, "^test.*\\.[rR]$", full.names = TRUE, recursive = TRUE)
131-
files <- grep("tests/testthat/testdata", files, value = TRUE, invert = TRUE)
132-
testthat:::filter_test_scripts(files, filter, invert, ...)
133-
}
130+
`testthat::find_test_scripts` = find_test_scripts_mock
134131
)
135132
}
133+
134+
135+
136+
137+
find_test_scripts_mock <- function(
138+
path,
139+
filter = NULL,
140+
invert = FALSE,
141+
...
142+
){
143+
files <- dir(
144+
path, "^test.*\\.[rR]$",
145+
full.names = TRUE,
146+
recursive = TRUE
147+
)
148+
149+
files <- grep(
150+
"tests/testthat/test(data/)|(data-raw/)",
151+
files,
152+
value = TRUE,
153+
invert = TRUE
154+
)
155+
156+
testthat:::filter_test_scripts(files, filter, invert, ...)
157+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
context("Tests in this file should never be run by test_* function")
2+
3+
test_that("this is not be run", {
4+
expect_silent(stop())
5+
})
6+

0 commit comments

Comments
 (0)