|
| 1 | +#' Returns testing depth set by session option or by environmental variable. |
| 2 | +#' |
| 3 | +#' @details Looks for the session option `TESTING_DEPTH` first. |
| 4 | +#' If not set, takes the system environmental variable `TESTING_DEPTH`. |
| 5 | +#' If neither is set, then returns 3 by default. |
| 6 | +#' If the value of `TESTING_DEPTH` is not a numeric of length 1, then returns 3. |
| 7 | +#' |
| 8 | +#' @return `numeric(1)` the testing depth. |
| 9 | +#' |
| 10 | +get_testing_depth <- function() { |
| 11 | + default_depth <- 3 |
| 12 | + depth <- getOption("TESTING_DEPTH", Sys.getenv("TESTING_DEPTH", default_depth)) |
| 13 | + depth <- tryCatch( |
| 14 | + as.numeric(depth), |
| 15 | + error = function(error) default_depth, |
| 16 | + warning = function(warning) default_depth |
| 17 | + ) |
| 18 | + if (length(depth) != 1) depth <- default_depth |
| 19 | + depth |
| 20 | +} |
| 21 | + |
| 22 | +#' Skipping tests in the testthat pipeline under specific scope |
| 23 | +#' @description This function should be used per each `testthat::test_that` call. |
| 24 | +#' Each of the call should specify an appropriate depth value. |
| 25 | +#' The depth value will set the appropriate scope so more/less time consuming tests could be recognized. |
| 26 | +#' The environment variable `TESTING_DEPTH` is used for changing the scope of `testthat` pipeline. |
| 27 | +#' `TESTING_DEPTH` interpretation for each possible value: |
| 28 | +#' \itemize{ |
| 29 | +#' \item{0}{no tests at all} |
| 30 | +#' \item{1}{fast - small scope - executed on every commit} |
| 31 | +#' \item{3}{medium - medium scope - daily integration pipeline} |
| 32 | +#' \item{5}{slow - all tests - daily package tests} |
| 33 | +#' } |
| 34 | +#' @param depth `numeric` the depth of the testing evaluation, |
| 35 | +#' has opposite interpretation to environment variable `TESTING_DEPTH`. |
| 36 | +#' So e.g. `0` means run it always and `5` means a heavy test which should be run rarely. |
| 37 | +#' If the `depth` argument is larger than `TESTING_DEPTH` then the test is skipped. |
| 38 | +#' @importFrom testthat skip |
| 39 | +#' @return `NULL` or invoke an error produced by `testthat::skip` |
| 40 | +#' @note By default `TESTING_DEPTH` is equal to 3 if there is no environment variable for it. |
| 41 | +#' By default `depth` argument lower or equal to 3 will not be skipped because by default `TESTING_DEPTH` |
| 42 | +#' is equal to 3. To skip <= 3 depth tests then the environment variable has to be lower than 3 respectively. |
| 43 | +skip_if_too_deep <- function(depth) { # nolintr |
| 44 | + checkmate::assert_numeric(depth, len = 1, lower = 0, upper = 5) |
| 45 | + testing_depth <- get_testing_depth() # by default 3 if there are no env variable |
| 46 | + if (testing_depth < depth) { |
| 47 | + testthat::skip(paste("testing depth", testing_depth, "is below current testing specification", depth)) |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +default_idle_timeout <- 20000 |
0 commit comments