From 854b2c7442008b4d091b72fe52e16995d86d333b Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Sat, 8 Oct 2022 19:20:37 +0200 Subject: [PATCH] Additional test for `namespace_linter()`+ clean-up (#1649) --- tests/testthat/test-namespace_linter.R | 68 +++++++------------------- 1 file changed, 17 insertions(+), 51 deletions(-) diff --git a/tests/testthat/test-namespace_linter.R b/tests/testthat/test-namespace_linter.R index 0bbf3e4e9..fba9d7624 100644 --- a/tests/testthat/test-namespace_linter.R +++ b/tests/testthat/test-namespace_linter.R @@ -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))", @@ -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.")), @@ -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))"),