Skip to content

Commit

Permalink
Merge branch 'main' into missing_tests_1
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil authored Oct 6, 2022
2 parents a7a7fc8 + dba72ab commit 1788011
Show file tree
Hide file tree
Showing 37 changed files with 209 additions and 205 deletions.
4 changes: 4 additions & 0 deletions R/linter_tags.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ available_tags <- function(packages = "lintr") {
platform_independent_sort(unique(unlist(available_linters(packages = packages, exclude_tags = NULL)[["tags"]])))
}

# nocov start

#' Generate Rd fragment for the Tags section of a linter
#'
#' @param linter_name Name of the linter to generate Rd code for.
Expand Down Expand Up @@ -211,3 +213,5 @@ rd_linterlist <- function() {
"}" # section
)
}

# nocov end
90 changes: 45 additions & 45 deletions tests/testthat/test-cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test_that("clear_cache deletes the file if a file is given", {
e1 <- new.env(parent = emptyenv())
d1 <- tempfile(pattern = "lintr_cache_")
f1 <- "R/test.R"
save_cache(cache = e1, file = f1, path = d1)
lintr:::save_cache(cache = e1, file = f1, path = d1)

want <- list(file.path(d1, fhash("R/test.R")), recursive = TRUE)
expect_equal(clear_cache(f1, d1), want)
Expand All @@ -57,8 +57,8 @@ test_that("load_cache loads the saved file in a new empty environment", {
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)
lintr:::save_cache(cache = e1, file = f1, path = d1)
e2 <- lintr:::load_cache(file = f1, path = d1)

expect_equal(e2, e1)
})
Expand All @@ -69,8 +69,8 @@ test_that("load_cache returns an empty environment if no cache file exists", {
f1 <- "R/test.R"
f2 <- "test.R"

save_cache(cache = e1, file = f1, path = d1)
e2 <- load_cache(file = f2, path = d1)
lintr:::save_cache(cache = e1, file = f1, path = d1)
e2 <- lintr:::load_cache(file = f2, path = d1)

expect_equal(e2, e1)
})
Expand All @@ -80,13 +80,13 @@ test_that("load_cache returns an empty environment if reading cache file fails",
e1[["x"]] <- "foobar"
d1 <- tempfile(pattern = "lintr_cache_")
f1 <- "R/test.R"
save_cache(cache = e1, file = f1, path = d1)
lintr:::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), "Could not load cache file")
expect_warning(e2 <- lintr:::load_cache(file = f1, path = d1), "Could not load cache file")
saveRDS(e1, cache_f1)
expect_warning(e3 <- load_cache(file = f1, path = d1), "Could not load cache file")
expect_warning(e3 <- lintr:::load_cache(file = f1, path = d1), "Could not load cache file")

