Skip to content

Commit 20d37fa

Browse files
Enable tests (#669)
* remove line in .lintr * lint files in tests/ * remove duplication
1 parent 3ec404d commit 20d37fa

13 files changed

+18
-30
lines changed

.lintr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ linters: with_defaults( # The following TODOs are part of an effort to have {lin
88
exclusions: list(
99
"inst/doc/creating_linters.R" = 1,
1010
"inst/example/bad.R",
11-
"tests", # TODO remove this
11+
"tests/testthat/default_linter_testcode.R",
1212
"tests/testthat/dummy_packages",
1313
"tests/testthat/exclusions-test",
1414
"tests/testthat/knitr_formats",

tests/testthat/test-T_and_F_symbol_linter.R

-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ test_that("returns the correct linting", {
1616
),
1717
linter)
1818
})
19-

tests/testthat/test-absolute_path_linter.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ test_that("returns the correct linting", {
166166
"./blah",
167167
encodeString("blah\\file.txt")
168168
)
169-
for(path in non_absolute_path_strings) {
169+
for (path in non_absolute_path_strings) {
170170
expect_lint(single_quote(path), NULL, linter)
171171
expect_lint(double_quote(path), NULL, linter)
172172
}

tests/testthat/test-closed_curly_linter.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ test_that("returns the correct linting", {
3535
rex("Closing curly-braces should always be on their own line, unless it's followed by an else.")
3636
),
3737
closed_curly_linter())
38-
38+
3939
expect_lint("eval(bquote({...}))",
4040
NULL,
4141
closed_curly_linter())
42-
42+
4343
expect_lint("fun({\n statements\n}, param)",
4444
NULL,
4545
closed_curly_linter())
46-
46+
4747
expect_lint("out <- lapply(stuff, function(i) {\n do_something(i)\n}) %>% unlist",
4848
NULL,
4949
closed_curly_linter())
5050

51-
expect_lint('{{x}}', NULL, closed_curly_linter())
51+
expect_lint("{{x}}", NULL, closed_curly_linter())
5252
})

tests/testthat/test-defaults.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test_that("undesirable functions and operators", {
1818
expect_is(x, "list")
1919
expect_gt(length(x), 0L)
2020
expect_true(all(names(x) != ""))
21-
expect_true(all(vapply(x, function(x) {is.na(x) || is.character(x)}, logical(1L))))
21+
expect_true(all(vapply(x, function(x) is.na(x) || is.character(x), logical(1L))))
2222
expect_true(all(vapply(x, length, integer(1L)) == 1L))
2323
}
2424
})

tests/testthat/test-extraction_operator_linter.R

-2
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,3 @@ test_that("linter returns the correct linting", {
2121
),
2222
linter)
2323
})
24-
25-

tests/testthat/test-get_source_expressions.R

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
context("get_source_expression")
2-
3-
41
with_content_to_parse <- function(content, code) {
52
f <- tempfile()
63
on.exit(unlink(f))
74
writeLines(content, f)
8-
pc <- lapply(get_source_expressions(f)[["expressions"]], `[[`, "parsed_content")
9-
eval(substitute(code))
5+
content_env <- new.env()
6+
content_env$pc <- lapply(get_source_expressions(f)[["expressions"]], `[[`, "parsed_content")
7+
eval(substitute(code), envir = content_env)
108
}
119

1210

tests/testthat/test-lint_file.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ test_that("lint() results do not depend on the position of the .lintr", {
8888
)
8989
)
9090

91-
lints_with_config_in_source_dir <- withr::with_dir(
91+
lints_with_config_in_r_dir <- withr::with_dir(
9292
pkg_path,
9393
lint_with_config(
9494
config_path = "R/.lintr",
@@ -102,7 +102,7 @@ test_that("lint() results do not depend on the position of the .lintr", {
102102
)
103103
expect_equal(
104104
as.data.frame(lints_with_config_at_pkg_root),
105-
as.data.frame(lints_with_config_in_source_dir),
105+
as.data.frame(lints_with_config_in_r_dir),
106106
info = paste(
107107
"lints for a source file should be independent of whether the .lintr",
108108
"file is in the project-root or the source-file-directory"

tests/testthat/test-lint_package.R

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
context("Integration tests for `lint_package`")
2-
31
# When called from inside a package:
4-
# lint_package(".")
2+
# lint_package(".") # nolint
53
# .. should give the same results as when called from outside the package
64
# with:
7-
# lint_package(path_to_package)
5+
# lint_package(path_to_package) # nolint
86

97
# Template packages for use in testing are stored in
10-
# `tests/testthat/dummy_packages/<pkgName>`
8+
# tests/testthat/dummy_packages/<pkgName>
119
# These packages should not have a .lintr file: Hardcoding a .lintr in a
1210
# dummy package throws problems during `R CMD check` (they are flagged as
1311
# hidden files, but can't be added to RBuildIgnore since they should be

tests/testthat/test-open_curly_linter.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ test_that("returns the correct linting", {
4747
open_curly_linter()
4848
)
4949

50-
expect_lint('{{x}}', NULL, open_curly_linter())
50+
expect_lint("{{x}}", NULL, open_curly_linter())
5151
})

tests/testthat/test-seq_linter.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test_that("finds 1:length(...) expressions", {
3030
expect_lint("function(x) { 1:dim(x)[1L] }",
3131
rex("dim(...)", anything, "use seq_len"),
3232
seq_linter)
33-
33+
3434
expect_lint("function(x) { 1L:dim(x)[[1]] }",
3535
rex("dim(...)", anything, "use seq_len"),
3636
seq_linter)

tests/testthat/test-spaces_inside_linter.R

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("spaces_inside_linter")
2-
31
test_that("returns the correct linting", {
42
msg <- rex::rex("Do not place spaces around code in parentheses or square brackets.")
53

@@ -55,7 +53,7 @@ test_that("returns the correct linting", {
5553

5654
# trailing comments are OK (#636)
5755
expect_lint("or( #code\n x, y\n)", NULL, spaces_inside_linter)
58-
56+
5957
expect_lint(trim_some("
6058
fun( # this is another comment
6159
a = 42, # because 42 is always the answer

tests/testthat/test-unneeded_concatenation_linter.R

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("unneeded_concatenation_linter")
2-
31
test_that("returns the correct linting", {
42
linter <- unneeded_concatenation_linter
53
msg_c <- rex::escape("Unneeded concatenation of a constant. Remove the \"c\" call.")
@@ -23,4 +21,3 @@ test_that("returns the correct linting", {
2321
),
2422
linter)
2523
})
26-

0 commit comments

Comments
 (0)