11test_that(" conjunct_test_linter skips allowed usages of expect_true" , {
2- expect_lint(" expect_true(x)" , NULL , conjunct_test_linter())
3- expect_lint(" testthat::expect_true(x, y, z)" , NULL , conjunct_test_linter())
2+ linter <- conjunct_test_linter()
3+
4+ expect_no_lint(" expect_true(x)" , linter )
5+ expect_no_lint(" testthat::expect_true(x, y, z)" , linter )
46
57 # more complicated expression
6- expect_lint (" expect_true(x || (y && z))" , NULL , conjunct_test_linter() )
8+ expect_no_lint (" expect_true(x || (y && z))" , linter )
79 # the same by operator precedence, though not obvious a priori
8- expect_lint (" expect_true(x || y && z)" , NULL , conjunct_test_linter() )
9- expect_lint (" expect_true(x && y || z)" , NULL , conjunct_test_linter() )
10+ expect_no_lint (" expect_true(x || y && z)" , linter )
11+ expect_no_lint (" expect_true(x && y || z)" , linter )
1012})
1113
1214test_that(" conjunct_test_linter skips allowed usages of expect_true" , {
13- expect_lint(" expect_false(x)" , NULL , conjunct_test_linter())
14- expect_lint(" testthat::expect_false(x, y, z)" , NULL , conjunct_test_linter())
15+ linter <- conjunct_test_linter()
16+
17+ expect_no_lint(" expect_false(x)" , linter )
18+ expect_no_lint(" testthat::expect_false(x, y, z)" , linter )
1519
1620 # more complicated expression
1721 # (NB: xx && yy || zz and xx || yy && zz both parse with || first)
18- expect_lint (" expect_false(x && (y || z))" , NULL , conjunct_test_linter() )
22+ expect_no_lint (" expect_false(x && (y || z))" , linter )
1923})
2024
2125test_that(" conjunct_test_linter blocks && conditions with expect_true()" , {
@@ -43,14 +47,14 @@ test_that("conjunct_test_linter blocks || conditions with expect_false()", {
4347test_that(" conjunct_test_linter skips allowed stopifnot() and assert_that() usages" , {
4448 linter <- conjunct_test_linter()
4549
46- expect_lint (" stopifnot(x)" , NULL , linter )
47- expect_lint (" assert_that(x, y, z)" , NULL , linter )
50+ expect_no_lint (" stopifnot(x)" , linter )
51+ expect_no_lint (" assert_that(x, y, z)" , linter )
4852
4953 # more complicated expression
50- expect_lint (" stopifnot(x || (y && z))" , NULL , linter )
54+ expect_no_lint (" stopifnot(x || (y && z))" , linter )
5155 # the same by operator precedence, though not obvious a priori
52- expect_lint (" stopifnot(x || y && z)" , NULL , linter )
53- expect_lint (" assertthat::assert_that(x && y || z)" , NULL , linter )
56+ expect_no_lint (" stopifnot(x || y && z)" , linter )
57+ expect_no_lint (" assertthat::assert_that(x && y || z)" , linter )
5458})
5559
5660test_that(" conjunct_test_linter blocks simple disallowed usages of stopifnot() and assert_that()" , {
@@ -66,12 +70,23 @@ test_that("conjunct_test_linter blocks simple disallowed usages of stopifnot() a
6670})
6771
6872test_that(" conjunct_test_linter's allow_named_stopifnot argument works" , {
73+ linter <- conjunct_test_linter()
74+
6975 # allowed by default
70- expect_lint (
76+ expect_no_lint (
7177 " stopifnot('x must be a logical scalar' = length(x) == 1 && is.logical(x) && !is.na(x))" ,
72- NULL ,
73- conjunct_test_linter()
78+ linter
7479 )
80+ # including with intervening comment
81+ expect_no_lint(
82+ trim_some("
83+ stopifnot('x must be a logical scalar' = # comment
84+ length(x) == 1 && is.logical(x) && !is.na(x)
85+ )
86+ " ),
87+ linter
88+ )
89+
7590 expect_lint(
7691 " stopifnot('x is a logical scalar' = length(x) == 1 && is.logical(x) && !is.na(x))" ,
7792 rex :: rex(" Write multiple conditions like stopifnot(A, B)" ),
@@ -82,11 +97,11 @@ test_that("conjunct_test_linter's allow_named_stopifnot argument works", {
8297test_that(" conjunct_test_linter skips allowed usages" , {
8398 linter <- conjunct_test_linter()
8499
85- expect_lint (" dplyr::filter(DF, A, B)" , NULL , linter )
86- expect_lint (" dplyr::filter(DF, !(A & B))" , NULL , linter )
100+ expect_no_lint (" dplyr::filter(DF, A, B)" , linter )
101+ expect_no_lint (" dplyr::filter(DF, !(A & B))" , linter )
87102 # | is the "top-level" operator here
88- expect_lint (" dplyr::filter(DF, A & B | C)" , NULL , linter )
89- expect_lint (" dplyr::filter(DF, A | B & C)" , NULL , linter )
103+ expect_no_lint (" dplyr::filter(DF, A & B | C)" , linter )
104+ expect_no_lint (" dplyr::filter(DF, A | B & C)" , linter )
90105})
91106
92107test_that(" conjunct_test_linter blocks simple disallowed usages" , {
@@ -105,22 +120,22 @@ test_that("conjunct_test_linter respects its allow_filter argument", {
105120 linter_dplyr <- conjunct_test_linter(allow_filter = " not_dplyr" )
106121 lint_msg <- rex :: rex(" Use dplyr::filter(DF, A, B) instead of dplyr::filter(DF, A & B)" )
107122
108- expect_lint (" dplyr::filter(DF, A & B)" , NULL , linter_always )
109- expect_lint (" dplyr::filter(DF, A & B & C)" , NULL , linter_always )
110- expect_lint (" DF %>% dplyr::filter(A & B)" , NULL , linter_always )
123+ expect_no_lint (" dplyr::filter(DF, A & B)" , linter_always )
124+ expect_no_lint (" dplyr::filter(DF, A & B & C)" , linter_always )
125+ expect_no_lint (" DF %>% dplyr::filter(A & B)" , linter_always )
111126 expect_lint(" dplyr::filter(DF, A & B)" , lint_msg , linter_dplyr )
112127 expect_lint(" dplyr::filter(DF, A & B & C)" , lint_msg , linter_dplyr )
113128 expect_lint(" DF %>% dplyr::filter(A & B)" , lint_msg , linter_dplyr )
114- expect_lint (" filter(DF, A & B)" , NULL , linter_dplyr )
115- expect_lint (" filter(DF, A & B & C)" , NULL , linter_dplyr )
116- expect_lint (" DF %>% filter(A & B)" , NULL , linter_dplyr )
129+ expect_no_lint (" filter(DF, A & B)" , linter_dplyr )
130+ expect_no_lint (" filter(DF, A & B & C)" , linter_dplyr )
131+ expect_no_lint (" DF %>% filter(A & B)" , linter_dplyr )
117132})
118133
119134test_that(" filter() is assumed to be dplyr::filter() by default, unless o/w specified" , {
120135 linter <- conjunct_test_linter()
121136
122- expect_lint (" stats::filter(A & B)" , NULL , linter )
123- expect_lint (" ns::filter(A & B)" , NULL , linter )
137+ expect_no_lint (" stats::filter(A & B)" , linter )
138+ expect_no_lint (" ns::filter(A & B)" , linter )
124139 expect_lint(
125140 " DF %>% filter(A & B)" ,
126141 rex :: rex(" Use dplyr::filter(DF, A, B) instead of dplyr::filter(DF, A & B)" ),
0 commit comments