-
Notifications
You must be signed in to change notification settings - Fork 186
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
Make require_testthat helper function #2587
base: main
Are you sure you want to change the base?
Conversation
R/expect_lint.R
Outdated
require_testthat <- function(name) { | ||
if (!requireNamespace("testthat", quietly = TRUE)) { | ||
stop( # nocov start | ||
name, "is designed to work within the 'testthat' testing framework, but 'testthat' is not installed.", |
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.
Doesn't stop()
use sep = ""
, butchering the error message like this?
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.
You are correct. Added a space.
NEWS.md
Outdated
@@ -56,6 +56,7 @@ | |||
* `make_linter_from_xpath()` errors up front when `lint_message` is missing (instead of delaying this error until the linter is used, #2541, @MichaelChirico). | |||
* `paste_linter()` is extended to recommend using `paste()` instead of `paste0()` for simply aggregating a character vector with `collapse=`, i.e., when `sep=` is irrelevant (#1108, @MichaelChirico). | |||
* `expect_no_lint()` was added as new function to cover the typical use case of expecting no lint message, akin to the recent {testthat} functions like `expect_no_warning()` (#2580, @F-Noelle). | |||
* `expect_lint_free()` and other functions that rely on the {testthat} framework now have a consistent error message. (#2585, @F-Noelle). |
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.
I would put this under a ## Notes
section (see other releases)
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.
Shifted the item to notes.
R/expect_lint.R
Outdated
@@ -158,3 +155,13 @@ expect_lint_free <- function(...) { | |||
|
|||
invisible(result) | |||
} | |||
|
|||
# Helper function to check if testthat is installed. | |||
require_testthat <- function(name) { |
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.
I would not require the argument, e.g. name = sys.call(sys.parent())
, or possibly re-using/unifying with linter_auto_name()
. Then just require_testthat()
.
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.
I tested this a bit. linter_auto_name(-5L)
seems to do the trick.
Addresses issues (#2585)