expect_equal(ls(e2), character())
expect_equal(ls(e3), character())
Expand All @@ -102,7 +102,7 @@ test_that("save_cache creates a directory if needed", {
expect_false(file.exists(d1))
expect_false(file.exists(file.path(d1, fhash(f1))))

save_cache(cache = e1, file = f1, path = d1)
lintr:::save_cache(cache = e1, file = f1, path = d1)

expect_true(file.exists(d1))
expect_true(file.info(d1)$isdir)
Expand All @@ -118,8 +118,8 @@ test_that("save_cache uses unambiguous cache file names", {
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)
lintr:::save_cache(cache = e1, file = f1, path = d1)
lintr:::save_cache(cache = e1, file = f2, path = d1)

expect_true(fhash(f1) != fhash(f2))
expect_true(file.exists(file.path(d1, fhash(f1))))
Expand All @@ -134,7 +134,7 @@ test_that("save_cache saves all non-hidden objects from the environment", {
d1 <- tempfile(pattern = "lintr_cache_")
f1 <- "R/test.R"

save_cache(cache = e1, file = f1, path = d1)
lintr:::save_cache(cache = e1, file = f1, path = d1)

e2 <- new.env(parent = emptyenv())
load(file = file.path(d1, fhash(f1)), envir = e2)
Expand All @@ -151,8 +151,8 @@ test_that("cache_file generates the same cache with different lints", {
writeLines("foobar", f1)
on.exit(unlink(f1))

cache_file(e1, f1, list(), list())
cache_file(e1, f1, list(), list(1L))
lintr:::cache_file(e1, f1, list(), list())
lintr:::cache_file(e1, f1, list(), list(1L))

expect_length(ls(e1), 1L)
})
Expand All @@ -164,8 +164,8 @@ test_that("cache_file generates different caches for different linters", {
writeLines("foobar", f1)
on.exit(unlink(f1))

cache_file(e1, f1, list(), list())
cache_file(e1, f1, list(1L), list())
lintr:::cache_file(e1, f1, list(), list())
lintr:::cache_file(e1, f1, list(1L), list())

expect_length(ls(e1), 2L)
})
Expand All @@ -179,7 +179,7 @@ test_that("retrieve_file returns NULL if there is no cached result", {
writeLines("foobar", f1)
on.exit(unlink(f1))

expect_null(retrieve_file(e1, f1, list()))
expect_null(lintr:::retrieve_file(e1, f1, list()))
})

test_that("retrieve_file returns the cached result if found", {
Expand All @@ -189,8 +189,8 @@ test_that("retrieve_file returns the cached result if found", {
writeLines("foobar", f1)
on.exit(unlink(f1))

cache_file(e1, f1, list(), list("foobar"))
expect_equal(retrieve_file(e1, f1, list()), list("foobar"))
lintr:::cache_file(e1, f1, list(), list("foobar"))
expect_equal(lintr:::retrieve_file(e1, f1, list()), list("foobar"))
})

# `cache_lint`
Expand All @@ -199,8 +199,8 @@ test_that("cache_lint generates the same cache with different lints", {
e1 <- new.env(parent = emptyenv())

t1 <- list(content = "test")
cache_lint(e1, t1, list(), list())
cache_lint(e1, t1, list(), list(1L))
lintr:::cache_lint(e1, t1, list(), list())
lintr:::cache_lint(e1, t1, list(), list(1L))

expect_length(ls(e1), 1L)
})
Expand All @@ -210,8 +210,8 @@ test_that("cache_lint generates different caches for different linters", {

t1 <- list(content = "test")

cache_lint(e1, t1, list(), list())
cache_lint(e1, t1, list(1L), list())
lintr:::cache_lint(e1, t1, list(), list())
lintr:::cache_lint(e1, t1, list(1L), list())

expect_length(ls(e1), 2L)
})
Expand All @@ -223,14 +223,14 @@ test_that("retrieve_lint returns the same lints if nothing has changed", {

e1 <- new.env(parent = emptyenv())

cache_lint(
lintr:::cache_lint(
cache = e1,
expr = test_data[["expr"]],
linter = test_data[["linters"]],
lints = test_data[["lints"]]
)

t1 <- retrieve_lint(
t1 <- lintr:::retrieve_lint(
cache = e1,
expr = test_data[["expr"]],
linter = test_data[["linters"]],
Expand All @@ -251,14 +251,14 @@ test_that(
lines2 <- c("", lines1)
lints <- test_data[["lints"]]

cache_lint(
lintr:::cache_lint(
cache = e1,
expr = test_data[["expr"]],
linter = test_data[["linters"]],
lints = lints
)

t1 <- retrieve_lint(
t1 <- lintr:::retrieve_lint(
cache = e1,
expr = test_data[["expr"]],
linter = test_data[["linters"]],
Expand All @@ -279,14 +279,14 @@ test_that("retrieve_lint returns the same lints with lines added below", {
lines1 <- test_data[["lines"]]
lines2 <- c(lines1, "")

cache_lint(
lintr:::cache_lint(
cache = e1,
expr = test_data[["expr"]],
linter = test_data[["linters"]],
lints = test_data[["lints"]]
)

t1 <- retrieve_lint(
t1 <- lintr:::retrieve_lint(
cache = e1,
expr = test_data[["expr"]],
linter = test_data[["linters"]],
Expand All @@ -308,14 +308,14 @@ test_that(

lints1 <- test_data[["lints"]]

cache_lint(
lintr:::cache_lint(
cache = e1,
expr = test_data[["expr"]],
linter = test_data[["linters"]],
lints = lints1
)

t1 <- retrieve_lint(
t1 <- lintr:::retrieve_lint(
cache = e1,
expr = test_data[["expr"]],
linter = test_data[["linters"]],
Expand All @@ -334,15 +334,15 @@ test_that("has_lint returns FALSE if there is no cached result", {
e1 <- new.env(parent = emptyenv())

t1 <- list(content = "foobar")
expect_false(has_lint(e1, t1, list()))
expect_false(lintr:::has_lint(e1, t1, list()))
})

test_that("has_lint returns TRUE if there is a cached result", {
e1 <- new.env(parent = emptyenv())

t1 <- list(content = "foobar")
cache_lint(e1, t1, list(), list())
expect_true(has_lint(e1, t1, list()))
lintr:::cache_lint(e1, t1, list(), list())
expect_true(lintr:::has_lint(e1, t1, list()))
})

test_that("has_lint distinguishes global expressions from line expression with same content", {
Expand All @@ -351,10 +351,10 @@ test_that("has_lint distinguishes global expressions from line expression with s
same_content <- "foobar"

line_expr <- list(content = same_content, parsed_content = data.frame())
cache_lint(e1, line_expr, list(), list())
lintr:::cache_lint(e1, line_expr, list(), list())

global_expr <- list(content = same_content, file_lines = character())
expect_false(has_lint(e1, global_expr, list()))
expect_false(lintr:::has_lint(e1, global_expr, list()))
})

# `find_new_line`
Expand All @@ -365,11 +365,11 @@ test_that("find_new_line returns the same if the line is the same", {
"foobar2",
"foobar3"
)
expect_equal(find_new_line(1L, "foobar1", t1), 1L)
expect_equal(lintr:::find_new_line(1L, "foobar1", t1), 1L)

expect_equal(find_new_line(2L, "foobar2", t1), 2L)
expect_equal(lintr:::find_new_line(2L, "foobar2", t1), 2L)

expect_equal(find_new_line(3L, "foobar3", t1), 3L)
expect_equal(lintr:::find_new_line(3L, "foobar3", t1), 3L)
})

test_that("find_new_line returns the correct line if it is before the current line", {
Expand All @@ -378,11 +378,11 @@ test_that("find_new_line returns the correct line if it is before the current li
"foobar2",
"foobar3"
)
expect_equal(find_new_line(1L, "foobar1", t1), 1L)
expect_equal(lintr:::find_new_line(1L, "foobar1", t1), 1L)

expect_equal(find_new_line(2L, "foobar1", t1), 1L)
expect_equal(lintr:::find_new_line(2L, "foobar1", t1), 1L)

expect_equal(find_new_line(3L, "foobar1", t1), 1L)
expect_equal(lintr:::find_new_line(3L, "foobar1", t1), 1L)
})

test_that("find_new_line returns the correct line if it is after the current line", {
Expand All @@ -391,11 +391,11 @@ test_that("find_new_line returns the correct line if it is after the current lin
"foobar2",
"foobar3"
)
expect_equal(find_new_line(1L, "foobar3", t1), 3L)
expect_equal(lintr:::find_new_line(1L, "foobar3", t1), 3L)

expect_equal(find_new_line(2L, "foobar3", t1), 3L)
expect_equal(lintr:::find_new_line(2L, "foobar3", t1), 3L)

expect_equal(find_new_line(3L, "foobar3", t1), 3L)
expect_equal(lintr:::find_new_line(3L, "foobar3", t1), 3L)
})

#
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test_that("GitHub Actions functionality works in a subdirectory", {
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)
lintr:::read_settings(NULL)
l <- lint_package(
pkg_path,
linters = list(assignment_linter()),
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-closed_curly_linter.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_that("returns the correct linting", {
closed_curly_message_regex <- rex(
closed_curly_message_regex <- rex::rex(
paste(
"Closing curly-braces should always be on their own line,",
"unless they are followed by an else."
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-commas_linter.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test_that("returns the correct linting", {
linter <- commas_linter()
msg_after <- rex("Commas should always have a space after.")
msg_before <- rex("Commas should never have a space before.")
msg_after <- rex::rex("Commas should always have a space after.")
msg_before <- rex::rex("Commas should never have a space before.")

expect_lint("blah", NULL, linter)
expect_lint("fun(1, 1)", NULL, linter)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-commented_code_linter.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_that("returns the correct linting", {
msg <- rex("Commented code should be removed.")
msg <- rex::rex("Commented code should be removed.")
linter <- commented_code_linter()
expect_s3_class(linter, "linter")

Expand Down Expand Up @@ -76,7 +76,7 @@ test_that("returns the correct linting", {
linter
)

test_ops <- append(ops[ops != "%[^%]*%"], values = c("%>%", "%anything%"))
test_ops <- append(lintr:::ops[lintr:::ops != "%[^%]*%"], values = c("%>%", "%anything%"))
for (op in test_ops) {
expect_lint(paste("i", op, "1", collapse = ""), NULL, linter)
expect_lint(paste("# something like i", op, "1", collapse = ""), NULL, linter)
Expand Down
16 changes: 8 additions & 8 deletions tests/testthat/test-comments.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ clear_ci_info <- function() {
test_that("it detects CI environments", {
clear_ci_info()
Sys.setenv(TRAVIS_REPO_SLUG = "foo/bar")
expect_true(in_ci())
expect_true(lintr:::in_ci())
Sys.setenv(TRAVIS_REPO_SLUG = "")
expect_false(in_ci())
expect_false(lintr:::in_ci())
})

test_that("it returns NULL if GIT_URL is not on github", {
Expand All @@ -26,7 +26,7 @@ test_that("it returns NULL if GIT_URL is not on github", {
GIT_URL = "https://example.com/user/repo.git",
CHANGE_ID = "123"
)
expect_false(in_ci())
expect_false(lintr:::in_ci())
})


Expand All @@ -42,17 +42,17 @@ test_that("it determines Jenkins PR build info", {
GIT_URL = "https://github.com/user/repo.git",
CHANGE_ID = "123"
)
expect_true(in_ci())
expect_true(lintr:::in_ci())

expect_equal(ci_build_info(), list(
expect_equal(lintr:::ci_build_info(), list(
user = "user",
repo = "repo",
pull = "123",
commit = NULL
))

Sys.unsetenv(c("JENKINS_URL", "GIT_URL", "CHANGE_ID"))
expect_false(in_ci())
expect_false(lintr:::in_ci())
})

test_that("it determines Jenkins commit build info", {
Expand All @@ -63,8 +63,8 @@ test_that("it determines Jenkins commit build info", {
GIT_COMMIT = "abcde"
)

expect_true(in_ci())
expect_equal(ci_build_info(), list(
expect_true(lintr:::in_ci())
expect_equal(lintr:::ci_build_info(), list(
user = "user",
repo = "repo",
pull = NULL,
Expand Down
Loading

0 comments on commit 1788011

Please sign in to comment.