diff --git a/tests/testthat/test-namespace_linter.R b/tests/testthat/test-namespace_linter.R index 081e38b21..847aad215 100644 --- a/tests/testthat/test-namespace_linter.R +++ b/tests/testthat/test-namespace_linter.R @@ -1,34 +1,34 @@ test_that("namespace_linter skips allowed usages", { linter <- namespace_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_no_lint("stats::sd", linter) + expect_no_lint("stats::sd(c(1,2,3))", linter) + expect_no_lint('"stats"::sd(c(1,2,3))', linter) + expect_no_lint('stats::"sd"(c(1,2,3))', linter) + expect_no_lint("stats::`sd`(c(1,2,3))", linter) - expect_lint("datasets::mtcars", NULL, linter) - expect_lint("stats:::print.formula", NULL, linter) - expect_lint('"stats":::print.formula', NULL, linter) + expect_no_lint("datasets::mtcars", linter) + expect_no_lint("stats:::print.formula", linter) + expect_no_lint('"stats":::print.formula', 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_no_lint("stats::ssd(c(1,2,3))", namespace_linter(check_exports = FALSE)) + expect_no_lint("stats:::ssd(c(1,2,3))", namespace_linter(check_nonexports = FALSE)) + expect_no_lint("stats:::ssd(c(1,2,3))", namespace_linter(check_exports = FALSE, check_nonexports = FALSE)) }) test_that("namespace_linter can work with backticked symbols", { skip_if_not_installed("rlang") linter <- namespace_linter() - expect_lint("rlang::`%||%`", NULL, linter) - expect_lint("rlang::`%||%`()", NULL, linter) + expect_no_lint("rlang::`%||%`", linter) + expect_no_lint("rlang::`%||%`()", linter) - expect_lint("rlang::'%||%'", NULL, linter) - expect_lint("rlang::'%||%'()", NULL, linter) - expect_lint('rlang::"%||%"', NULL, linter) - expect_lint('rlang::"%||%"()', NULL, linter) + expect_no_lint("rlang::'%||%'", linter) + expect_no_lint("rlang::'%||%'()", linter) + expect_no_lint('rlang::"%||%"', linter) + expect_no_lint('rlang::"%||%"()', linter) expect_lint("rlang::`%>%`", "'%>%' is not exported from {rlang}.", linter) expect_lint("rlang::'%>%'()", "'%>%' is not exported from {rlang}.", linter) diff --git a/tests/testthat/test-redundant_ifelse_linter.R b/tests/testthat/test-redundant_ifelse_linter.R index bf7fbc0ae..1c4bf7830 100644 --- a/tests/testthat/test-redundant_ifelse_linter.R +++ b/tests/testthat/test-redundant_ifelse_linter.R @@ -1,13 +1,13 @@ test_that("redundant_ifelse_linter skips allowed usages", { linter <- redundant_ifelse_linter() - expect_lint("ifelse(x > 5, 0, 2)", NULL, linter) - expect_lint("ifelse(x > 5, TRUE, NA)", NULL, linter) - expect_lint("ifelse(x > 5, FALSE, NA)", NULL, linter) - expect_lint("ifelse(x > 5, TRUE, TRUE)", NULL, linter) + expect_no_lint("ifelse(x > 5, 0, 2)", linter) + expect_no_lint("ifelse(x > 5, TRUE, NA)", linter) + expect_no_lint("ifelse(x > 5, FALSE, NA)", linter) + expect_no_lint("ifelse(x > 5, TRUE, TRUE)", linter) - expect_lint("ifelse(x > 5, 0L, 2L)", NULL, linter) - expect_lint("ifelse(x > 5, 0L, 10L)", NULL, linter) + expect_no_lint("ifelse(x > 5, 0L, 2L)", linter) + expect_no_lint("ifelse(x > 5, 0L, 10L)", linter) }) test_that("redundant_ifelse_linter blocks simple disallowed usages", { @@ -111,38 +111,38 @@ test_that("redundant_ifelse_linter blocks usages equivalent to as.numeric, optio test_that("allow10 works as intended", { linter <- redundant_ifelse_linter(allow10 = TRUE) - expect_lint("ifelse(x > 5, 1L, 0L)", NULL, linter) - expect_lint("ifelse(x > 5, 0L, 1L)", NULL, linter) + expect_no_lint("ifelse(x > 5, 1L, 0L)", linter) + expect_no_lint("ifelse(x > 5, 0L, 1L)", linter) - expect_lint("ifelse(x > 5, 1, 0)", NULL, linter) - expect_lint("ifelse(x > 5, 0, 1)", NULL, linter) + expect_no_lint("ifelse(x > 5, 1, 0)", linter) + expect_no_lint("ifelse(x > 5, 0, 1)", linter) - expect_lint("dplyr::if_else(x > 5, 1L, 0L)", NULL, linter) - expect_lint("data.table::fifelse(x > 5, 0L, 1L)", NULL, linter) + expect_no_lint("dplyr::if_else(x > 5, 1L, 0L)", linter) + expect_no_lint("data.table::fifelse(x > 5, 0L, 1L)", linter) - expect_lint("if_else(x > 5, 1, 0)", NULL, linter) - expect_lint("fifelse(x > 5, 0, 1)", NULL, linter) + expect_no_lint("if_else(x > 5, 1, 0)", linter) + expect_no_lint("fifelse(x > 5, 0, 1)", linter) }) test_that("ifelse(missing = ) gives correct lints", { linter <- redundant_ifelse_linter() expect_lint("if_else(x > 5, TRUE, FALSE, NA)", rex::rex("Just use the logical condition"), linter) - expect_lint("if_else(x > 5, TRUE, FALSE, TRUE)", NULL, linter) - expect_lint("if_else(x > 5, TRUE, FALSE, 5L)", NULL, linter) + expect_no_lint("if_else(x > 5, TRUE, FALSE, TRUE)", linter) + expect_no_lint("if_else(x > 5, TRUE, FALSE, 5L)", linter) expect_lint("if_else(x > 5, 1L, 0L, NA_integer_)", rex::rex("Prefer as.integer(x)"), linter) - expect_lint("if_else(x > 5, 1L, 0L, 2L)", NULL, linter) - expect_lint("if_else(x > 5, 1L, 0L, 5)", NULL, linter) + expect_no_lint("if_else(x > 5, 1L, 0L, 2L)", linter) + expect_no_lint("if_else(x > 5, 1L, 0L, 5)", linter) expect_lint("if_else(x > 5, 1, 0, NA_real_)", rex::rex("Prefer as.numeric(x)"), linter) - expect_lint("if_else(x > 5, 1, 0, 2)", NULL, linter) - expect_lint("if_else(x > 5, 1, 0, '5')", NULL, linter) + expect_no_lint("if_else(x > 5, 1, 0, 2)", linter) + expect_no_lint("if_else(x > 5, 1, 0, '5')", linter) # TRUE/FALSE must be found in yes/no, not missing= - expect_lint("if_else(x > 5, 'a', TRUE, FALSE)", NULL, linter) - expect_lint("if_else(x > 5, 'a', 0L, 1L)", NULL, linter) - expect_lint("if_else(x > 5, 'a', 1, 0)", NULL, linter) + expect_no_lint("if_else(x > 5, 'a', TRUE, FALSE)", linter) + expect_no_lint("if_else(x > 5, 'a', 0L, 1L)", linter) + expect_no_lint("if_else(x > 5, 'a', 1, 0)", linter) }) test_that("lints vectorize", { diff --git a/tests/testthat/test-which_grepl_linter.R b/tests/testthat/test-which_grepl_linter.R index 2c3a4e3ba..3f7b780a5 100644 --- a/tests/testthat/test-which_grepl_linter.R +++ b/tests/testthat/test-which_grepl_linter.R @@ -1,6 +1,6 @@ test_that("which_grepl_linter skips allowed usages", { # this _could_ be combined as p1|p2, but often it's cleaner to read this way - expect_lint("which(grepl(p1, x) | grepl(p2, x))", NULL, which_grepl_linter()) + expect_no_lint("which(grepl(p1, x) | grepl(p2, x))", which_grepl_linter()) }) test_that("which_grepl_linter blocks simple disallowed usages", { diff --git a/tests/testthat/test-whitespace_linter.R b/tests/testthat/test-whitespace_linter.R index 0a6aca9d6..bd48ac9e4 100644 --- a/tests/testthat/test-whitespace_linter.R +++ b/tests/testthat/test-whitespace_linter.R @@ -1,24 +1,22 @@ test_that("whitespace_linter skips allowed usages", { linter <- whitespace_linter() - expect_lint("blah", NULL, linter) - expect_lint(" blah", NULL, linter) - expect_lint(" blah", NULL, linter) - expect_lint("#\tblah", NULL, linter) + expect_no_lint("blah", linter) + expect_no_lint(" blah", linter) + expect_no_lint(" blah", linter) + expect_no_lint("#\tblah", linter) }) test_that("whitespace_linter skips allowed tab usages inside strings", { linter <- whitespace_linter() - expect_lint( + expect_no_lint( 'lint_msg <- "dont flag tabs if\tthey are inside a string."', - NULL, linter ) - expect_lint( + expect_no_lint( 'lint_msg <- "dont flag tabs if\n\tthey are inside multiline strings."', - NULL, linter ) }) diff --git a/tests/testthat/test-yoda_test_linter.R b/tests/testthat/test-yoda_test_linter.R index 812440d9e..09d1d9da5 100644 --- a/tests/testthat/test-yoda_test_linter.R +++ b/tests/testthat/test-yoda_test_linter.R @@ -1,12 +1,12 @@ test_that("yoda_test_linter skips allowed usages", { linter <- yoda_test_linter() - expect_lint("expect_equal(x, 2)", NULL, linter) + expect_no_lint("expect_equal(x, 2)", linter) # namespace qualification doesn't matter - expect_lint("testthat::expect_identical(x, 'a')", NULL, linter) + expect_no_lint("testthat::expect_identical(x, 'a')", linter) # two variables can't be distinguished which is expected/actual (without # playing quixotic games trying to parse that out from variable names) - expect_lint("expect_equal(x, y)", NULL, linter) + expect_no_lint("expect_equal(x, y)", linter) }) test_that("yoda_test_linter blocks simple disallowed usages", { @@ -24,8 +24,8 @@ test_that("yoda_test_linter ignores strings in $ expressions", { linter <- yoda_test_linter() # the "key" here shows up at the same level of the parse tree as plain "key" normally would - expect_lint('expect_equal(x$"key", 2)', NULL, linter) - expect_lint('expect_equal(x@"key", 2)', NULL, linter) + expect_no_lint('expect_equal(x$"key", 2)', linter) + expect_no_lint('expect_equal(x@"key", 2)', linter) }) # if we only inspect the first argument & ignore context, get false positives @@ -34,7 +34,7 @@ local({ linter <- yoda_test_linter() patrick::with_parameters_test_that( "yoda_test_linter ignores usage in pipelines", - expect_lint(sprintf("foo() %s expect_identical(2)", pipe), NULL, linter), + expect_no_lint(sprintf("foo() %s expect_identical(2)", pipe), linter), pipe = pipes, .test_name = names(pipes) )