From cdaf688c8b3b8fc28b4fcac33bda91de8ecb78b4 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 5 Dec 2023 19:19:03 +0100 Subject: [PATCH] all but namespaced functions covered --- R/lintr-package.R | 1 + tests/testthat/test-cache.R | 3 +-- tests/testthat/test-ci.R | 12 +++--------- tests/testthat/test-rstudio_markers.R | 2 +- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/R/lintr-package.R b/R/lintr-package.R index 3305e5901..898db1445 100644 --- a/R/lintr-package.R +++ b/R/lintr-package.R @@ -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 diff --git a/tests/testthat/test-cache.R b/tests/testthat/test-cache.R index 792786495..6b0c47aa1 100644 --- a/tests/testthat/test-cache.R +++ b/tests/testthat/test-cache.R @@ -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) diff --git a/tests/testthat/test-ci.R b/tests/testthat/test-ci.R index 6da47a84f..8bab65609 100644 --- a/tests/testthat/test-ci.R +++ b/tests/testthat/test-ci.R @@ -27,8 +27,6 @@ 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) @@ -36,32 +34,28 @@ test_that("GitHub Actions - linting on error works", { 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) }) diff --git a/tests/testthat/test-rstudio_markers.R b/tests/testthat/test-rstudio_markers.R index 203e87a41..3a9fb2aef 100644 --- a/tests/testthat/test-rstudio_markers.R +++ b/tests/testthat/test-rstudio_markers.R @@ -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)