-
Notifications
You must be signed in to change notification settings - Fork 187
Extend conjunct_expectation_linter to include stopifnot(), rename to conjunct_test_linter #1011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6846de7
f9badf1
231dde5
f70b050
9913740
bce6710
67a5216
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
test_that("conjunct_test_linter skips allowed usages of expect_true", { | ||
expect_lint("expect_true(x)", NULL, conjunct_test_linter()) | ||
expect_lint("testthat::expect_true(x, y, z)", NULL, conjunct_test_linter()) | ||
|
||
# more complicated expression | ||
expect_lint("expect_true(x || (y && z))", NULL, conjunct_test_linter()) | ||
# the same by operator precedence, though not obvious a priori | ||
expect_lint("expect_true(x || y && z)", NULL, conjunct_test_linter()) | ||
expect_lint("expect_true(x && y || z)", NULL, conjunct_test_linter()) | ||
}) | ||
|
||
test_that("conjunct_test_linter skips allowed usages of expect_true", { | ||
expect_lint("expect_false(x)", NULL, conjunct_test_linter()) | ||
expect_lint("testthat::expect_false(x, y, z)", NULL, conjunct_test_linter()) | ||
|
||
# more complicated expression | ||
# (NB: xx && yy || zz and xx || yy && zz both parse with || first) | ||
expect_lint("expect_false(x && (y || z))", NULL, conjunct_test_linter()) | ||
}) | ||
|
||
test_that("conjunct_test_linter blocks && conditions with expect_true()", { | ||
expect_lint( | ||
"expect_true(x && y)", | ||
rex::rex("Instead of expect_true(A && B), write multiple expectations"), | ||
conjunct_test_linter() | ||
) | ||
|
||
expect_lint( | ||
"expect_true(x && y && z)", | ||
rex::rex("Instead of expect_true(A && B), write multiple expectations"), | ||
conjunct_test_linter() | ||
) | ||
}) | ||
|
||
test_that("conjunct_test_linter blocks || conditions with expect_false()", { | ||
expect_lint( | ||
"expect_false(x || y)", | ||
rex::rex("Instead of expect_false(A || B), write multiple expectations"), | ||
conjunct_test_linter() | ||
) | ||
|
||
expect_lint( | ||
"expect_false(x || y || z)", | ||
rex::rex("Instead of expect_false(A || B), write multiple expectations"), | ||
conjunct_test_linter() | ||
) | ||
|
||
# these lint because `||` is always outer by operator precedence | ||
expect_lint( | ||
"expect_false(x || y && z)", | ||
rex::rex("Instead of expect_false(A || B), write multiple expectations"), | ||
conjunct_test_linter() | ||
) | ||
expect_lint( | ||
"expect_false(x && y || z)", | ||
rex::rex("Instead of expect_false(A || B), write multiple expectations"), | ||
conjunct_test_linter() | ||
) | ||
}) | ||
|
||
test_that("conjunct_test_linter skips allowed usages", { | ||
expect_lint("stopifnot(x)", NULL, conjunct_test_linter()) | ||
expect_lint("stopifnot(x, y, z)", NULL, conjunct_test_linter()) | ||
|
||
# more complicated expression | ||
expect_lint("stopifnot(x || (y && z))", NULL, conjunct_test_linter()) | ||
# the same by operator precedence, though not obvious a priori | ||
expect_lint("stopifnot(x || y && z)", NULL, conjunct_test_linter()) | ||
expect_lint("stopifnot(x && y || z)", NULL, conjunct_test_linter()) | ||
}) | ||
|
||
test_that("conjunct_stopifnot_linter blocks simple disallowed usages", { | ||
expect_lint( | ||
"stopifnot(x && y)", | ||
rex::rex("Instead of stopifnot(A && B), write multiple conditions"), | ||
conjunct_test_linter() | ||
) | ||
|
||
expect_lint( | ||
"stopifnot(x && y && z)", | ||
rex::rex("Instead of stopifnot(A && B), write multiple conditions"), | ||
conjunct_test_linter() | ||
) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be just
or text() = 'assert_that'
in the XPathThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right... plus tests. better not to clutter this PR with that