Skip to content

Commit

Permalink
Enable tests (#669)
Browse files Browse the repository at this point in the history
* remove line in .lintr

* lint files in tests/

* remove duplication
  • Loading branch information
MichaelChirico authored Dec 6, 2020
1 parent 3ec404d commit 20d37fa
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ linters: with_defaults( # The following TODOs are part of an effort to have {lin
exclusions: list(
"inst/doc/creating_linters.R" = 1,
"inst/example/bad.R",
"tests", # TODO remove this
"tests/testthat/default_linter_testcode.R",
"tests/testthat/dummy_packages",
"tests/testthat/exclusions-test",
"tests/testthat/knitr_formats",
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-T_and_F_symbol_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ test_that("returns the correct linting", {
),
linter)
})

2 changes: 1 addition & 1 deletion tests/testthat/test-absolute_path_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ test_that("returns the correct linting", {
"./blah",
encodeString("blah\\file.txt")
)
for(path in non_absolute_path_strings) {
for (path in non_absolute_path_strings) {
expect_lint(single_quote(path), NULL, linter)
expect_lint(double_quote(path), NULL, linter)
}
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-closed_curly_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ test_that("returns the correct linting", {
rex("Closing curly-braces should always be on their own line, unless it's followed by an else.")
),
closed_curly_linter())

expect_lint("eval(bquote({...}))",
NULL,
closed_curly_linter())

expect_lint("fun({\n statements\n}, param)",
NULL,
closed_curly_linter())

expect_lint("out <- lapply(stuff, function(i) {\n do_something(i)\n}) %>% unlist",
NULL,
closed_curly_linter())

expect_lint('{{x}}', NULL, closed_curly_linter())
expect_lint("{{x}}", NULL, closed_curly_linter())
})
2 changes: 1 addition & 1 deletion tests/testthat/test-defaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test_that("undesirable functions and operators", {
expect_is(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))))
expect_true(all(vapply(x, function(x) is.na(x) || is.character(x), logical(1L))))
expect_true(all(vapply(x, length, integer(1L)) == 1L))
}
})
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-extraction_operator_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,3 @@ test_that("linter returns the correct linting", {
),
linter)
})


8 changes: 3 additions & 5 deletions tests/testthat/test-get_source_expressions.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
context("get_source_expression")


with_content_to_parse <- function(content, code) {
f <- tempfile()
on.exit(unlink(f))
writeLines(content, f)
pc <- lapply(get_source_expressions(f)[["expressions"]], `[[`, "parsed_content")
eval(substitute(code))
content_env <- new.env()
content_env$pc <- lapply(get_source_expressions(f)[["expressions"]], `[[`, "parsed_content")
eval(substitute(code), envir = content_env)
}


Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-lint_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ test_that("lint() results do not depend on the position of the .lintr", {
)
)

lints_with_config_in_source_dir <- withr::with_dir(
lints_with_config_in_r_dir <- withr::with_dir(
pkg_path,
lint_with_config(
config_path = "R/.lintr",
Expand All @@ -102,7 +102,7 @@ test_that("lint() results do not depend on the position of the .lintr", {
)
expect_equal(
as.data.frame(lints_with_config_at_pkg_root),
as.data.frame(lints_with_config_in_source_dir),
as.data.frame(lints_with_config_in_r_dir),
info = paste(
"lints for a source file should be independent of whether the .lintr",
"file is in the project-root or the source-file-directory"
Expand Down
8 changes: 3 additions & 5 deletions tests/testthat/test-lint_package.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
context("Integration tests for `lint_package`")

# When called from inside a package:
# lint_package(".")
# lint_package(".") # nolint
# .. should give the same results as when called from outside the package
# with:
# lint_package(path_to_package)
# lint_package(path_to_package) # nolint

# Template packages for use in testing are stored in
# `tests/testthat/dummy_packages/<pkgName>`
# tests/testthat/dummy_packages/<pkgName>
# These packages should not have a .lintr file: Hardcoding a .lintr in a
# dummy package throws problems during `R CMD check` (they are flagged as
# hidden files, but can't be added to RBuildIgnore since they should be
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-open_curly_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ test_that("returns the correct linting", {
open_curly_linter()
)

expect_lint('{{x}}', NULL, open_curly_linter())
expect_lint("{{x}}", NULL, open_curly_linter())
})
2 changes: 1 addition & 1 deletion tests/testthat/test-seq_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test_that("finds 1:length(...) expressions", {
expect_lint("function(x) { 1:dim(x)[1L] }",
rex("dim(...)", anything, "use seq_len"),
seq_linter)

expect_lint("function(x) { 1L:dim(x)[[1]] }",
rex("dim(...)", anything, "use seq_len"),
seq_linter)
Expand Down
4 changes: 1 addition & 3 deletions tests/testthat/test-spaces_inside_linter.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("spaces_inside_linter")

test_that("returns the correct linting", {
msg <- rex::rex("Do not place spaces around code in parentheses or square brackets.")

Expand Down Expand Up @@ -55,7 +53,7 @@ test_that("returns the correct linting", {

# trailing comments are OK (#636)
expect_lint("or( #code\n x, y\n)", NULL, spaces_inside_linter)

expect_lint(trim_some("
fun( # this is another comment
a = 42, # because 42 is always the answer
Expand Down
3 changes: 0 additions & 3 deletions tests/testthat/test-unneeded_concatenation_linter.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("unneeded_concatenation_linter")

test_that("returns the correct linting", {
linter <- unneeded_concatenation_linter
msg_c <- rex::escape("Unneeded concatenation of a constant. Remove the \"c\" call.")
Expand All @@ -23,4 +21,3 @@ test_that("returns the correct linting", {
),
linter)
})

0 comments on commit 20d37fa

Please sign in to comment.