diff --git a/tests/testthat/test_dockerize.R b/tests/testthat/test_dockerize.R index c715b5d..c9c70a6 100644 --- a/tests/testthat/test_dockerize.R +++ b/tests/testthat/test_dockerize.R @@ -1,3 +1,7 @@ +.gen_temp_dir <- function() { + file.path(tempdir(), paste(sample(c(LETTERS, letters), 20, replace = TRUE), collapse = "")) +} + test_that("defensive programming", { graph <- readRDS("../testdata/sle_graph.RDS") expect_error(dockerize(graph, output_dir = tempdir())) @@ -5,7 +9,7 @@ test_that("defensive programming", { test_that("integration of #13 in dockerize()", { gran_ok <- readRDS("../testdata/gran_ok.RDS") - temp_dir <- file.path(tempdir(), sample(1:10000, size = 1)) + temp_dir <- .gen_temp_dir() dockerize(granlist = gran_ok, output_dir = temp_dir) ## granlist_as_comment = TRUE x <- readLines(file.path(temp_dir, "gran.R")) expect_true(any(grepl("^## ## To reconstruct this file", x))) @@ -17,7 +21,7 @@ test_that("integration of #13 in dockerize()", { test_that("integration of #16 in dockerize()", { ## verbose gran_ok <- readRDS("../testdata/gran_ok.RDS") - temp_dir <- file.path(tempdir(), sample(1:10000, size = 1)) + temp_dir <- .gen_temp_dir() dockerize(granlist = gran_ok, output_dir = temp_dir) ## verbose = TRUE x <- readLines(file.path(temp_dir, "gran.R")) expect_true(any(grepl("^verbose <- TRUE", x))) @@ -39,7 +43,7 @@ test_that("integration of #16 in dockerize()", { test_that("integration of #18 in dockerize()", { gran_ok <- readRDS("../testdata/gran_ok.RDS") - temp_dir <- file.path(tempdir(), sample(1:10000, size = 1)) + temp_dir <- .gen_temp_dir() dockerize(granlist = gran_ok, output_dir = temp_dir) ## cran_mirror = "https://cran.r-project.org/" x <- readLines(file.path(temp_dir, "gran.R")) expect_true(any(grepl("^cran_mirror <- \"https://cran\\.r\\-project\\.org/\"", x))) @@ -58,7 +62,7 @@ test_that("integration of #18 in dockerize()", { test_that("integration of #20 to dockerize()", { gran_ok <- readRDS("../testdata/gran_ok.RDS") expect_equal(gran_ok$r_version, "4.2.2") - temp_dir <- file.path(tempdir(), sample(1:10000, size = 1)) + temp_dir <- .gen_temp_dir() dockerize(gran_ok, output_dir = temp_dir) ## cran_mirror = "https://cran.r-project.org/" x <- readLines(file.path(temp_dir, "gran.R")) expect_true(any(grepl("^cran_mirror <- \"https://cran\\.r\\-project\\.org/\"", x))) @@ -78,7 +82,7 @@ test_that("integration of #20 to dockerize()", { test_that("Dockerize R < 3.1 and >= 2.1", { gran_rio <- readRDS("../testdata/gran_rio_old.RDS") expect_equal(gran_rio$r_version, "3.0.1") - temp_dir <- file.path(tempdir(), sample(1:10000, size = 1)) + temp_dir <- .gen_temp_dir() dockerize(gran_rio, output_dir = temp_dir) expect_true(file.exists(file.path(temp_dir, "compile_r.sh"))) Dockerfile <- readLines(file.path(temp_dir, "Dockerfile")) @@ -92,7 +96,7 @@ test_that("Dockerize R < 3.1 and >= 2.1", { test_that("Docker R < 2.1", { gran_rio <- readRDS("../testdata/gran_rio_old.RDS") gran_rio$r_version <- "2.1.0" ## exactly 2.1.0, no error - temp_dir <- file.path(tempdir(), sample(1:10000, size = 1)) + temp_dir <- .gen_temp_dir() expect_error(dockerize(gran_rio, output_dir = temp_dir), NA) gran_rio <- readRDS("../testdata/gran_rio_old.RDS") gran_rio$r_version <- "2.0.0" @@ -115,6 +119,7 @@ test_that(".consolidate_sysreqs and issue #21", { test_that("Dockerize warning, issue #21", { graph <- readRDS("../testdata/issue21.RDS") - temp_dir <- file.path(tempdir(), sample(1:10000, size = 1)) + temp_dir <- .gen_temp_dir() expect_warning(dockerize(graph, output_dir = temp_dir)) }) + diff --git a/tests/testthat/test_resolve.R b/tests/testthat/test_resolve.R index c25c452..61278ad 100644 --- a/tests/testthat/test_resolve.R +++ b/tests/testthat/test_resolve.R @@ -1,3 +1,7 @@ +.gen_temp_dir <- function() { + file.path(tempdir(), paste(sample(c(LETTERS, letters), 20, replace = TRUE), collapse = "")) +} + test_that("defensive programming", { expect_error(resolve("LDAvis", os = "windows")) }) @@ -48,7 +52,7 @@ test_that("cache #17", { skip_if_offline() skip_on_cran() gran_ok <- readRDS("../testdata/gran_ok.RDS") - temp_dir <- file.path(tempdir(), sample(1:10000, size = 1)) + temp_dir <- .gen_temp_dir() dockerize(gran_ok, output_dir = temp_dir) ## cache = FALSE x <- readLines(file.path(temp_dir, "Dockerfile")) expect_false(any(grepl("^COPY cache", x))) @@ -71,7 +75,7 @@ test_that("cache for R < 3.1 and R >= 2.1", { skip_on_cran() gran_rio <- readRDS("../testdata/gran_rio_old.RDS") expect_equal(gran_rio$r_version, "3.0.1") - temp_dir <- file.path(tempdir(), sample(1:10000, size = 1)) + temp_dir <- .gen_temp_dir() dockerize(gran_rio, output_dir = temp_dir, cache = TRUE, verbose = FALSE) x <- readLines(file.path(temp_dir, "Dockerfile")) expect_true(any(grepl("^COPY cache", x)))