Skip to content

Commit 67941cd

Browse files
committed
Support developer tests.
1 parent fe38519 commit 67941cd

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

R/test-files.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ local_teardown_env <- function(frame = parent.frame()) {
373373
#' @export
374374
find_test_scripts <- function(path, filter = NULL, invert = FALSE, ..., full.names = TRUE, start_first = NULL) {
375375
files <- dir(path, "^test.*\\.[rR]$", full.names = full.names)
376+
if (env_var_is_true("CI") || env_var_is_true("NOT_CRAN")) {
377+
devfiles <- dir(path, "^dev-test.*\\.[rR]$", full.names = full.names)
378+
files <- c(files, devfiles)
379+
}
376380
files <- filter_test_scripts(files, filter, invert, ...)
377381
order_test_scripts(files, start_first)
378382
}

tests/testthat/test-test-files.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,23 @@ test_that("stops on failure", {
88
})
99

1010
test_that("runs all tests and records output", {
11-
withr::local_envvar(TESTTHAT_PARALLEL = "FALSE")
11+
withr::local_envvar(TESTTHAT_PARALLEL = "FALSE", NOT_CRAN = "false", CI = "false")
1212
res <- test_dir(test_path("test_dir"), reporter = "silent", stop_on_failure = FALSE)
1313
df <- as.data.frame(res)
1414
df$user <- df$system <- df$real <- df$result <- NULL
1515

16+
expect_equal(nrow(df), 17)
1617
local_reproducible_output(width = 200)
1718
local_edition(3) # set to 2 in ./test_dir
1819
expect_snapshot_output(print(df))
1920
})
2021

22+
test_that("runs additional dev tests", {
23+
withr::local_envvar(TESTTHAT_PARALLEL = "FALSE", NOT_CRAN = "true")
24+
res <- test_dir(test_path("test_dir"), reporter = "silent", stop_on_failure = FALSE)
25+
expect_equal(nrow(as.data.frame(res)), 18)
26+
})
27+
2128
test_that("complains if no files", {
2229
withr::local_envvar(TESTTHAT_PARALLEL = "FALSE")
2330
path <- withr::local_tempfile()

vignettes/special-files.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This vignette describes the various special files that testthat understands: tes
2424
## Test files
2525

2626
These are the bread and butter of testthat.
27-
Test files live in `tests/testthat/`, start with either `test-` or `test_`, and end with `.r` or `.R`.
27+
Public test files live in `tests/testthat/`, start with either `test-` or `test_`, and end with `.r` or `.R`. Additional developer tests use the same pattern but prefixed with `dev-`.
2828
We recommend organising your test files so that there's a one-to-one correspondence between the files in `R/` and the files in `tests/testthat/` so that (e.g.) `R/myfile.R` has a matching `tests/testthat/test-myfile.R`.
2929
This correspondence is maintained by functions like `usethis::use_r()` and `usethis::use_test()` and is taken advantage of by functions like `devtools::test_active_file()` and `devtools::test_coverage_active_file()`.
3030

0 commit comments

Comments
 (0)