diff --git a/tests/testthat/test-ci.R b/tests/testthat/test-ci.R index df42f8cd6..021f77957 100644 --- a/tests/testthat/test-ci.R +++ b/tests/testthat/test-ci.R @@ -1,5 +1,4 @@ test_that("GitHub Actions functionality works", { - # imitate being on GHA whether or not we are withr::local_envvar(list(GITHUB_ACTIONS = "true")) withr::local_options(lintr.rstudio_source_markers = FALSE) tmp <- withr::local_tempfile(lines = "x <- 1:nrow(y)") @@ -9,7 +8,6 @@ test_that("GitHub Actions functionality works", { }) test_that("GitHub Actions functionality works in a subdirectory", { - # imitate being on GHA whether or not we are pkg_path <- test_path("dummy_packages", "assignmentLinter") withr::local_envvar(list(GITHUB_ACTIONS = "true")) withr::local_options(lintr.rstudio_source_markers = FALSE, lintr.github_annotation_project_dir = pkg_path) @@ -26,14 +24,31 @@ test_that("GitHub Actions functionality works in a subdirectory", { ) }) -test_that("GitHub Actions - linting on error works", { - # imitate being on GHA whether or not we are - withr::local_envvar(list(GITHUB_ACTIONS = "true", LINTR_ERROR_ON_LINT = "true")) - withr::local_options(lintr.rstudio_source_markers = FALSE) - tmp <- withr::local_tempfile(lines = "x <- 1:nrow(y)") +patrick::with_parameters_test_that( + "GitHub Actions - error on lint works", + { + withr::local_envvar(list(GITHUB_ACTIONS = "true", LINTR_ERROR_ON_LINT = env_var_value)) + withr::local_options(lintr.rstudio_source_markers = FALSE) + tmp <- withr::local_tempfile(lines = "x <- 1:nrow(y)") - l <- lint(tmp) + l <- lint(tmp) - local_mocked_bindings(quit = function(...) cat("Tried to quit.\n")) - expect_output(print(l), "::warning file", fixed = TRUE) -}) + local_mocked_bindings(quit = function(...) cat("Tried to quit.\n")) + expect_output(print(l), "::warning file", fixed = TRUE) + }, + env_var_value = list("T", "true") +) + +patrick::with_parameters_test_that( + "GitHub Actions - env var for error on lint is converted to logical", + { + withr::local_envvar(list(GITHUB_ACTIONS = "true", LINTR_ERROR_ON_LINT = env_var_value)) + withr::local_options(lintr.rstudio_source_markers = FALSE) + tmp <- withr::local_tempfile(lines = "x <- 1:nrow(y)") + + l <- lint(tmp) + + expect_output(print(l), "::warning file", fixed = TRUE) + }, + env_var_value = list("", "F", NA, NULL) +) diff --git a/tests/testthat/test-settings.R b/tests/testthat/test-settings.R index 27e41bcff..0136fe1ba 100644 --- a/tests/testthat/test-settings.R +++ b/tests/testthat/test-settings.R @@ -88,29 +88,6 @@ test_that("rot utility works as intended", { expect_identical(lintr:::rot(letters), c(letters[14L:26L], LETTERS[1L:13L])) }) -test_that("logical_env utility works as intended", { - test_env <- "LINTR_TEST_LOGICAL_ENV_" - withr::with_envvar( - setNames("true", test_env), - expect_true(lintr:::logical_env(test_env)) - ) - - withr::with_envvar( - setNames("F", test_env), - expect_false(lintr:::logical_env(test_env)) - ) - - withr::with_envvar( - setNames("", test_env), - expect_null(lintr:::logical_env(test_env)) - ) - - withr::with_envvar( - setNames(list(NULL), test_env), - expect_null(lintr:::logical_env(test_env)) - ) -}) - # fixing #774 test_that("linters_with_defaults doesn't break on very long input", { expect_named(