Skip to content

Commit

Permalink
Merge branch 'main' into negative-expect-equal
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil authored Jun 8, 2024
2 parents 36a8c0c + c3ba49b commit 79334a8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
37 changes: 26 additions & 11 deletions tests/testthat/test-ci.R
Original file line number Diff line number Diff line change
@@ -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)")
Expand All @@ -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)
Expand All @@ -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)
)
23 changes: 0 additions & 23 deletions tests/testthat/test-settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 79334a8

Please sign in to comment.