1library(testthat)
2
3runTests <- function(testDir = NULL, outputDir = NULL, filter = NULL) {
4
5   "%||%" <- function(x, y) if (is.null(x)) y else x
6
7   testDir   <- testDir   %||% Sys.getenv("TESTTHAT_TESTS_DIR",  unset = NA)
8   outputDir <- outputDir %||% Sys.getenv("TESTTHAT_OUTPUT_DIR", unset = NA)
9   filter    <- filter    %||% Sys.getenv("TESTTHAT_FILTER",     unset = "")
10
11   # run tests
12   results <- testthat::test_dir(
13      path            = testDir,
14      filter          = filter,
15      stop_on_failure = FALSE,
16      stop_on_warning = FALSE
17   )
18
19   # compute number of failures
20   df <- as.data.frame(results)
21   failures <- sum(df$failed)
22
23   # write to file
24   cat(failures, file = file.path(outputDir, "testthat-failures.log"))
25
26}
27