Skip to content

Commit

Permalink
all but namespaced functions covered
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Dec 5, 2023
1 parent 4d4962e commit cdaf688
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
1 change: 1 addition & 0 deletions R/lintr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ NULL
# make binding available for mock testing
# ref: https://testthat.r-lib.org/dev/reference/local_mocked_bindings.html#base-functions
unlink <- NULL
quit <- NULL
3 changes: 1 addition & 2 deletions tests/testthat/test-cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,9 @@ test_that("lint with cache uses the provided relative cache directory", {
})

test_that("it works outside of a package", {
skip_if_not_installed("mockery")
linter <- assignment_linter()

mockery::stub(lintr:::find_default_encoding, "find_package", function(...) NULL)
local_mocked_bindings(find_package = function(...) NULL)
path <- withr::local_tempfile(pattern = "my_cache_dir_")
expect_false(dir.exists(path))
expect_lint("a <- 1", NULL, linter, cache = path)
Expand Down
12 changes: 3 additions & 9 deletions tests/testthat/test-ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,35 @@ test_that("GitHub Actions functionality works in a subdirectory", {
})

test_that("GitHub Actions - linting on error works", {
skip_if_not_installed("mockery")

# 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)")

l <- lint(tmp)

mockery::stub(print.lints, "base::quit", function(...) cat("Tried to quit.\n"))
local_mocked_bindings(quit = function(...) cat("Tried to quit.\n"))
expect_output(print(l), "::warning file", fixed = TRUE)
})

test_that("Printing works for Travis", {
skip_if_not_installed("mockery")

withr::local_envvar(list(GITHUB_ACTIONS = "false", TRAVIS_REPO_SLUG = "test/repo", LINTR_COMMENT_BOT = "true"))
withr::local_options(lintr.rstudio_source_markers = FALSE)
tmp <- withr::local_tempfile(lines = "x <- 1:nrow(y)")

l <- lint(tmp)

mockery::stub(print.lints, "github_comment", function(x, ...) cat(x, "\n"))
local_mocked_bindings(github_comment = function(x, ...) cat(x, "\n"))
expect_output(print(l), "*warning:*", fixed = TRUE)
})

test_that("Printing works for Wercker", {
skip_if_not_installed("mockery")

withr::local_envvar(list(GITHUB_ACTIONS = "false", WERCKER_GIT_BRANCH = "test/repo", LINTR_COMMENT_BOT = "true"))
withr::local_options(lintr.rstudio_source_markers = FALSE)
tmp <- withr::local_tempfile(lines = "x <- 1:nrow(y)")

l <- lint(tmp)

mockery::stub(print.lints, "github_comment", function(x, ...) cat(x, "\n"))
local_mocked_bindings(github_comment = function(x, ...) cat(x, "\n"))
expect_output(print(l), "*warning:*", fixed = TRUE)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-rstudio_markers.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ test_that("rstudio_source_markers apply to print within rstudio", {
empty <- withr::local_tempfile(lines = character(0L))

mockery::stub(print.lints, "rstudioapi::hasFun", function(x, ...) TRUE)
mockery::stub(print.lints, "rstudio_source_markers", function(x) cat("matched\n"))
local_mocked_bindings(rstudio_source_markers = function(x) cat("matched\n"))

l <- lint(tmp, seq_linter())
expect_output(print(l), "matched", fixed = TRUE)
Expand Down

0 comments on commit cdaf688

Please sign in to comment.