-
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?
Changes from 4 commits
d5e43c5
af7c4cd
5a710c8
cc167c4
130c02f
af6a43b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,13 +42,8 @@ | |
#' ) | ||
#' @export | ||
expect_lint <- function(content, checks, ..., file = NULL, language = "en") { | ||
if (!requireNamespace("testthat", quietly = TRUE)) { | ||
stop( # nocov start | ||
"'expect_lint' and 'expect_no_lint' are designed to work within the 'testthat' testing framework, ", | ||
"but 'testthat' is not installed.", | ||
call. = FALSE | ||
) # nocov end | ||
} | ||
require_testthat("expect_lint") | ||
|
||
old_lang <- set_lang(language) | ||
on.exit(reset_lang(old_lang)) | ||
|
||
|
@@ -129,18 +124,20 @@ expect_lint <- function(content, checks, ..., file = NULL, language = "en") { | |
#' @rdname expect_lint | ||
#' @export | ||
expect_no_lint <- function(content, ..., file = NULL, language = "en") { | ||
require_testthat("expect_no_lint") | ||
expect_lint(content, NULL, ..., file = file, language = language) | ||
} | ||
|
||
#' Test that the package is lint free | ||
#' | ||
#' This function is a thin wrapper around lint_package that simply tests there are no | ||
#' lints in the package. It can be used to ensure that your tests fail if the package | ||
#' contains lints. | ||
#' This function is a thin wrapper around lint_package that simply tests there are no lints in the package. | ||
#' It can be used to ensure that your tests fail if the package contains lints. | ||
#' | ||
#' @param ... arguments passed to [lint_package()] | ||
#' @export | ||
expect_lint_free <- function(...) { | ||
require_testthat("expect_lint_free") | ||
|
||
testthat::skip_on_cran() | ||
testthat::skip_on_covr() | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. I would not require the argument, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested this a bit. |
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are correct. Added a space. |
||
call. = FALSE | ||
) # nocov end | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.