Skip to content

Commit f2409ea

Browse files
Use public interface to test logical_env()
cf. #1692
1 parent 1c7f4a0 commit f2409ea

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

tests/testthat/test-ci.R

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
test_that("GitHub Actions functionality works", {
2-
# imitate being on GHA whether or not we are
32
withr::local_envvar(list(GITHUB_ACTIONS = "true"))
43
withr::local_options(lintr.rstudio_source_markers = FALSE)
54
tmp <- withr::local_tempfile(lines = "x <- 1:nrow(y)")
@@ -9,7 +8,6 @@ test_that("GitHub Actions functionality works", {
98
})
109

1110
test_that("GitHub Actions functionality works in a subdirectory", {
12-
# imitate being on GHA whether or not we are
1311
pkg_path <- test_path("dummy_packages", "assignmentLinter")
1412
withr::local_envvar(list(GITHUB_ACTIONS = "true"))
1513
withr::local_options(lintr.rstudio_source_markers = FALSE, lintr.github_annotation_project_dir = pkg_path)
@@ -26,8 +24,21 @@ test_that("GitHub Actions functionality works in a subdirectory", {
2624
)
2725
})
2826

29-
test_that("GitHub Actions - linting on error works", {
30-
# imitate being on GHA whether or not we are
27+
patrick::with_parameters_test_that(
28+
"GitHub Actions - env var for error on lint is converted to logical",
29+
{
30+
withr::local_envvar(list(GITHUB_ACTIONS = "true", LINTR_ERROR_ON_LINT = env_var_value))
31+
withr::local_options(lintr.rstudio_source_markers = FALSE)
32+
tmp <- withr::local_tempfile(lines = "x <- 1:nrow(y)")
33+
34+
l <- lint(tmp)
35+
36+
expect_output(print(l), "::warning file", fixed = TRUE)
37+
},
38+
env_var_value = c("", "F", NA),
39+
)
40+
41+
test_that("GitHub Actions - error on lint works", {
3142
withr::local_envvar(list(GITHUB_ACTIONS = "true", LINTR_ERROR_ON_LINT = "true"))
3243
withr::local_options(lintr.rstudio_source_markers = FALSE)
3344
tmp <- withr::local_tempfile(lines = "x <- 1:nrow(y)")

tests/testthat/test-settings.R

-23
Original file line numberDiff line numberDiff line change
@@ -88,29 +88,6 @@ test_that("rot utility works as intended", {
8888
expect_identical(lintr:::rot(letters), c(letters[14L:26L], LETTERS[1L:13L]))
8989
})
9090

91-
test_that("logical_env utility works as intended", {
92-
test_env <- "LINTR_TEST_LOGICAL_ENV_"
93-
withr::with_envvar(
94-
setNames("true", test_env),
95-
expect_true(lintr:::logical_env(test_env))
96-
)
97-
98-
withr::with_envvar(
99-
setNames("F", test_env),
100-
expect_false(lintr:::logical_env(test_env))
101-
)
102-
103-
withr::with_envvar(
104-
setNames("", test_env),
105-
expect_null(lintr:::logical_env(test_env))
106-
)
107-
108-
withr::with_envvar(
109-
setNames(list(NULL), test_env),
110-
expect_null(lintr:::logical_env(test_env))
111-
)
112-
})
113-
11491
# fixing #774
11592
test_that("linters_with_defaults doesn't break on very long input", {
11693
expect_named(

0 commit comments

Comments
 (0)