1
1
test_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 )
4
6
5
7
# 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 )
7
9
# 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 )
10
12
})
11
13
12
14
test_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 )
15
19
16
20
# more complicated expression
17
21
# (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 )
19
23
})
20
24
21
25
test_that(" conjunct_test_linter blocks && conditions with expect_true()" , {
@@ -43,14 +47,14 @@ test_that("conjunct_test_linter blocks || conditions with expect_false()", {
43
47
test_that(" conjunct_test_linter skips allowed stopifnot() and assert_that() usages" , {
44
48
linter <- conjunct_test_linter()
45
49
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 )
48
52
49
53
# more complicated expression
50
- expect_lint (" stopifnot(x || (y && z))" , NULL , linter )
54
+ expect_no_lint (" stopifnot(x || (y && z))" , linter )
51
55
# 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 )
54
58
})
55
59
56
60
test_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
66
70
})
67
71
68
72
test_that(" conjunct_test_linter's allow_named_stopifnot argument works" , {
73
+ linter <- conjunct_test_linter()
74
+
69
75
# allowed by default
70
- expect_lint (
76
+ expect_no_lint (
71
77
" stopifnot('x must be a logical scalar' = length(x) == 1 && is.logical(x) && !is.na(x))" ,
72
- NULL ,
73
- conjunct_test_linter()
78
+ linter
74
79
)
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
+
75
90
expect_lint(
76
91
" stopifnot('x is a logical scalar' = length(x) == 1 && is.logical(x) && !is.na(x))" ,
77
92
rex :: rex(" Write multiple conditions like stopifnot(A, B)" ),
@@ -82,11 +97,11 @@ test_that("conjunct_test_linter's allow_named_stopifnot argument works", {
82
97
test_that(" conjunct_test_linter skips allowed usages" , {
83
98
linter <- conjunct_test_linter()
84
99
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 )
87
102
# | 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 )
90
105
})
91
106
92
107
test_that(" conjunct_test_linter blocks simple disallowed usages" , {
@@ -105,22 +120,22 @@ test_that("conjunct_test_linter respects its allow_filter argument", {
105
120
linter_dplyr <- conjunct_test_linter(allow_filter = " not_dplyr" )
106
121
lint_msg <- rex :: rex(" Use dplyr::filter(DF, A, B) instead of dplyr::filter(DF, A & B)" )
107
122
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 )
111
126
expect_lint(" dplyr::filter(DF, A & B)" , lint_msg , linter_dplyr )
112
127
expect_lint(" dplyr::filter(DF, A & B & C)" , lint_msg , linter_dplyr )
113
128
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 )
117
132
})
118
133
119
134
test_that(" filter() is assumed to be dplyr::filter() by default, unless o/w specified" , {
120
135
linter <- conjunct_test_linter()
121
136
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 )
124
139
expect_lint(
125
140
" DF %>% filter(A & B)" ,
126
141
rex :: rex(" Use dplyr::filter(DF, A, B) instead of dplyr::filter(DF, A & B)" ),
0 commit comments