From d37dccb26be9919a0e4e2b88bb76c26f2ae687cf Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Mon, 22 Jul 2024 14:34:55 +0200 Subject: [PATCH] on cran windows, reduce hook tests to one successful and one failing one to save time. --- R/testing.R | 4 + .../test-hook-codemeta-description-updated.R | 52 +++--- tests/testthat/test-hook-deps-in-desc-R.R | 172 ++++++++--------- tests/testthat/test-hook-lintr.R | 22 ++- tests/testthat/test-hook-parsable-R.R | 25 +-- .../testthat/test-hook-readme-rmd-rendered.R | 66 +++---- tests/testthat/test-hook-roxygenize.R | 29 +-- tests/testthat/test-hook-spell-check.R | 38 ++-- tests/testthat/test-hook-style-files.R | 173 +++++++++--------- 9 files changed, 299 insertions(+), 282 deletions(-) diff --git a/R/testing.R b/R/testing.R index ad1e98e11..d50b7afd6 100644 --- a/R/testing.R +++ b/R/testing.R @@ -266,6 +266,10 @@ on_cran <- function() { !identical(Sys.getenv("NOT_CRAN"), "true") } +on_windows_on_cran <- function() { + on_cran() && is_windows() +} + #' The testing environment does not use a conda environment if the env variable #' PRECOMMIT_INSTALLATION_METHOD is not 'conda'. #' @keywords internal diff --git a/tests/testthat/test-hook-codemeta-description-updated.R b/tests/testthat/test-hook-codemeta-description-updated.R index 0ec6e7949..0ed319c0a 100644 --- a/tests/testthat/test-hook-codemeta-description-updated.R +++ b/tests/testthat/test-hook-codemeta-description-updated.R @@ -5,31 +5,6 @@ run_test("codemeta-description-update", std_out = NULL, ) -run_test("codemeta-description-update", - file_name = c("DESCRIPTION"), - suffix = "", - std_err = "No `codemeta.json` found in repository.", - std_out = NULL, -) - - -# outdated -run_test("codemeta-description-update", - file_name = c("DESCRIPTION", "codemeta.json"), - suffix = "", - std_err = "out of date", - std_out = NULL, - file_transformer = function(files) { - if (length(files) > 1) { - # transformer is called once on all files and once per file - content_2 <- readLines(files[1]) - Sys.sleep(2) - writeLines(content_2, files[1]) - } - files - } -) - # succeed run_test("codemeta-description-update", file_name = c("DESCRIPTION", "codemeta.json"), @@ -86,3 +61,30 @@ if (!on_cran()) { } ) } + +if (!on_windows_on_cran()) { + run_test("codemeta-description-update", + file_name = c("DESCRIPTION"), + suffix = "", + std_err = "No `codemeta.json` found in repository.", + std_out = NULL, + ) + + + # outdated + run_test("codemeta-description-update", + file_name = c("DESCRIPTION", "codemeta.json"), + suffix = "", + std_err = "out of date", + std_out = NULL, + file_transformer = function(files) { + if (length(files) > 1) { + # transformer is called once on all files and once per file + content_2 <- readLines(files[1]) + Sys.sleep(2) + writeLines(content_2, files[1]) + } + files + } + ) +} diff --git a/tests/testthat/test-hook-deps-in-desc-R.R b/tests/testthat/test-hook-deps-in-desc-R.R index ff7ab8ddf..fdad32cfa 100644 --- a/tests/testthat/test-hook-deps-in-desc-R.R +++ b/tests/testthat/test-hook-deps-in-desc-R.R @@ -10,17 +10,17 @@ run_test("deps-in-desc", artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")) ) -# in sub directory with wrong root -run_test("deps-in-desc", - suffix = "-fail.R", std_err = "Could not find R package", - file_transformer = function(files) { - fs::path_abs(fs::file_move(files, "rpkg")) - }, - artifacts = c("rpkg/DESCRIPTION" = test_path("in/DESCRIPTION")) -) -# in sub directory with correct root if (!on_cran()) { + # in sub directory with wrong root + run_test("deps-in-desc", + suffix = "-fail.R", std_err = "Could not find R package", + file_transformer = function(files) { + fs::path_abs(fs::file_move(files, "rpkg")) + }, + artifacts = c("rpkg/DESCRIPTION" = test_path("in/DESCRIPTION")) + ) + # in sub directory with correct root run_test("deps-in-desc", cmd_args = "--root=rpkg", suffix = "-fail.R", std_err = "Dependency check failed", @@ -41,93 +41,95 @@ if (!on_cran()) { } -# with ::: -run_test("deps-in-desc", - "deps-in-desc-dot3", - suffix = "-fail.R", std_err = "Dependency check failed", - artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")) -) - -run_test("deps-in-desc", - "deps-in-desc-dot3", - suffix = "-success.R", std_err = NULL, - artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")) -) - -run_test("deps-in-desc", - "deps-in-desc-dot3", - suffix = "-fail.R", std_err = NULL, - artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")), - cmd_args = "--allow_private_imports" -) +if (!on_windows_on_cran()) { + # with ::: + run_test("deps-in-desc", + "deps-in-desc-dot3", + suffix = "-fail.R", std_err = "Dependency check failed", + artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")) + ) -# Rmd -run_test("deps-in-desc", - "deps-in-desc", - suffix = "-fail.Rmd", std_err = "Dependency check failed", - std_out = "deps-in-desc-fail.Rmd`: ttyzp", - artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")) -) + run_test("deps-in-desc", + "deps-in-desc-dot3", + suffix = "-success.R", std_err = NULL, + artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")) + ) -run_test("deps-in-desc", - "deps-in-desc", - suffix = "-success.Rmd", std_err = NULL, - artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")) -) + run_test("deps-in-desc", + "deps-in-desc-dot3", + suffix = "-fail.R", std_err = NULL, + artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")), + cmd_args = "--allow_private_imports" + ) -# README.Rmd is excluded -run_test("deps-in-desc", - "README.Rmd", - suffix = "", std_err = NULL, - artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION-no-deps.dcf")) -) + # Rmd + run_test("deps-in-desc", + "deps-in-desc", + suffix = "-fail.Rmd", std_err = "Dependency check failed", + std_out = "deps-in-desc-fail.Rmd`: ttyzp", + artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")) + ) + run_test("deps-in-desc", + "deps-in-desc", + suffix = "-success.Rmd", std_err = NULL, + artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")) + ) + # README.Rmd is excluded + run_test("deps-in-desc", + "README.Rmd", + suffix = "", std_err = NULL, + artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION-no-deps.dcf")) + ) -# Rnw -run_test("deps-in-desc", - "deps-in-desc", - suffix = "-fail.Rnw", std_err = "Dependency check failed", - artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")) -) -run_test("deps-in-desc", - "deps-in-desc", - suffix = "-success.Rnw", std_err = NULL, - artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")) -) -# Rprofile -# because .Rprofile is executed on startup, this must be an installed -# package (to not give an error staight away) not listed in -# test_path("in/DESCRIPTION") -if (Sys.getenv("GITHUB_WORKFLOW") != "Hook tests") { - # seems like .Rprofile with renv activation does not get executed when - # argument to Rscript contains Rprofile ?! Skip this - expect_true(rlang::is_installed("R.cache")) + # Rnw run_test("deps-in-desc", - "Rprofile", - suffix = "", std_err = "Dependency check failed", - artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")), - file_transformer = function(files) { - writeLines("R.cache::findCache", files) - fs::file_move( - files, - fs::path(fs::path_dir(files), paste0(".", fs::path_file(files))) - ) - } + "deps-in-desc", + suffix = "-fail.Rnw", std_err = "Dependency check failed", + artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")) ) run_test("deps-in-desc", - "Rprofile", - suffix = "", std_err = NULL, - artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")), - file_transformer = function(files) { - writeLines("utils::head", files) - fs::file_move( - files, - fs::path(fs::path_dir(files), paste0(".", fs::path_file(files))) - ) - } + "deps-in-desc", + suffix = "-success.Rnw", std_err = NULL, + artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")) ) + + # Rprofile + # because .Rprofile is executed on startup, this must be an installed + # package (to not give an error staight away) not listed in + # test_path("in/DESCRIPTION") + if (Sys.getenv("GITHUB_WORKFLOW") != "Hook tests") { + # seems like .Rprofile with renv activation does not get executed when + # argument to Rscript contains Rprofile ?! Skip this + expect_true(rlang::is_installed("R.cache")) + run_test("deps-in-desc", + "Rprofile", + suffix = "", std_err = "Dependency check failed", + artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")), + file_transformer = function(files) { + writeLines("R.cache::findCache", files) + fs::file_move( + files, + fs::path(fs::path_dir(files), paste0(".", fs::path_file(files))) + ) + } + ) + + run_test("deps-in-desc", + "Rprofile", + suffix = "", std_err = NULL, + artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")), + file_transformer = function(files) { + writeLines("utils::head", files) + fs::file_move( + files, + fs::path(fs::path_dir(files), paste0(".", fs::path_file(files))) + ) + } + ) + } } diff --git a/tests/testthat/test-hook-lintr.R b/tests/testthat/test-hook-lintr.R index a44fcb23c..0a486e813 100644 --- a/tests/testthat/test-hook-lintr.R +++ b/tests/testthat/test-hook-lintr.R @@ -9,16 +9,18 @@ run_test("lintr", # failure run_test("lintr", suffix = "-fail.R", std_err = "not lint free") -# warning -run_test( - "lintr", - suffix = "-fail.R", cmd_args = "--warn_only", std_err = NULL -) +if (!on_windows_on_cran()) { + # warning + run_test( + "lintr", + suffix = "-fail.R", cmd_args = "--warn_only", std_err = NULL + ) -# .qmd ---- + # .qmd ---- -# success -run_test("lintr", suffix = "-success.qmd", std_err = NULL) + # success + run_test("lintr", suffix = "-success.qmd", std_err = NULL) -# failure -run_test("lintr", suffix = "-fail.qmd", std_err = "not lint free") + # failure + run_test("lintr", suffix = "-fail.qmd", std_err = "not lint free") +} diff --git a/tests/testthat/test-hook-parsable-R.R b/tests/testthat/test-hook-parsable-R.R index a592c413d..619a713e6 100644 --- a/tests/testthat/test-hook-parsable-R.R +++ b/tests/testthat/test-hook-parsable-R.R @@ -2,18 +2,19 @@ run_test("parsable-R", suffix = "-success.R", std_err = NULL ) - -run_test("parsable-R", - suffix = "-success.Rmd", - std_err = NULL -) - # failure run_test("parsable-R", suffix = "-fail.R", std_out = "Full context", std_err = "1 1") -run_test( - "parsable-R", - suffix = "-fail.Rmd", - std_out = "parsable-R-fail.Rmd", - std_err = "1 1" -) +if (!on_windows_on_cran()) { + run_test("parsable-R", + suffix = "-success.Rmd", + std_err = NULL + ) + + run_test( + "parsable-R", + suffix = "-fail.Rmd", + std_out = "parsable-R-fail.Rmd", + std_err = "1 1" + ) +} diff --git a/tests/testthat/test-hook-readme-rmd-rendered.R b/tests/testthat/test-hook-readme-rmd-rendered.R index 7404acd08..79f12cfdc 100644 --- a/tests/testthat/test-hook-readme-rmd-rendered.R +++ b/tests/testthat/test-hook-readme-rmd-rendered.R @@ -17,39 +17,6 @@ if (has_git()) { } ) - - # only one file staged - run_test("readme-rmd-rendered", - file_name = c("README.Rmd", "README.md"), - suffix = "", - std_err = "should be both staged", - std_out = NULL, - file_transformer = function(files) { - if (length(files) > 1) { - # transformer is called once on all files and once per file - content_2 <- readLines(files[2]) - Sys.sleep(2) - writeLines(content_2, files[2]) - git_init() - git2r::add(path = files[1]) - } - files - } - ) - - # only has md - run_test("readme-rmd-rendered", - file_name = "README.md", - suffix = "", - std_err = NULL, - std_out = NULL, - file_transformer = function(files) { - git_init() - git2r::add(path = files[1]) - files - } - ) - # only has Rmd run_test("readme-rmd-rendered", file_name = "README.Rmd", @@ -62,4 +29,37 @@ if (has_git()) { files } ) + if (!on_windows_on_cran()) { + # only one file staged + run_test("readme-rmd-rendered", + file_name = c("README.Rmd", "README.md"), + suffix = "", + std_err = "should be both staged", + std_out = NULL, + file_transformer = function(files) { + if (length(files) > 1) { + # transformer is called once on all files and once per file + content_2 <- readLines(files[2]) + Sys.sleep(2) + writeLines(content_2, files[2]) + git_init() + git2r::add(path = files[1]) + } + files + } + ) + + # only has md + run_test("readme-rmd-rendered", + file_name = "README.md", + suffix = "", + std_err = NULL, + std_out = NULL, + file_transformer = function(files) { + git_init() + git2r::add(path = files[1]) + files + } + ) + } } diff --git a/tests/testthat/test-hook-roxygenize.R b/tests/testthat/test-hook-roxygenize.R index 3954f5c92..7723a977e 100644 --- a/tests/testthat/test-hook-roxygenize.R +++ b/tests/testthat/test-hook-roxygenize.R @@ -55,24 +55,25 @@ if (!on_cran()) { files } ) + + # with Rd present in wrong root + run_test("roxygenize", + file_name = c("R/roxygenize.R" = "roxygenize.R"), + suffix = "", + std_err = "Please commit the new `.Rd` files", + artifacts = c( + "DESCRIPTION" = test_path("in/DESCRIPTION-no-deps.dcf") + ), + file_transformer = function(files) { + git_init() + git2r::add(path = files) + files + } + ) } -# with Rd present in wrong root -run_test("roxygenize", - file_name = c("R/roxygenize.R" = "roxygenize.R"), - suffix = "", - std_err = "Please commit the new `.Rd` files", - artifacts = c( - "DESCRIPTION" = test_path("in/DESCRIPTION-no-deps.dcf") - ), - file_transformer = function(files) { - git_init() - git2r::add(path = files) - files - } -) # with up to date rd present diff --git a/tests/testthat/test-hook-spell-check.R b/tests/testthat/test-hook-spell-check.R index f5e551bc3..0f29eb5d6 100644 --- a/tests/testthat/test-hook-spell-check.R +++ b/tests/testthat/test-hook-spell-check.R @@ -10,23 +10,25 @@ run_test( read_only = TRUE ) -# failure with --read-only does not update WORDLIST -run_test( - "spell-check", - suffix = "-fail-2.md", - std_err = "Spell check failed", - cmd_args = "--read-only", - artifacts = c("inst/WORDLIST" = test_path("in/WORDLIST")), - read_only = TRUE -) +if (!on_windows_on_cran()) { + # failure with --read-only does not update WORDLIST + run_test( + "spell-check", + suffix = "-fail-2.md", + std_err = "Spell check failed", + cmd_args = "--read-only", + artifacts = c("inst/WORDLIST" = test_path("in/WORDLIST")), + read_only = TRUE + ) -# success with wordlist -run_test("spell-check", - suffix = "-wordlist-success.md", - std_err = NULL, - artifacts = c("inst/WORDLIST" = test_path("in/WORDLIST")) -) + # success with wordlist + run_test("spell-check", + suffix = "-wordlist-success.md", + std_err = NULL, + artifacts = c("inst/WORDLIST" = test_path("in/WORDLIST")) + ) -# success with ignored files -# uses lang argument -run_test("spell-check", suffix = "-language-success.md", cmd_args = "--lang=en_GB") + # success with ignored files + # uses lang argument + run_test("spell-check", suffix = "-language-success.md", cmd_args = "--lang=en_GB") +} diff --git a/tests/testthat/test-hook-style-files.R b/tests/testthat/test-hook-style-files.R index f01cfb707..602072b24 100644 --- a/tests/testthat/test-hook-style-files.R +++ b/tests/testthat/test-hook-style-files.R @@ -8,106 +8,109 @@ run_test("style-files", std_err = NA ) -run_test("style-files", - suffix = "-fail-parse.R", cmd_args = c("--cache-root=styler"), - std_err = "" -) -# success with cmd args -run_test("style-files", - file_name = "style-files-cmd", - suffix = "-success.R", - cmd_args = c("--style_pkg=styler", "--style_fun=tidyverse_style", "--cache-root=styler") -) +if (!on_windows_on_cran()) { + run_test("style-files", + suffix = "-fail-parse.R", cmd_args = c("--cache-root=styler"), + std_err = "" + ) -run_test("style-files", - file_name = "style-files-cmd", - suffix = "-success.R", - cmd_args = c("--scope=spaces", "--cache-root=styler") -) + # success with cmd args + run_test("style-files", + file_name = "style-files-cmd", + suffix = "-success.R", + cmd_args = c("--style_pkg=styler", "--style_fun=tidyverse_style", "--cache-root=styler") + ) -run_test("style-files", - file_name = "style-files-cmd", - suffix = "-success.R", - cmd_args = c('--scope="I(\'spaces\')"', "--cache-root=styler") -) + run_test("style-files", + file_name = "style-files-cmd", + suffix = "-success.R", + cmd_args = c("--scope=spaces", "--cache-root=styler") + ) -run_test("style-files", - file_name = "style-files-cmd", - suffix = "-success.R", - cmd_args = c( - '--scope="I(\'spaces\')"', - "--base_indention=0", - "--include_roxygen_examples=TRUE", - "--cache-root=styler" + run_test("style-files", + file_name = "style-files-cmd", + suffix = "-success.R", + cmd_args = c('--scope="I(\'spaces\')"', "--cache-root=styler") ) -) -run_test("style-files", - file_name = "style-files-reindention", - suffix = "-success.R", - cmd_args = c( - '--scope="I(\'spaces\')"', - "--base_indention=0", - "--include_roxygen_examples=TRUE", - '--reindention="specify_reindention(\'#\')"', - "--cache-root=styler" + run_test("style-files", + file_name = "style-files-cmd", + suffix = "-success.R", + cmd_args = c( + '--scope="I(\'spaces\')"', + "--base_indention=0", + "--include_roxygen_examples=TRUE", + "--cache-root=styler" + ) ) -) -run_test("style-files", - file_name = "style-files", - suffix = "-base-indention-success.R", - cmd_args = c("--base_indention=4", "--cache-root=styler") -) + run_test("style-files", + file_name = "style-files-reindention", + suffix = "-success.R", + cmd_args = c( + '--scope="I(\'spaces\')"', + "--base_indention=0", + "--include_roxygen_examples=TRUE", + '--reindention="specify_reindention(\'#\')"', + "--cache-root=styler" + ) + ) -run_test("style-files", - file_name = "style-files", - suffix = "-roxygen-success.R", - cmd_args = c("--include_roxygen_examples=FALSE", "--cache-root=styler") -) + run_test("style-files", + file_name = "style-files", + suffix = "-base-indention-success.R", + cmd_args = c("--base_indention=4", "--cache-root=styler") + ) -run_test("style-files", - file_name = "style-files", - suffix = "-ignore-success.R", - cmd_args = c( - "--cache-root=styler", - '--ignore-start="^# styler: off$"', - '--ignore-stop="^# styler: on$"' + run_test("style-files", + file_name = "style-files", + suffix = "-roxygen-success.R", + cmd_args = c("--include_roxygen_examples=FALSE", "--cache-root=styler") ) -) -run_test("style-files", - file_name = "style-files", - suffix = "-ignore-fail.R", - cmd_args = "--cache-root=styler", - std_err = "" -) + run_test("style-files", + file_name = "style-files", + suffix = "-ignore-success.R", + cmd_args = c( + "--cache-root=styler", + '--ignore-start="^# styler: off$"', + '--ignore-stop="^# styler: on$"' + ) + ) + run_test("style-files", + file_name = "style-files", + suffix = "-ignore-fail.R", + cmd_args = "--cache-root=styler", + std_err = "" + ) -# fail with cmd args -run_test("style-files", - file_name = "style-files-cmd", - suffix = "-success.R", - cmd_args = c("--scope=space", "--cache-root=styler"), - std_err = "", - expect_success = FALSE -) -run_test("style-files", - file_name = "style-files-cmd", - suffix = "-fail.R", - std_err = NA, - cmd_args = c( - "--style_pkg=styler", "--style_fun=tidyverse_style", "--cache-root=styler" + # fail with cmd args + run_test("style-files", + file_name = "style-files-cmd", + suffix = "-success.R", + cmd_args = c("--scope=space", "--cache-root=styler"), + std_err = "", + expect_success = FALSE ) -) -run_test("style-files", - file_name = "style-files-cmd", - suffix = "-fail.R", - std_err = "must be listed in `additional_dependencies:`", - cmd_args = c( - "--style_pkg=blubliblax", "--style_fun=tidyverse_style", "--cache-root=styler" + run_test("style-files", + file_name = "style-files-cmd", + suffix = "-fail.R", + std_err = NA, + cmd_args = c( + "--style_pkg=styler", "--style_fun=tidyverse_style", "--cache-root=styler" + ) ) -) + + run_test("style-files", + file_name = "style-files-cmd", + suffix = "-fail.R", + std_err = "must be listed in `additional_dependencies:`", + cmd_args = c( + "--style_pkg=blubliblax", "--style_fun=tidyverse_style", "--cache-root=styler" + ) + ) +}