From 8f5d3a0add3690a370b33cd1a746899a8a45d66c Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 3 Mar 2022 23:25:20 -0800 Subject: [PATCH 1/8] Start using testthat 3e --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index a9c206640..8d8e5378b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,12 +34,13 @@ Suggests: mockery, rmarkdown, rstudioapi (>= 0.2), - testthat (>= 2.2.1), + testthat (>= 3.0.0), withr License: MIT + file LICENSE Encoding: UTF-8 VignetteBuilder: knitr RoxygenNote: 7.1.2 +Config/testthat/edition: 3 Collate: 'utils.R' 'aaa.R' From e365f176aeb22e17b1fc33f5d5f7fdd4847f62b7 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Wed, 9 Mar 2022 02:34:12 -0800 Subject: [PATCH 2/8] get migrated tests passing --- NEWS.md | 1 + tests/testthat/test-cache.R | 158 +++++++----------- tests/testthat/test-ci.R | 78 ++++----- tests/testthat/test-commented_code_linter.R | 2 +- tests/testthat/test-defaults.R | 6 +- tests/testthat/test-get_source_expressions.R | 37 ++-- tests/testthat/test-implicit_integer_linter.R | 2 +- tests/testthat/test-knitr_formats.R | 4 +- tests/testthat/test-lint_file.R | 3 +- tests/testthat/test-methods.R | 6 +- tests/testthat/test-object_name_linter.R | 66 ++++---- tests/testthat/test-rstudio_markers.R | 61 +++---- 12 files changed, 188 insertions(+), 236 deletions(-) diff --git a/NEWS.md b/NEWS.md index 012c76259..a76b20290 100644 --- a/NEWS.md +++ b/NEWS.md @@ -79,6 +79,7 @@ function calls. (#850, #851, @renkun-ken) * Debugging functions (`browser()`, `debug()`, `debugcall()`, `debugonce()`, `trace()`, `undebug()`, `untrace()`) are now part of the default set of undesirable functions to help prevent them from being committed by mistake. (#876, @michaelchirico) * New linter `package_hooks_linter()` runs a series of checks also done by `R CMD check` on the `.onLoad()`, `.onAttach()`, `.Last.lib()` and `.onDetach()` hooks (#882, @MichaelChirico) * Improved location information for R parse errors (#894, #892, @renkun-ken and @AshesITR) +* `lintr` now uses the 3rd edition of `testthat` (@MichaelChirico) # lintr 2.0.1 diff --git a/tests/testthat/test-cache.R b/tests/testthat/test-cache.R index 9d4693a01..b6d00cf8f 100644 --- a/tests/testthat/test-cache.R +++ b/tests/testthat/test-cache.R @@ -53,116 +53,92 @@ test_that("clear_cache deletes the directory if no file is given", { # `load_cache` test_that("load_cache loads the saved file in a new empty environment", { - with_mock( - `lintr::read_settings` = function(...) invisible(...), - - e1 <- new.env(parent = emptyenv()), - assign("x", "foobar", envir = e1), - d1 <- tempfile(pattern = "lintr_cache_"), - f1 <- "R/test.R", - save_cache(cache = e1, file = f1, path = d1), - e2 <- load_cache(file = f1, path = d1), - - expect_equal(ls(e2), "x"), - expect_equal(e2[["x"]], "foobar") - ) + e1 <- new.env(parent = emptyenv()) + assign("x", "foobar", envir = e1) + d1 <- tempfile(pattern = "lintr_cache_") + f1 <- "R/test.R" + save_cache(cache = e1, file = f1, path = d1) + e2 <- load_cache(file = f1, path = d1) + + expect_equal(ls(e2), "x") + expect_equal(e2[["x"]], "foobar") }) test_that("load_cache returns an empty environment if no cache file exists", { - with_mock( - `lintr::read_settings` = function(...) invisible(...), - - e1 <- new.env(parent = emptyenv()), - d1 <- tempfile(pattern = "lintr_cache_"), - f1 <- "R/test.R", - f2 <- "test.R", + e1 <- new.env(parent = emptyenv()) + d1 <- tempfile(pattern = "lintr_cache_") + f1 <- "R/test.R" + f2 <- "test.R" - save_cache(cache = e1, file = f1, path = d1), - e2 <- load_cache(file = f2, path = d1), + save_cache(cache = e1, file = f1, path = d1) + e2 <- load_cache(file = f2, path = d1) - expect_equal(ls(e2), character(0)) - ) + expect_equal(ls(e2), character(0)) }) test_that("load_cache returns an empty environment if reading cache file fails", { - with_mock( - `lintr::read_settings` = function(...) invisible(...), - - e1 <- new.env(parent = emptyenv()), - assign("x", "foobar", envir = e1), - d1 <- tempfile(pattern = "lintr_cache_"), - f1 <- "R/test.R", - save_cache(cache = e1, file = f1, path = d1), - cache_f1 <- file.path(d1, fhash(f1)), - writeLines(character(), cache_f1), - expect_warning(e2 <- load_cache(file = f1, path = d1)), - saveRDS(e1, cache_f1), - expect_warning(e3 <- load_cache(file = f1, path = d1)), - expect_equal(ls(e2), character(0)), - expect_equal(ls(e3), character(0)) - ) + e1 <- new.env(parent = emptyenv()) + assign("x", "foobar", envir = e1) + d1 <- tempfile(pattern = "lintr_cache_") + f1 <- "R/test.R" + save_cache(cache = e1, file = f1, path = d1) + cache_f1 <- file.path(d1, fhash(f1)) + writeLines(character(), cache_f1) + expect_warning(e2 <- load_cache(file = f1, path = d1)) + saveRDS(e1, cache_f1) + expect_warning(e3 <- load_cache(file = f1, path = d1)) + expect_equal(ls(e2), character(0)) + expect_equal(ls(e3), character(0)) }) # `save_cache` test_that("save_cache creates a directory if needed", { - with_mock( - `lintr::read_settings` = function(...) invisible(...), - - e1 <- new.env(parent = emptyenv()), - d1 <- tempfile(pattern = "lintr_cache_"), - f1 <- "R/test.R", + e1 <- new.env(parent = emptyenv()) + d1 <- tempfile(pattern = "lintr_cache_") + f1 <- "R/test.R" - expect_false(file.exists(d1)), - expect_false(file.exists(file.path(d1, fhash(f1)))), + expect_false(file.exists(d1)) + expect_false(file.exists(file.path(d1, fhash(f1)))) - save_cache(cache = e1, file = f1, path = d1), + save_cache(cache = e1, file = f1, path = d1) - expect_true(file.exists(d1)), - expect_true(file.info(d1)$isdir), - expect_true(file.exists(file.path(d1, fhash(f1)))) - ) + expect_true(file.exists(d1)) + expect_true(file.info(d1)$isdir) + expect_true(file.exists(file.path(d1, fhash(f1)))) }) test_that("save_cache uses unambiguous cache file names", { - with_mock( - `lintr::read_settings` = function(...) invisible(...), - - e1 <- new.env(parent = emptyenv()), - d1 <- tempfile(pattern = "lintr_cache_"), - f1 <- "R/test.R", - f2 <- "test.R", + e1 <- new.env(parent = emptyenv()) + d1 <- tempfile(pattern = "lintr_cache_") + f1 <- "R/test.R" + f2 <- "test.R" - expect_false(file.exists(file.path(d1, fhash(f1)))), - expect_false(file.exists(file.path(d1, fhash(f2)))), + expect_false(file.exists(file.path(d1, fhash(f1)))) + expect_false(file.exists(file.path(d1, fhash(f2)))) - save_cache(cache = e1, file = f1, path = d1), - save_cache(cache = e1, file = f2, path = d1), + save_cache(cache = e1, file = f1, path = d1) + save_cache(cache = e1, file = f2, path = d1) - expect_true(fhash(f1) != fhash(f2)), - expect_true(file.exists(file.path(d1, fhash(f1)))), - expect_true(file.exists(file.path(d1, fhash(f2)))) - ) + expect_true(fhash(f1) != fhash(f2)) + expect_true(file.exists(file.path(d1, fhash(f1)))) + expect_true(file.exists(file.path(d1, fhash(f2)))) }) test_that("save_cache saves all non-hidden objects from the environment", { - with_mock( - `lintr::read_settings` = function(...) invisible(...), - - e1 <- new.env(parent = emptyenv()), - e1$t1 <- 1, - e1$t2 <- 2, + e1 <- new.env(parent = emptyenv()) + e1$t1 <- 1 + e1$t2 <- 2 - d1 <- tempfile(pattern = "lintr_cache_"), - f1 <- "R/test.R", + d1 <- tempfile(pattern = "lintr_cache_") + f1 <- "R/test.R" - save_cache(cache = e1, file = f1, path = d1), + save_cache(cache = e1, file = f1, path = d1) - e2 <- new.env(parent = emptyenv()), - load(file = file.path(d1, fhash(f1)), envir = e2), + e2 <- new.env(parent = emptyenv()) + load(file = file.path(d1, fhash(f1)), envir = e2) - expect_equal(e1, e2) - ) + expect_identical(as.list(e1), as.list(e2)) }) # `cache_file` @@ -435,18 +411,14 @@ test_that("lint with cache uses the provided relative cache directory", { test_that("it works outside of a package", { linter <- assignment_linter() - with_mock( - `lintr::find_package` = function(...) NULL, - `lintr::pkg_name` = function(...) NULL, - - path <- tempfile(pattern = "my_cache_dir_"), - expect_false(dir.exists(path)), - expect_lint("a <- 1", NULL, linter, cache = path), - expect_true(dir.exists(path)), - expect_length(list.files(path), 1), - expect_lint("a <- 1", NULL, linter, cache = path), - expect_true(dir.exists(path)) - ) + mockery::stub(lintr:::find_default_encoding, "find_package", function(...) NULL) + path <- tempfile(pattern = "my_cache_dir_") + expect_false(dir.exists(path)) + expect_lint("a <- 1", NULL, linter, cache = path) + expect_true(dir.exists(path)) + expect_length(list.files(path), 1) + expect_lint("a <- 1", NULL, linter, cache = path) + expect_true(dir.exists(path)) }) test_that("cache = TRUE workflow works", { diff --git a/tests/testthat/test-ci.R b/tests/testthat/test-ci.R index 9eb1117a4..de13b25c6 100644 --- a/tests/testthat/test-ci.R +++ b/tests/testthat/test-ci.R @@ -1,67 +1,55 @@ test_that("GitHub Actions functionality works", { # imitate being on GHA whether or not we are - withr::with_envvar(c(GITHUB_ACTIONS = "true"), { - old <- options(lintr.rstudio_source_markers = FALSE) - on.exit(options(old), add = TRUE) + withr::local_envvar(list(GITHUB_ACTIONS = "true")) + withr::local_options(lintr.rstudio_source_markers = FALSE) + tmp <- withr::local_tempfile() - writeLines("x <- 1:nrow(y)", tmp <- tempfile()) - on.exit(unlink(tmp)) + writeLines("x <- 1:nrow(y)", tmp) - l <- lint(tmp) - expect_output(print(l), "::warning file", fixed = TRUE) - }) + l <- lint(tmp) + expect_output(print(l), "::warning file", fixed = TRUE) }) test_that("GitHub Actions functionality works in a subdirectory", { # imitate being on GHA whether or not we are pkg_path <- file.path("dummy_packages", "assignmentLinter") - withr::with_envvar(c(GITHUB_ACTIONS = "true"), { - old <- options( - lintr.rstudio_source_markers = FALSE, - lintr.github_annotation_project_dir = pkg_path - ) - on.exit(options(old), add = TRUE) - - read_settings(NULL) - l <- lint_package( - pkg_path, linters = list(assignment_linter()), - parse_settings = FALSE - ) - expect_output( - print(l), - paste0("::warning file=", file.path(pkg_path, "R(/|\\\\)abc\\.R")) - ) - }) + withr::local_envvar(list(GITHUB_ACTIONS = "true")) + withr::local_options(lintr.rstudio_source_markers = FALSE, lintr.github_annotation_project_dir = pkg_path) + + read_settings(NULL) + l <- lint_package( + pkg_path, + linters = list(assignment_linter()), + parse_settings = FALSE + ) + expect_output( + print(l), + paste0("::warning file=", file.path(pkg_path, "R(/|\\\\)abc\\.R")) + ) }) test_that("Printing works for Travis", { - withr::with_envvar(c(GITHUB_ACTIONS = "false", TRAVIS_REPO_SLUG = "test/repo", LINTR_COMMENT_BOT = "true"), { - old <- options(lintr.rstudio_source_markers = FALSE) - on.exit(options(old), add = TRUE) + 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() + writeLines("x <- 1:nrow(y)", tmp) - writeLines("x <- 1:nrow(y)", tmp <- tempfile()) - on.exit(unlink(tmp)) + l <- lint(tmp) - l <- lint(tmp) - - with_mock(github_comment = function(x, ...) cat(x, "\n"), .env = asNamespace("lintr"), { - expect_output(print(l), "*warning:*", fixed = TRUE) - }) + with_mock(github_comment = function(x, ...) cat(x, "\n"), .env = asNamespace("lintr"), { + expect_output(print(l), "*warning:*", fixed = TRUE) }) }) test_that("Printing works for Wercker", { - withr::with_envvar(c(GITHUB_ACTIONS = "false", WERCKER_GIT_BRANCH = "test/repo", LINTR_COMMENT_BOT = "true"), { - old <- options(lintr.rstudio_source_markers = FALSE) - on.exit(options(old), add = TRUE) - - writeLines("x <- 1:nrow(y)", tmp <- tempfile()) - on.exit(unlink(tmp)) + 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() + writeLines("x <- 1:nrow(y)", tmp) - l <- lint(tmp) + l <- lint(tmp) - with_mock(github_comment = function(x, ...) cat(x, "\n"), .env = asNamespace("lintr"), { - expect_output(print(l), "*warning:*", fixed = TRUE) - }) + with_mock(github_comment = function(x, ...) cat(x, "\n"), .env = asNamespace("lintr"), { + expect_output(print(l), "*warning:*", fixed = TRUE) }) }) diff --git a/tests/testthat/test-commented_code_linter.R b/tests/testthat/test-commented_code_linter.R index 9eb40b307..ab13ed83b 100644 --- a/tests/testthat/test-commented_code_linter.R +++ b/tests/testthat/test-commented_code_linter.R @@ -1,7 +1,7 @@ test_that("returns the correct linting", { msg <- rex("Commented code should be removed.") linter <- commented_code_linter() - expect_is(linter, "linter") + expect_s3_class(linter, "linter") expect_lint("blah", NULL, linter) diff --git a/tests/testthat/test-defaults.R b/tests/testthat/test-defaults.R index eaf9257d4..422508d16 100644 --- a/tests/testthat/test-defaults.R +++ b/tests/testthat/test-defaults.R @@ -1,7 +1,7 @@ test_that("linters", { # non-empty named list of functions x <- default_linters - expect_is(x, "list") + expect_type(x, "list") expect_gt(length(x), 0L) expect_true(all(names(x) != "")) expect_true(all(vapply(x, inherits, logical(1L), "linter"))) @@ -14,7 +14,7 @@ test_that("undesirable functions and operators", { all_undesirable_operators, default_undesirable_operators) for (x in vars) { - expect_is(x, "list") + expect_type(x, "list") expect_gt(length(x), 0L) expect_true(all(names(x) != "")) expect_true(all(vapply(x, function(x) is.na(x) || is.character(x), logical(1L)))) @@ -25,7 +25,7 @@ test_that("undesirable functions and operators", { test_that("settings", { # non-empty named list x <- default_settings - expect_is(x, "list") + expect_type(x, "list") expect_gt(length(x), 0L) expect_true(all(names(x) != "")) }) diff --git a/tests/testthat/test-get_source_expressions.R b/tests/testthat/test-get_source_expressions.R index 53e390d90..bb8749ce2 100644 --- a/tests/testthat/test-get_source_expressions.R +++ b/tests/testthat/test-get_source_expressions.R @@ -18,45 +18,48 @@ test_that("tab positions have been corrected", { ) with_content_to_parse("TRUE", - expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "TRUE", c("col1", "col2")], c(1L, 4L)) + expect_identical(unlist(pc[[1L]][pc[[1L]][["text"]] == "TRUE", c("col1", "col2")], use.names = FALSE), c(1L, 4L)) ) with_content_to_parse("\tTRUE", - expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "TRUE", c("col1", "col2")], c(2L, 5L)) + expect_identical(unlist(pc[[1L]][pc[[1L]][["text"]] == "TRUE", c("col1", "col2")], use.names = FALSE), c(2L, 5L)) ) with_content_to_parse("\t\tTRUE", - expect_equivalent(pc[[1]][pc[[1L]][["text"]] == "TRUE", c("col1", "col2")], c(3L, 6L)) + expect_identical(unlist(pc[[1]][pc[[1L]][["text"]] == "TRUE", c("col1", "col2")], use.names = FALSE), c(3L, 6L)) ) with_content_to_parse("x\t<-\tTRUE", { - expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "x", c("col1", "col2")], c(1L, 1L)) - expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "<-", c("col1", "col2")], c(3L, 4L)) - expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "TRUE", c("col1", "col2")], c(6L, 9L)) + expect_identical(unlist(pc[[1L]][pc[[1L]][["text"]] == "x", c("col1", "col2")], use.names = FALSE), c(1L, 1L)) + expect_identical(unlist(pc[[1L]][pc[[1L]][["text"]] == "<-", c("col1", "col2")], use.names = FALSE), c(3L, 4L)) + expect_identical(unlist(pc[[1L]][pc[[1L]][["text"]] == "TRUE", c("col1", "col2")], use.names = FALSE), c(6L, 9L)) }) with_content_to_parse("\tfunction\t(x)\t{\tprint(pc[\t,1])\t;\t}", { - expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "function", c("col1", "col2")], c(2L, 9L)) - expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "x", c("col1", "col2")], c(12L, 12L)) - expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "print", c("col1", "col2")], c(17L, 21L)) - expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == ";", c("col1", "col2")], c(32L, 32L)) - expect_equivalent(pc[[1L]][pc[[1L]][["text"]] == "}", c("col1", "col2")], c(34L, 34L)) + expect_identical( + unlist(pc[[1L]][pc[[1L]][["text"]] == "function", c("col1", "col2")], use.names = FALSE), + c(2L, 9L) + ) + expect_identical(unlist(pc[[1L]][pc[[1L]][["text"]] == "x", c("col1", "col2")], use.names = FALSE), c(12L, 12L)) + expect_identical(unlist(pc[[1L]][pc[[1L]][["text"]] == "print", c("col1", "col2")], use.names = FALSE), c(17L, 21L)) + expect_identical(unlist(pc[[1L]][pc[[1L]][["text"]] == ";", c("col1", "col2")], use.names = FALSE), c(32L, 32L)) + expect_identical(unlist(pc[[1L]][pc[[1L]][["text"]] == "}", c("col1", "col2")], use.names = FALSE), c(34L, 34L)) }) with_content_to_parse("# test tab\n\ns <- 'I have \\t a dog'\nrep(\ts, \t3)", { - expect_equivalent( - pc[[2L]][pc[[2L]][["text"]] == "'I have \\t a dog'", c("line1", "col1", "col2")], + expect_identical( + unlist(pc[[2L]][pc[[2L]][["text"]] == "'I have \\t a dog'", c("line1", "col1", "col2")], use.names = FALSE), c(3L, 6L, 22L) ) - expect_equivalent( - pc[[3L]][pc[[3L]][["text"]] == "3", c("line1", "col1", "col2")], + expect_identical( + unlist(pc[[3L]][pc[[3L]][["text"]] == "3", c("line1", "col1", "col2")], use.names = FALSE), c(4L, 10L, 10L) ) }) with_content_to_parse("function(){\nTRUE\n\t}", { - expect_equivalent( - pc[[1L]][1L, c("line1", "col1", "line2", "col2")], + expect_identical( + unlist(pc[[1L]][1L, c("line1", "col1", "line2", "col2")], use.names = FALSE), c(1L, 1L, 3L, 2L), info = "expression that spans several lines" ) diff --git a/tests/testthat/test-implicit_integer_linter.R b/tests/testthat/test-implicit_integer_linter.R index ce586281a..bab09465b 100644 --- a/tests/testthat/test-implicit_integer_linter.R +++ b/tests/testthat/test-implicit_integer_linter.R @@ -36,7 +36,7 @@ test_that("single numerical constants are properly identified ", { test_that("linter returns the correct linting", { msg <- "Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles." linter <- implicit_integer_linter() - expect_is(linter, "linter") + expect_s3_class(linter, "linter") expect_lint("x <<- 1L", NULL, linter) expect_lint("1.0/-Inf -> y", NULL, linter) diff --git a/tests/testthat/test-knitr_formats.R b/tests/testthat/test-knitr_formats.R index 7505e5f73..4ac069a24 100644 --- a/tests/testthat/test-knitr_formats.R +++ b/tests/testthat/test-knitr_formats.R @@ -12,9 +12,9 @@ test_that("it handles dir", { parse_settings = FALSE ) has_lints <- length(lints) > 0 - testthat::expect(has_lints, "There should be lints") + expect_true(has_lints, info="There should be lints") - testthat::expect_equivalent(length(unique(names(lints))), 6, info="For every file there should be at least 1 lint") + expect_identical(length(unique(names(lints))), 6L, info="For every file there should be at least 1 lint") }) test_that("it handles markdown", { diff --git a/tests/testthat/test-lint_file.R b/tests/testthat/test-lint_file.R index fc902b7cc..3b45e8620 100644 --- a/tests/testthat/test-lint_file.R +++ b/tests/testthat/test-lint_file.R @@ -186,7 +186,8 @@ test_that("compatibility warnings work", { "Use is.na", linters = list(unclass(equals_na_linter())) ), - fixed = "The use of linters of class 'function'" + "The use of linters of class 'function'", + fixed = TRUE ) expect_error( diff --git a/tests/testthat/test-methods.R b/tests/testthat/test-methods.R index d1132b7c8..fc929bfcf 100644 --- a/tests/testthat/test-methods.R +++ b/tests/testthat/test-methods.R @@ -21,7 +21,7 @@ test_that("it returns the input trimmed to the last full lint if one exists with test_that("as.data.frame.lints", { # A minimum lint - expect_is( + expect_s3_class( l1 <- Lint( "dummy.R", line_number = 1L, @@ -33,7 +33,7 @@ test_that("as.data.frame.lints", { ) # A larger lint - expect_is( + expect_s3_class( l2 <- Lint( "dummy.R", line_number = 2L, @@ -53,7 +53,7 @@ test_that("as.data.frame.lints", { # Convert lints to data.frame lints <- structure(list(l1, l2), class = "lints") - expect_is( + expect_s3_class( df <- as.data.frame.lints(lints), "data.frame" ) diff --git a/tests/testthat/test-object_name_linter.R b/tests/testthat/test-object_name_linter.R index ed41f4861..fdf05de94 100644 --- a/tests/testthat/test-object_name_linter.R +++ b/tests/testthat/test-object_name_linter.R @@ -1,39 +1,39 @@ test_that("styles are correctly identified", { styles <- names(style_regexes) do_style_check <- function(nms) lapply(styles, check_style, nms = nms) - # symbl UpC lowC snake SNAKE dot alllow ALLUP - expect_equivalent(do_style_check("x"), list(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE)) - expect_equivalent(do_style_check(".x"), list(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE)) - expect_equivalent(do_style_check("X"), list(FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE)) - expect_equivalent(do_style_check("x."), list(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) - expect_equivalent(do_style_check("X."), list(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) - expect_equivalent(do_style_check("x_"), list(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE)) - expect_equivalent(do_style_check("X_"), list(FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE)) - expect_equivalent(do_style_check("xy"), list(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE)) - expect_equivalent(do_style_check("xY"), list(FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE)) - expect_equivalent(do_style_check("Xy"), list(FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) - expect_equivalent(do_style_check("XY"), list(FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE)) - expect_equivalent(do_style_check("x1"), list(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE)) - expect_equivalent(do_style_check("X1"), list(FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE)) - expect_equivalent(do_style_check("x_y"), list(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE)) - expect_equivalent(do_style_check("X_Y"), list(FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE)) - expect_equivalent(do_style_check("X.Y"), list(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) - expect_equivalent(do_style_check("x_2"), list(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE)) - expect_equivalent(do_style_check("X_2"), list(FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE)) - expect_equivalent(do_style_check("x.2"), list(FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE)) - expect_equivalent(do_style_check("X.2"), list(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) - - # symbl UpC lowC snake SNAKE dot alllow ALLUP - expect_equivalent(do_style_check("IHave1Cat"), c(FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) - expect_equivalent(do_style_check("iHave1Cat"), c(FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE)) - expect_equivalent(do_style_check("i_have_1_cat"), c(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE)) - expect_equivalent(do_style_check("I_HAVE_1_CAT"), c(FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE)) - expect_equivalent(do_style_check("i.have.1.cat"), c(FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE)) - expect_equivalent(do_style_check("ihave1cat"), c(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE)) - expect_equivalent(do_style_check("IHAVE1CAT"), c(FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE)) - expect_equivalent(do_style_check("I.HAVE_ONECAT"), c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) - expect_equivalent(do_style_check("."), c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) - expect_equivalent(do_style_check("%^%"), c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) + # symbl UpC lowC snake SNAKE dot allow ALLUP + expect_identical(do_style_check("x"), list(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE)) + expect_identical(do_style_check(".x"), list(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE)) + expect_identical(do_style_check("X"), list(FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE)) + expect_identical(do_style_check("x."), list(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) + expect_identical(do_style_check("X."), list(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) + expect_identical(do_style_check("x_"), list(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE)) + expect_identical(do_style_check("X_"), list(FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE)) + expect_identical(do_style_check("xy"), list(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE)) + expect_identical(do_style_check("xY"), list(FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE)) + expect_identical(do_style_check("Xy"), list(FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) + expect_identical(do_style_check("XY"), list(FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE)) + expect_identical(do_style_check("x1"), list(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE)) + expect_identical(do_style_check("X1"), list(FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE)) + expect_identical(do_style_check("x_y"), list(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE)) + expect_identical(do_style_check("X_Y"), list(FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE)) + expect_identical(do_style_check("X.Y"), list(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) + expect_identical(do_style_check("x_2"), list(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE)) + expect_identical(do_style_check("X_2"), list(FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE)) + expect_identical(do_style_check("x.2"), list(FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE)) + expect_identical(do_style_check("X.2"), list(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) + + # symbl UpC lowC snake SNAKE dot alllow ALLUP + expect_identical(do_style_check("IHave1Cat"), list(FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) + expect_identical(do_style_check("iHave1Cat"), list(FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE)) + expect_identical(do_style_check("i_have_1_cat"), list(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE)) + expect_identical(do_style_check("I_HAVE_1_CAT"), list(FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE)) + expect_identical(do_style_check("i.have.1.cat"), list(FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE)) + expect_identical(do_style_check("ihave1cat"), list(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE)) + expect_identical(do_style_check("IHAVE1CAT"), list(FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE)) + expect_identical(do_style_check("I.HAVE_ONECAT"), list(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) + expect_identical(do_style_check("."), list(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) + expect_identical(do_style_check("%^%"), list(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) }) test_that("linter ignores some objects", { diff --git a/tests/testthat/test-rstudio_markers.R b/tests/testthat/test-rstudio_markers.R index 2270f419d..c75889d3f 100644 --- a/tests/testthat/test-rstudio_markers.R +++ b/tests/testthat/test-rstudio_markers.R @@ -1,4 +1,7 @@ test_that("it returns markers which match lints", { + mockery::stub(rstudio_source_markers, "rstudioapi::callFun", function(...) list(...)) + mockery::stub(rstudio_source_markers, "rstudioapi::executeCommand", function(...) NULL) + lint1 <- structure( list( Lint(filename = "test_file", @@ -10,11 +13,8 @@ test_that("it returns markers which match lints", { ), class = "lints" ) - with_mock( - `rstudioapi::callFun` = function(...) list(...), - `rstudioapi::executeCommand` = function(...) NULL, - marker1 <- rstudio_source_markers(lint1) - ) + + marker1 <- rstudio_source_markers(lint1) expect_equal(marker1$name, "lintr") expect_equal(marker1$markers[[1]]$type, lint1[[1]]$type) expect_equal(marker1$markers[[1]]$file, lint1[[1]]$filename) @@ -38,11 +38,7 @@ test_that("it returns markers which match lints", { ), class = "lints" ) - with_mock( - `rstudioapi::callFun` = function(...) list(...), - `rstudioapi::executeCommand` = function(...) NULL, - marker2 <- rstudio_source_markers(lint2) - ) + marker2 <- rstudio_source_markers(lint2) expect_equal(marker2$name, "lintr") expect_equal(marker2$markers[[1]]$type, lint2[[1]]$type) expect_equal(marker2$markers[[1]]$file, lint2[[1]]$filename) @@ -52,6 +48,9 @@ test_that("it returns markers which match lints", { }) test_that("it prepends the package path if it exists", { + mockery::stub(rstudio_source_markers, "rstudioapi::callFun", function(...) list(...)) + mockery::stub(rstudio_source_markers, "rstudioapi::executeCommand", function(...) NULL) + lint3 <- structure( list( Lint(filename = "test_file", @@ -64,11 +63,7 @@ test_that("it prepends the package path if it exists", { class = "lints", path = "test" ) - with_mock( - `rstudioapi::callFun` = function(...) list(...), - `rstudioapi::executeCommand` = function(...) NULL, - marker3 <- rstudio_source_markers(lint3) - ) + marker3 <- rstudio_source_markers(lint3) expect_equal(marker3$name, "lintr") expect_equal(marker3$basePath, "test") expect_equal(marker3$markers[[1]]$type, lint3[[1]]$type) @@ -79,40 +74,32 @@ test_that("it prepends the package path if it exists", { }) test_that("it returns an empty list of markers if there are no lints", { + mockery::stub(rstudio_source_markers, "rstudioapi::callFun", function(...) list(...)) + mockery::stub(rstudio_source_markers, "rstudioapi::executeCommand", function(...) NULL) + lint4 <- structure( list(), class = "lints" ) - with_mock( - `rstudioapi::callFun` = function(...) list(...), - `rstudioapi::executeCommand` = function(...) NULL, - marker4 <- rstudio_source_markers(lint4) - ) + marker4 <- rstudio_source_markers(lint4) expect_equal(marker4$name, "lintr") expect_equal(marker4$markers, list()) }) test_that("rstudio_source_markers apply to print within rstudio", { + withr::local_options(lintr.rstudio_source_markers = TRUE) + tmp <- withr::local_tempfile(lines = "1:ncol(x)") + empty <- withr::local_tempfile() + file.create(empty) + with_mock( `rstudioapi::hasFun` = function(x, ...) TRUE, `rstudioapi::callFun` = function(...) cat("matched\n"), { - writeLines("1:ncol(x)", tmp <- tempfile()) - on.exit(unlink(tmp)) - - old <- options(lintr.rstudio_source_markers = TRUE) - on.exit(options(old), add = TRUE) + l <- lint(tmp, seq_linter()) + expect_output(print(l), "matched", fixed = TRUE) - l <- lint(tmp, seq_linter()) + l <- lint(empty, seq_linter()) - expect_output(print(l), "matched", fixed = TRUE) - - empty <- tempfile() - file.create(empty) - on.exit(unlink(empty), add = TRUE) - - l <- lint(empty, seq_linter()) - - expect_output(print(l), "matched", fixed = TRUE) - } - ) + expect_output(print(l), "matched", fixed = TRUE) + }) }) From 2b71ca784b8bc9b9b92be45a8ae2bf2bb072cf74 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Wed, 9 Mar 2022 12:27:54 -0800 Subject: [PATCH 3/8] reference PR --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 98f7a500c..7662f3745 100644 --- a/NEWS.md +++ b/NEWS.md @@ -85,7 +85,7 @@ function calls. (#850, #851, @renkun-ken) * Each linter can have multiple tags * New function `available_linters()` to list available linters and their tags This feature is extensible by package authors providing add-on linters for {lintr}. -* `lintr` now uses the 3rd edition of `testthat` (@MichaelChirico) +* `lintr` now uses the 3rd edition of `testthat` (@MichaelChirico, #910) # lintr 2.0.1 From 24c5ff07aca370ecf1c76a22ec1ec5c560f8ca8d Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Wed, 9 Mar 2022 23:41:49 -0800 Subject: [PATCH 4/8] infix spacing --- tests/testthat/test-knitr_formats.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-knitr_formats.R b/tests/testthat/test-knitr_formats.R index 4ac069a24..4cbc51a41 100644 --- a/tests/testthat/test-knitr_formats.R +++ b/tests/testthat/test-knitr_formats.R @@ -12,9 +12,9 @@ test_that("it handles dir", { parse_settings = FALSE ) has_lints <- length(lints) > 0 - expect_true(has_lints, info="There should be lints") + expect_true(has_lints, info = "There should be lints") - expect_identical(length(unique(names(lints))), 6L, info="For every file there should be at least 1 lint") + expect_identical(length(unique(names(lints))), 6L, info = "For every file there should be at least 1 lint") }) test_that("it handles markdown", { From 0ec8ba4faaeb2b3449d6984a818d5d1399d2a766 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 10 Mar 2022 00:05:16 -0800 Subject: [PATCH 5/8] add & use a helper for comparing environments --- tests/testthat/helper.R | 31 +++++++++++++++++++++++++++++++ tests/testthat/test-cache.R | 23 ++++++++++++----------- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index c534e8fa3..3862f4acb 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -44,3 +44,34 @@ trim_some <- function(x, num = NULL) { rex::re_substitutes(x, rex::rex(start, n_times(any, num)), "", global = TRUE, options = "multi-line") } + +expect_environments_equal <- function(actual, expected) { + act <- quasi_label(rlang::enquo(actual), arg = "actual") + exp <- quasi_label(rlang::enquo(expected), arg = "expected") + + act$objs <- ls(act$val, all.names = TRUE) + exp$objs <- ls(exp$val, all.names = TRUE) + + act_not_exp <- setdiff(act$objs, exp$objs) + if (length(act_not_exp) > 6L) act_not_exp <- c(utils::head(act_not_exp, 6L), "...") + expect( + length(act_not_exp) == 0L, + sprintf("Objects found in %s but not %s: %s", act$lab, exp$lab, toString(act_not_exp)) + ) + + exp_not_act <- setdiff(act$objs, exp$objs) + if (length(exp_not_act) > 6L) exp_not_act <- c(utils::head(exp_not_act, 6L), "...") + expect( + length(exp_not_act) == 0L, + sprintf("Objects found in %s but not %s: %s", exp$lab, act$lab, toString(exp_not_act)) + ) + + for (obj in intersect(act$objs, exp$objs)) + expect_identical( + act$val[[obj]], exp$val[[obj]], + label = sprintf("%s$%s", act$lab, obj), + expected.label = sprintf("%s$%s", exp$lab, obj) + ) + + invisible(act$val) +} diff --git a/tests/testthat/test-cache.R b/tests/testthat/test-cache.R index b6d00cf8f..00dcccf67 100644 --- a/tests/testthat/test-cache.R +++ b/tests/testthat/test-cache.R @@ -54,14 +54,13 @@ test_that("clear_cache deletes the directory if no file is given", { test_that("load_cache loads the saved file in a new empty environment", { e1 <- new.env(parent = emptyenv()) - assign("x", "foobar", envir = e1) + e1[["x"]] <- "foobar" d1 <- tempfile(pattern = "lintr_cache_") f1 <- "R/test.R" save_cache(cache = e1, file = f1, path = d1) e2 <- load_cache(file = f1, path = d1) - expect_equal(ls(e2), "x") - expect_equal(e2[["x"]], "foobar") + expect_environments_equal(e2, e1) }) test_that("load_cache returns an empty environment if no cache file exists", { @@ -73,20 +72,22 @@ test_that("load_cache returns an empty environment if no cache file exists", { save_cache(cache = e1, file = f1, path = d1) e2 <- load_cache(file = f2, path = d1) - expect_equal(ls(e2), character(0)) + expect_environments_equal(e2, e1) }) test_that("load_cache returns an empty environment if reading cache file fails", { e1 <- new.env(parent = emptyenv()) - assign("x", "foobar", envir = e1) + e1[["x"]] <- "foobar" d1 <- tempfile(pattern = "lintr_cache_") f1 <- "R/test.R" save_cache(cache = e1, file = f1, path = d1) cache_f1 <- file.path(d1, fhash(f1)) writeLines(character(), cache_f1) + expect_warning(e2 <- load_cache(file = f1, path = d1)) saveRDS(e1, cache_f1) expect_warning(e3 <- load_cache(file = f1, path = d1)) + expect_equal(ls(e2), character(0)) expect_equal(ls(e3), character(0)) }) @@ -138,7 +139,7 @@ test_that("save_cache saves all non-hidden objects from the environment", { e2 <- new.env(parent = emptyenv()) load(file = file.path(d1, fhash(f1)), envir = e2) - expect_identical(as.list(e1), as.list(e2)) + expect_environments_equal(e1, e2) }) # `cache_file` @@ -153,7 +154,7 @@ test_that("cache_file generates the same cache with different lints", { cache_file(e1, f1, list(), list()) cache_file(e1, f1, list(), list(1)) - expect_equal(length(ls(e1)), 1) + expect_length(ls(e1), 1L) }) test_that("cache_file generates different caches for different linters", { @@ -166,7 +167,7 @@ test_that("cache_file generates different caches for different linters", { cache_file(e1, f1, list(), list()) cache_file(e1, f1, list(1), list()) - expect_equal(length(ls(e1)), 2) + expect_length(ls(e1), 2L) }) # `retrieve_file` @@ -201,7 +202,7 @@ test_that("cache_lint generates the same cache with different lints", { cache_lint(e1, t1, list(), list()) cache_lint(e1, t1, list(), list(1)) - expect_equal(length(ls(e1)), 1) + expect_length(ls(e1), 1L) }) test_that("cache_lint generates different caches for different linters", { @@ -212,7 +213,7 @@ test_that("cache_lint generates different caches for different linters", { cache_lint(e1, t1, list(), list()) cache_lint(e1, t1, list(1), list()) - expect_equal(length(ls(e1)), 2) + expect_length(ls(e1), 2L) }) # `retrieve_lint` @@ -416,7 +417,7 @@ test_that("it works outside of a package", { expect_false(dir.exists(path)) expect_lint("a <- 1", NULL, linter, cache = path) expect_true(dir.exists(path)) - expect_length(list.files(path), 1) + expect_length(list.files(path), 1L) expect_lint("a <- 1", NULL, linter, cache = path) expect_true(dir.exists(path)) }) From a54770c80a0f3b5217206d7750cc14fe7d80ec54 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 10 Mar 2022 00:27:51 -0800 Subject: [PATCH 6/8] add rlang Suggested --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index e6c86e948..6fd181410 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,6 +32,7 @@ Suggests: covr, httr (>= 1.2.1), mockery, + rlang, rmarkdown, rstudioapi (>= 0.2), testthat (>= 3.0.0), From 21d64a89f9ddcce1f9b61f94465c88b6788ac18b Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Fri, 11 Mar 2022 02:30:33 -0800 Subject: [PATCH 7/8] revert custom helper --- tests/testthat/helper.R | 31 ------------------------------- tests/testthat/test-cache.R | 9 ++++++--- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 3862f4acb..c534e8fa3 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -44,34 +44,3 @@ trim_some <- function(x, num = NULL) { rex::re_substitutes(x, rex::rex(start, n_times(any, num)), "", global = TRUE, options = "multi-line") } - -expect_environments_equal <- function(actual, expected) { - act <- quasi_label(rlang::enquo(actual), arg = "actual") - exp <- quasi_label(rlang::enquo(expected), arg = "expected") - - act$objs <- ls(act$val, all.names = TRUE) - exp$objs <- ls(exp$val, all.names = TRUE) - - act_not_exp <- setdiff(act$objs, exp$objs) - if (length(act_not_exp) > 6L) act_not_exp <- c(utils::head(act_not_exp, 6L), "...") - expect( - length(act_not_exp) == 0L, - sprintf("Objects found in %s but not %s: %s", act$lab, exp$lab, toString(act_not_exp)) - ) - - exp_not_act <- setdiff(act$objs, exp$objs) - if (length(exp_not_act) > 6L) exp_not_act <- c(utils::head(exp_not_act, 6L), "...") - expect( - length(exp_not_act) == 0L, - sprintf("Objects found in %s but not %s: %s", exp$lab, act$lab, toString(exp_not_act)) - ) - - for (obj in intersect(act$objs, exp$objs)) - expect_identical( - act$val[[obj]], exp$val[[obj]], - label = sprintf("%s$%s", act$lab, obj), - expected.label = sprintf("%s$%s", exp$lab, obj) - ) - - invisible(act$val) -} diff --git a/tests/testthat/test-cache.R b/tests/testthat/test-cache.R index 00dcccf67..ef1620d34 100644 --- a/tests/testthat/test-cache.R +++ b/tests/testthat/test-cache.R @@ -60,7 +60,8 @@ test_that("load_cache loads the saved file in a new empty environment", { save_cache(cache = e1, file = f1, path = d1) e2 <- load_cache(file = f1, path = d1) - expect_environments_equal(e2, e1) + # TODO(michaelchirico): use plain expect_equal after waldo#133 makes it into a CRAN release + expect_equal(as.list(e2, all.names = TRUE), as.list(e1, all.names = TRUE)) }) test_that("load_cache returns an empty environment if no cache file exists", { @@ -72,7 +73,8 @@ test_that("load_cache returns an empty environment if no cache file exists", { save_cache(cache = e1, file = f1, path = d1) e2 <- load_cache(file = f2, path = d1) - expect_environments_equal(e2, e1) + # TODO(michaelchirico): use plain expect_equal after waldo#133 makes it into a CRAN release + expect_equal(as.list(e2, all.names = TRUE), as.list(e1, all.names = TRUE)) }) test_that("load_cache returns an empty environment if reading cache file fails", { @@ -139,7 +141,8 @@ test_that("save_cache saves all non-hidden objects from the environment", { e2 <- new.env(parent = emptyenv()) load(file = file.path(d1, fhash(f1)), envir = e2) - expect_environments_equal(e1, e2) + # TODO(michaelchirico): use plain expect_equal after waldo#133 makes it into a CRAN release + expect_equal(as.list(e1, all.names = TRUE), as.list(e2, all.names = TRUE)) }) # `cache_file` From c8e149078031d40ecb3bc8916acdf7a342174a22 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Fri, 11 Mar 2022 02:31:11 -0800 Subject: [PATCH 8/8] remove rlang too --- DESCRIPTION | 1 - 1 file changed, 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6fd181410..e6c86e948 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,7 +32,6 @@ Suggests: covr, httr (>= 1.2.1), mockery, - rlang, rmarkdown, rstudioapi (>= 0.2), testthat (>= 3.0.0),