Skip to content

Commit

Permalink
on cran windows, reduce hook tests to one successful and one failing …
Browse files Browse the repository at this point in the history
…one to save time.
  • Loading branch information
lorenzwalthert committed Jul 22, 2024
1 parent b372db1 commit d37dccb
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 282 deletions.
4 changes: 4 additions & 0 deletions R/testing.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 27 additions & 25 deletions tests/testthat/test-hook-codemeta-description-updated.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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
}
)
}
172 changes: 87 additions & 85 deletions tests/testthat/test-hook-deps-in-desc-R.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)))
)
}
)
}
}
22 changes: 12 additions & 10 deletions tests/testthat/test-hook-lintr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
25 changes: 13 additions & 12 deletions tests/testthat/test-hook-parsable-R.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}
Loading

0 comments on commit d37dccb

Please sign in to comment.