Skip to content

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

Merged
merged 6 commits into from
Aug 1, 2023
Merged

Run single test #1840

merged 6 commits into from
Aug 1, 2023

Conversation

hadley
Copy link
Member

@hadley hadley commented Jul 31, 2023

Fixes #1776

@hadley hadley requested review from jennybc and kevinushey July 31, 2023 18:02
Copy link
Collaborator

@kevinushey kevinushey left a 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,
Copy link
Collaborator

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?

Copy link
Member Author

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

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")?

Copy link
Member Author

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.

Copy link
Member

@jennybc jennybc left a 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 (or desc?) 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.
Copy link
Member

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.

Copy link
Member Author

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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?

Copy link
Member Author

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,
Copy link
Member

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

Copy link
Member Author

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.

@hadley hadley merged commit a478401 into main Aug 1, 2023
@hadley hadley deleted the run-single-test branch August 1, 2023 22:01
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.
Copy link
Member

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.

Copy link
Member

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.

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.

Feature request: Run a single named test within a file
3 participants