Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

F-Noelle
Copy link
Contributor

@F-Noelle F-Noelle commented May 28, 2024

Addresses issues (#2585)

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.",
Copy link
Collaborator

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?

Copy link
Contributor Author

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).
Copy link
Collaborator

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)

Copy link
Contributor Author

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) {
Copy link
Collaborator

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().

Copy link
Contributor Author

@F-Noelle F-Noelle May 28, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

expect_lint() error for missing {testthat} should reference which function called it
3 participants