diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c68113ae34b581318d04a12b9f9196d997e8b9fd..7c26382b461450aec9d94d5c417b7f9e020a359f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,6 @@ stages: - check - - regression + - scheduled_tests - revdepcheck default: @@ -10,13 +10,14 @@ default: - PATH=~/R/sources/R-${R_VERSION}/bin:$PATH - R -e 'remotes::install_deps(dep = TRUE)' -.regression: - stage: regression +.scheduled_tests: + stage: scheduled_tests script: - - Rscript tests/testthat/regression_tests.R stable + - Rscript tests/scheduled.R + - Rscript tests/regression.R stable - R CMD INSTALL . - - Rscript tests/testthat/regression_tests.R dev - - Rscript tests/testthat/regression_tests.R compare + - Rscript tests/regression.R dev + - Rscript tests/regression.R compare .check: stage: check @@ -33,26 +34,26 @@ default: NOT_CRAN: "false" extends: .check -regression_patched: +scheduled_tests_patched: variables: R_VERSION: "patched" - extends: .regression + extends: .scheduled_tests -regression_devel: +scheduled_tests_devel: only: refs: - schedules variables: R_VERSION: "devel" - extends: .regression + extends: .scheduled_tests -regression_oldrel: +scheduled_tests_oldrel: only: refs: - schedules variables: R_VERSION: "oldrel" - extends: .regression + extends: .scheduled_tests check_not_cran_patched: variables: diff --git a/tests/testthat/helper_regression.R b/tests/regression.R similarity index 74% rename from tests/testthat/helper_regression.R rename to tests/regression.R index bc05c5521a19946aa2cef6170f7f28f830dfefe2..34f7f5461fb2eceec8131f13743c4d2dadad8d7e 100644 --- a/tests/testthat/helper_regression.R +++ b/tests/regression.R @@ -1,3 +1,5 @@ +# Helper functions for regression + StoreStableExampleResults <- function( package = "airGR", path = file.path("tests/tmp", Sys.getenv("R_VERSION"), "stable"), @@ -81,3 +83,27 @@ CompareStableDev <- function() { quit(status = 1) } } + +############### +# MAIN SCRIPT # +############### + +# Execute Regression test by comparing RD files stored in folders /tests/tmp/ref and /tests/tmp/test +Args <- commandArgs(trailingOnly = TRUE) + +lActions <- list( + stable = StoreStableExampleResults, + dev = StoreDevExampleResults, + compare = CompareStableDev +) + +if(length(Args) == 1 && Args %in% names(lActions)) { + lActions[[Args]]() +} else { + stop("This script should be run with one argument in the command line:\n", + "`Rscript tests/regression_tests.R [stable|dev|compare]`.\n", + "Available arguments are:\n", + "- stable: install stable version from CRAN, run and store examples\n", + "- dev: install dev version from current directory, run and store examples\n", + "- compare: stored results of both versions") +} diff --git a/tests/scheduled.R b/tests/scheduled.R new file mode 100644 index 0000000000000000000000000000000000000000..c8f4d7ee8db6177d4a643f6b315e9a10f80f8229 --- /dev/null +++ b/tests/scheduled.R @@ -0,0 +1,47 @@ +#' Script for running scheduled test +#' +#' All files with the pattern /testthat/tests/scheduled-*.R are tested +#' as testthat does for files /testthat/tests/test-*.R. +#' +#' This script should be started with `source` command from the root of the package. +#' @example +#' source("tests/scheduled.R") + +#################### +# Helper functions # +#################### + +#' Wrapper for [quit] which is only applied outside of RStudio +#' +#' @param status See `status` parameter of [quit]. Default `quit = 1`. +#' @param ... Other parameters sent to [quit] +#' +#' @return NULL +#' @export +quit2 <- function(status = 1, ...) { + if (all(!grepl("rstudio", Sys.getenv(), ignore.case = TRUE))) { + quit(status, ...) + } +} + +############### +# MAIN SCRIPT # +############### + +library(testthat) +library(airGR) + +scheduled_tests <- +list.files( + path = "tests/testthat", + pattern = "^scheduled-.*\\.R$", + full.names = TRUE +) + +lRes = lapply(scheduled_tests, test_file) +for (res in lRes) { + dRes <- as.data.frame(res) + if (any(dRes[, "failed"] > 0) | any(dRes[, "error"])) { + quit2() + } +} diff --git a/tests/testthat/regression_tests.R b/tests/testthat/regression_tests.R deleted file mode 100644 index 4456e09edc85aaa6b06bd36f3b518d41c192e786..0000000000000000000000000000000000000000 --- a/tests/testthat/regression_tests.R +++ /dev/null @@ -1,21 +0,0 @@ -# Execute Regression test by comparing RD files stored in folders /tests/tmp/ref and /tests/tmp/test -Args <- commandArgs(trailingOnly = TRUE) - -source("tests/testthat/helper_regression.R") - -lActions <- list( - stable = StoreStableExampleResults, - dev = StoreDevExampleResults, - compare = CompareStableDev -) - -if(Args %in% names(lActions)) { - lActions[[Args]]() -} else { - stop("This script should be run with one argument in the command line:\n", - "`Rscript tests/regression_tests.R [stable|dev|compare]`.\n", - "Available arguments are:\n", - "- stable: install stable version from CRAN, run and store examples\n", - "- dev: install dev version from current directory, run and store examples\n", - "- compare: stored results of both versions") -} diff --git a/tests/testthat/test-Calibration.R b/tests/testthat/scheduled-Calibration.R similarity index 99% rename from tests/testthat/test-Calibration.R rename to tests/testthat/scheduled-Calibration.R index 49d44ca1c4f4eef5e1b7accbdb1d3e1346d20660..673ad265893a3a76fd638857b1114c03bd88fa83 100644 --- a/tests/testthat/test-Calibration.R +++ b/tests/testthat/scheduled-Calibration.R @@ -107,7 +107,6 @@ TestModelCalibration <- function(model) { model <- as.list(model) test_that(paste(model$name, ifelse(as.logical(model$IsHyst), "Hysteresis", ""), "works"), { - skip_on_cran() ParamFinalR <- ModelCalibration(model)