Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate out tests for allowed assignments with braces #1872

Merged
merged 7 commits into from
Dec 29, 2022
82 changes: 67 additions & 15 deletions tests/testthat/test-implicit_assignment_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,67 @@ test_that("implicit_assignment_linter respects except argument", {
)
})

test_that("implicit_assignment_linter makes exceptions for functions that capture side-effects", {
linter <- implicit_assignment_linter()
test_that("implicit_assignment_linter skips allowed usages with braces", {
linter <- implicit_assignment_linter(except = character(0L))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that no exceptions are included here.


# base
expect_lint("output <- capture.output(x <- f())", NULL, linter)
expect_lint("quote(a <- 1L)", NULL, linter)
expect_lint("bquote(a <- 1L)", NULL, linter)
expect_lint("expression(a <- 1L)", NULL, linter)
expect_lint("local({ a <- 1L })", NULL, linter)

# rlang
expect_lint("expr(a <- 1L)", NULL, linter)
expect_lint("quo(a <- 1L)", NULL, linter)
expect_lint("quos(a <- 1L)", NULL, linter)
expect_lint(
trim_some("
foo({
a <- 1L
})
"),
NULL,
linter
)
expect_lint(
trim_some("
output <- capture.output({
x <- f()
})
"),
NULL,
linter
)
expect_lint(
trim_some("
quote({
a <- 1L
})
"),
NULL,
linter
)
expect_lint(
trim_some("
bquote({
a <- 1L
})
"),
NULL,
linter
)
expect_lint(
trim_some("
expression({
a <- 1L
})
"),
NULL,
linter
)
expect_lint(
trim_some("
local({
a <- 1L
})
"),
NULL,
linter
)
})

# withr
expect_lint("with_options(list(digits = 3L), x <- getOption('digits'))", NULL, linter)
test_that("implicit_assignment_linter makes exceptions for functions that capture side-effects", {
linter <- implicit_assignment_linter()

# testthat
expect_lint("expect_warning(out <- f(-1))", NULL, linter)
Expand All @@ -204,6 +248,14 @@ test_that("implicit_assignment_linter makes exceptions for functions that captur
NULL,
linter
)

# rlang
expect_lint("expr(a <- 1L)", NULL, linter)
expect_lint("quo(a <- 1L)", NULL, linter)
expect_lint("quos(a <- 1L)", NULL, linter)

# withr
expect_lint("with_options(list(digits = 3L), x <- getOption('digits'))", NULL, linter)
})

test_that("implicit_assignment_linter blocks disallowed usages in simple conditional statements", {
Expand Down