Commit 6cbced89 authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

Merge branch '69-regression-tests-are-not-functionning' into 'dev'

Resolve "Regression tests are not functionning"

Closes #69

See merge request !18
Showing with 90 additions and 17 deletions
+90 -17
...@@ -33,17 +33,11 @@ default: ...@@ -33,17 +33,11 @@ default:
.regression: .regression:
stage: regression stage: regression
only:
refs:
- schedules
script: script:
- Rscript -e 'source("tests/testthat/store_examples.R"); StoreRefExampleResults("airGR");' - Rscript tests/testthat/regression_tests.R stable
- R CMD INSTALL . - R CMD INSTALL .
- Rscript -e 'source("tests/testthat/store_examples.R"); StoreTestExampleResults("airGR");' - Rscript tests/testthat/regression_tests.R dev
artifacts: - Rscript tests/testthat/regression_tests.R compare
paths:
- tests/tmp/
expire_in: 1 week
.check_not_cran: .check_not_cran:
stage: tests stage: tests
...@@ -73,11 +67,17 @@ regression_patched: ...@@ -73,11 +67,17 @@ regression_patched:
extends: .regression extends: .regression
regression_devel: regression_devel:
only:
refs:
- schedules
variables: variables:
R_VERSION: "devel" R_VERSION: "devel"
extends: .regression extends: .regression
regression_oldrel: regression_oldrel:
only:
refs:
- schedules
variables: variables:
R_VERSION: "oldrel" R_VERSION: "oldrel"
extends: .regression extends: .regression
......
...@@ -5,3 +5,4 @@ ...@@ -5,3 +5,4 @@
# Example for ignoring OutputsModel variable produced by example("RunModel_GR2M"): RunModel_GR2M OutputsModel # Example for ignoring OutputsModel variable produced by example("RunModel_GR2M"): RunModel_GR2M OutputsModel
RunModel_GR2M OutputsModel RunModel_GR2M OutputsModel
RunModel_GR2M RunOptions RunModel_GR2M RunOptions
RunModel_GR1A OutputsModel
StoreRefExampleResults <- function(package, ...) { StoreStableExampleResults <- function(
package = "airGR",
path = file.path("tests/tmp", Sys.getenv("R_VERSION"), "stable"),
...) {
install.packages(package, repos = "http://cran.r-project.org") install.packages(package, repos = "http://cran.r-project.org")
StoreExampleResults(package = package, path = "tests/tmp/ref", ...) StoreExampleResults(package = package, path = path, ...)
} }
StoreTestExampleResults <- function(package, ...) { StoreDevExampleResults <- function(
StoreExampleResults( package = "airGR",
package = package, path = file.path("tests/tmp", Sys.getenv("R_VERSION"), "dev"),
path = file.path("tests/tmp", Sys.getenv("R_VERSION", "test")), ...) {
... StoreExampleResults(package = package, path = path, ...)
)
} }
#' Run examples of a package and store the output variables in RDS files for further testing. #' Run examples of a package and store the output variables in RDS files for further testing.
...@@ -72,3 +74,8 @@ StoreTopicResults <- function(topic, package, path, run.dontrun = TRUE, run.dont ...@@ -72,3 +74,8 @@ StoreTopicResults <- function(topic, package, path, run.dontrun = TRUE, run.dont
} }
CompareStableDev <- function() {
res = testthat::test_file("tests/testthat/regression.R")
dRes = as.data.frame(res)
if(any(dRes[,"failed"]>0) | any(dRes[,"error"])) quit(status = 1)
}
context("Compare example outputs with CRAN") context("Compare example outputs with CRAN")
CompareWithRef <- function(refVarFile, testDir, regIgnore) { CompareWithStable <- function(refVarFile, testDir, regIgnore) {
v <- data.frame(topic = basename(dirname(refVarFile)), v <- data.frame(topic = basename(dirname(refVarFile)),
var = gsub("\\.rds$", "", basename(refVarFile))) var = gsub("\\.rds$", "", basename(refVarFile)))
if (is.null(regIgnore) || all(apply(regIgnore, 1, function(x) !all(x == v)))) { if (is.null(regIgnore) || all(apply(regIgnore, 1, function(x) !all(x == v)))) {
test_that(paste("Compare", v$topic, v$var), { test_that(paste("Compare", v$topic, v$var), {
skip_on_cran()
testVarFile <- paste0( testVarFile <- paste0(
file.path("../tmp", Sys.getenv("R_VERSION", "test"), v$topic, v$var), file.path(testDir, v$topic, v$var),
".rds" ".rds"
) )
expect_true(file.exists(testVarFile)) expect_true(file.exists(testVarFile))
...@@ -20,23 +19,26 @@ CompareWithRef <- function(refVarFile, testDir, regIgnore) { ...@@ -20,23 +19,26 @@ CompareWithRef <- function(refVarFile, testDir, regIgnore) {
} }
} }
if (dir.exists("../tmp/ref") & dir.exists("../tmp/test")) { tmp_path <- file.path("../tmp", Sys.getenv("R_VERSION"));
refVarFiles <- list.files("../tmp/ref", recursive = TRUE, full.names = TRUE)
regIgnoreFile <- "../../.regressionignore2" if (dir.exists(file.path(tmp_path, "stable")) & dir.exists(file.path(tmp_path, "dev"))) {
refVarFiles <- list.files(file.path(tmp_path, "stable"), recursive = TRUE, full.names = TRUE)
regIgnoreFile <- "../../.regressionignore"
if (file.exists(regIgnoreFile)) { if (file.exists(regIgnoreFile)) {
message("Using .regressionignore file. The following variables are going to be skipped:")
regIgnore <- read.table(file = regIgnoreFile, regIgnore <- read.table(file = regIgnoreFile,
sep = " ", header = FALSE, skip = 5, sep = " ", header = FALSE, skip = 5,
col.names = c("topic", "var"), col.names = c("topic", "var"),
stringsAsFactors = FALSE) stringsAsFactors = FALSE)
apply(regIgnore, 1, function(x) message(x[1], ": ", x[2]))
} else { } else {
message("File ", file.path(getwd(), regIgnoreFile), " not found")
regIgnore <- NULL regIgnore <- NULL
} }
lapply(X = refVarFiles, CompareWithRef, testDir = "../tmp/test", regIgnore = regIgnore) lapply(X = refVarFiles, CompareWithStable, testDir = file.path(tmp_path, "dev"), regIgnore = regIgnore)
} else { } else {
warning("Regression tests compared to released version needs that you run the following instructions first:\n", stop("Regression tests compared to released version needs that you run the following instructions first:\n",
"Rscript -e 'source(\"tests/testthat/store_examples.R\"); StoreRefExampleResults(\"airGR\");'\n", "Rscript tests/testthat/regression_tests.R stable\n",
"R CMD INSTALL .\n", "R CMD INSTALL .\n",
"Rscript -e 'source(\"tests/testthat/store_examples.R\"); StoreTestExampleResults(\"airGR\");'\n") "Rscript tests/testthat/regression_tests.R dev")
} }
# 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")
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment