-
Notifications
You must be signed in to change notification settings - Fork 330
Run single test #1840
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
Run single test #1840
Conversation
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.
LGTM!
R/source.R
Outdated
source_file <- function(path, | ||
env = test_env(), | ||
chdir = TRUE, | ||
label = NULL, |
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.
Do you think it's worth leaving the door open to multiple labels here?
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'd rather start with a single label, and then later expand, if needed.
if (!is_call(expr, "test_that", n = 2)) { | ||
include[[i]] <- TRUE | ||
} else { | ||
if (!is_string(expr[[2]])) |
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.
Do you need to worry about people running code like test_that({}, desc = "weird")
?
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.
If you do that you're on your own 😄
People do weird things here (i.e. I bet someone does something like test_that(my_fun("my label"), ...)
. If you want to handle those cases, IMO the IDE should figure out the line numbers from its parse tree and pass those through.
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.
Looks good!
One more clump of comments that are not easy to hang off the PR, about test_file()
:
- The title of the help topic is currently "Run all tests in a single file", but the addition of
label
(ordesc
?) changes things. Should we at least remove the "all"? - The docs for
label
here suggest that we might run multiple tests, but I think we want to stay rigidly oriented towards running a single test, yeah?
R/source.R
Outdated
@@ -5,13 +5,18 @@ | |||
#' @param path Path to files. | |||
#' @param pattern Regular expression used to filter files. | |||
#' @param env Environment in which to evaluate code. | |||
#' @param label If not-`NULL`, will run only test with this label. |
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.
We're always going to match label
against desc
in a test_that()
call.
Should we just call this argument desc
?
In any case, I think desc
has to get mentioned here, because "label" isn't an established testthat term.
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.
Ooops, I thought that argument was called the label 😭
for (i in seq_along(exprs)) { | ||
expr <- exprs[[i]] | ||
|
||
if (!is_call(expr, "test_that", n = 2)) { |
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.
if (!is_call(expr, "test_that", n = 2)) { | |
if (!is_call(expr, "test_that", n = 2) && !found) { |
What if we only execute top-level code before the matching test_that()
call?
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.
Oooh good thought.
R/test-files.R
Outdated
test_file <- function(path, reporter = default_compact_reporter(), package = NULL, ...) { | ||
test_file <- function(path, | ||
reporter = default_compact_reporter(), | ||
label = NULL, |
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 think I'm sort of surprised that label
isn't being added after ...
.
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'm not sure how we should remediate functions where ...
is in the wrong place so I'm sticking with the existing convention.
R/test-files.R
Outdated
#' @param label Optionally, supply a string here to run only tests that | ||
#' with this exact label. | ||
#' @param desc Optionally, supply a string here to run only a single | ||
#' tests that with this `desc`ription. |
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.
There's a lingering wording problem here.
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.
Sorry I was looking at an outdated diff. Ignore me.
Fixes #1776