Skip to content

Commit

Permalink
Additional test for namespace_linter()+ clean-up (#1649)
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil authored Oct 8, 2022
1 parent 0af31f5 commit 854b2c7
Showing 1 changed file with 17 additions and 51 deletions.
68 changes: 17 additions & 51 deletions tests/testthat/test-namespace_linter.R
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
test_that("returns the correct linting", {
test_that("namespace_linter skips allowed usages", {
linter <- namespace_linter()

expect_lint(
"stats::sd",
NULL,
linter
)
expect_lint("stats::sd", NULL, linter)
expect_lint("stats::sd(c(1,2,3))", NULL, linter)
expect_lint('"stats"::sd(c(1,2,3))', NULL, linter)
expect_lint('stats::"sd"(c(1,2,3))', NULL, linter)
expect_lint("stats::`sd`(c(1,2,3))", NULL, linter)

expect_lint(
"stats::sd(c(1,2,3))",
NULL,
linter
)

expect_lint(
'"stats"::sd(c(1,2,3))',
NULL,
linter
)
expect_lint("datasets::mtcars", NULL, linter)
expect_lint("stats:::print.formula", NULL, linter)
expect_lint('"stats":::print.formula', NULL, linter)
})

expect_lint(
'stats::"sd"(c(1,2,3))',
NULL,
linter
)
test_that("namespace_linter respects check_exports and check_nonexports arguments", {
expect_lint("stats::ssd(c(1,2,3))", NULL, namespace_linter(check_exports = FALSE))
expect_lint("stats:::ssd(c(1,2,3))", NULL, namespace_linter(check_nonexports = FALSE))
expect_lint("stats:::ssd(c(1,2,3))", NULL, namespace_linter(check_exports = FALSE, check_nonexports = FALSE))
})

expect_lint(
"stats::`sd`(c(1,2,3))",
NULL,
linter
)
test_that("namespace_linter blocks disallowed usages", {
linter <- namespace_linter()

expect_lint(
"statts::sd(c(1,2,3))",
Expand All @@ -43,24 +33,6 @@ test_that("returns the correct linting", {
linter
)

expect_lint(
"stats::ssd(c(1,2,3))",
NULL,
namespace_linter(check_exports = FALSE)
)

expect_lint(
"datasets::mtcars",
NULL,
linter
)

expect_lint(
"stats:::print.formula",
NULL,
linter
)

expect_lint(
"stats:::sd(c(1,2,3))",
list(message = rex::rex("'sd' is exported from {stats}. Use stats::sd instead.")),
Expand All @@ -79,12 +51,6 @@ test_that("returns the correct linting", {
linter
)

expect_lint(
"stats:::sdd(c(1,2,3))",
NULL,
namespace_linter(check_nonexports = FALSE)
)

expect_lint(
"stats::sd(c(1,2,3))\nstats::sdd(c(1,2,3))",
list(line = "stats::sdd(c(1,2,3))"),
Expand Down

0 comments on commit 854b2c7

Please sign in to comment.