From 791556a7835a419e3c8b5c18f527678380dba02a Mon Sep 17 00:00:00 2001 From: Jan Wijffels Date: Thu, 26 Aug 2021 10:27:04 +0200 Subject: [PATCH] Change unit testing from testthat to tinytest. Fix unit test of "/opt" folder --- DESCRIPTION | 15 ++++++++------- inst/NEWS | 5 +++++ inst/tinytest/test_cron_add.R | 6 ++++++ .../tinytest/test_general_tests.R | 7 +------ inst/tinytest/test_verify_script_path.R | 12 ++++++++++++ tests/testthat.R | 3 --- tests/testthat/test-cron_add.R | 12 ------------ tests/testthat/test-verify_script_path.R | 13 ------------- tests/tinytest.R | 4 ++++ 9 files changed, 36 insertions(+), 41 deletions(-) create mode 100644 inst/tinytest/test_cron_add.R rename tests/testthat/test-general_tests.R => inst/tinytest/test_general_tests.R (87%) create mode 100644 inst/tinytest/test_verify_script_path.R delete mode 100644 tests/testthat.R delete mode 100644 tests/testthat/test-cron_add.R delete mode 100644 tests/testthat/test-verify_script_path.R create mode 100644 tests/tinytest.R diff --git a/DESCRIPTION b/DESCRIPTION index 7b4468b..f6470a1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,23 +1,24 @@ Package: cronR Type: Package Title: Schedule R Scripts and Processes with the 'cron' Job Scheduler -Version: 0.5.0 -Authors@R: c(person("Jan", "Wijffels", role = c("aut", "cre", "cph"), email = - "jwijffels@bnosac.be"), person("BNOSAC", role = "cph"), person("Kevin", "Ushey", - role = c("cph"), email = "kevinushey@gmail.com")) +Version: 0.5.1 +Authors@R: c( + person("Jan", "Wijffels", role = c("aut", "cre", "cph"), email = "jwijffels@bnosac.be"), + person("BNOSAC", role = "cph"), + person("Kevin", "Ushey", role = c("cph"), email = "kevinushey@gmail.com")) Maintainer: Jan Wijffels Description: Create, edit, and remove 'cron' jobs on your unix-alike system. The package provides a set of easy-to-use wrappers to 'crontab'. It also provides an RStudio add-in to easily launch and schedule your scripts. URL: https://github.com/bnosac/cronR -Imports: +Imports: digest -Suggests: +Suggests: knitr, rmarkdown, miniUI, shiny (>= 0.11), shinyFiles (>= 0.6.0), - testthat + tinytest License: MIT + file LICENSE VignetteBuilder: knitr OS_type: unix diff --git a/inst/NEWS b/inst/NEWS index f1e063b..4c48556 100644 --- a/inst/NEWS +++ b/inst/NEWS @@ -1,6 +1,11 @@ Package: cronR ================ +Version: 0.5.1 [2021-08-26] + +- Switch unit testing from testthat to tinytest +- Fix unit test if user has access rights to /opt folder (e.g. as root) + Version: 0.5.0 [2021-08-20] - Change default directory of R script deployment in the addin: cron_rstudioaddin diff --git a/inst/tinytest/test_cron_add.R b/inst/tinytest/test_cron_add.R new file mode 100644 index 0000000..774739c --- /dev/null +++ b/inst/tinytest/test_cron_add.R @@ -0,0 +1,6 @@ +myscript <- system.file("extdata", "helloworld.R", package = "cronR") + +f <- system.file(package = "cronR", "extdata", "helloworld.R") +cmd <- cron_rscript(f) +expect_silent(cron_add(command = cmd, frequency = 'minutely', id = 'abc', description = 'My process 1')) +expect_silent(cron_clear(ask = FALSE)) \ No newline at end of file diff --git a/tests/testthat/test-general_tests.R b/inst/tinytest/test_general_tests.R similarity index 87% rename from tests/testthat/test-general_tests.R rename to inst/tinytest/test_general_tests.R index d7e638d..2074abf 100644 --- a/tests/testthat/test-general_tests.R +++ b/inst/tinytest/test_general_tests.R @@ -1,8 +1,5 @@ -context("cronR-general") -test_that("cronR general examples work as expected", { - skip_on_cran() - +expect_silent({ cron_ls() cron_njobs() cron_add("testing!", id="abc", tags=c("test1", "test2"), @@ -32,6 +29,4 @@ test_that("cronR general examples work as expected", { cron_njobs() cron_ls("abc") cron_clear(FALSE) - }) - diff --git a/inst/tinytest/test_verify_script_path.R b/inst/tinytest/test_verify_script_path.R new file mode 100644 index 0000000..19afe07 --- /dev/null +++ b/inst/tinytest/test_verify_script_path.R @@ -0,0 +1,12 @@ +path <- "/opt" +if(!is.na(file.info(path)$isdir) && file.access(path, mode = 2)){ + expect_warning( + cronR:::verify_rscript_path(path), + "You do not have write access to the specified Rscript repository path, /opt." + ) +} + +expect_warning( + cronR:::verify_rscript_path("/DirClearlyDoesNotExist"), + "The specified Rscript repository path /DirClearlyDoesNotExist does not exist, make sure this is an existing directory without spaces." +) \ No newline at end of file diff --git a/tests/testthat.R b/tests/testthat.R deleted file mode 100644 index 7cacf72..0000000 --- a/tests/testthat.R +++ /dev/null @@ -1,3 +0,0 @@ -library(testthat) -library(cronR) -test_check("cronR") \ No newline at end of file diff --git a/tests/testthat/test-cron_add.R b/tests/testthat/test-cron_add.R deleted file mode 100644 index 5437388..0000000 --- a/tests/testthat/test-cron_add.R +++ /dev/null @@ -1,12 +0,0 @@ -context("cronR-examples") - -test_that("cronR examples can be scheduled as expected", { - skip_on_cran() - - myscript <- system.file("extdata", "helloworld.R", package = "cronR") - - f <- system.file(package = "cronR", "extdata", "helloworld.R") - cmd <- cron_rscript(f) - expect_error(cron_add(command = cmd, frequency = 'minutely', id = 'abc', description = 'My process 1'), NA) - expect_warning(cron_clear(ask = FALSE), NA) -}) \ No newline at end of file diff --git a/tests/testthat/test-verify_script_path.R b/tests/testthat/test-verify_script_path.R deleted file mode 100644 index 8abf77c..0000000 --- a/tests/testthat/test-verify_script_path.R +++ /dev/null @@ -1,13 +0,0 @@ -test_that("verify_rscript_path shows warning messages correctly", { - - expect_warning( - cronR:::verify_rscript_path("/opt"), - "You do not have write access to the specified Rscript repository path, /opt." - ) - - expect_warning( - cronR:::verify_rscript_path("/DirClearlyDoesNotExist"), - "The specified Rscript repository path /DirClearlyDoesNotExist does not exist, make sure this is an existing directory without spaces." - ) - -}) diff --git a/tests/tinytest.R b/tests/tinytest.R new file mode 100644 index 0000000..ad420fe --- /dev/null +++ b/tests/tinytest.R @@ -0,0 +1,4 @@ +if(requireNamespace("tinytest", quietly=TRUE)){ + home <- identical(Sys.getenv("HONEYIMHOME"), "TRUE") || identical(Sys.info()[["nodename"]], "live") + tinytest::test_package("cronR", at_home = home) +}