-
Notifications
You must be signed in to change notification settings - Fork 321
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
Add support for test files in nested directories #1850
base: main
Are you sure you want to change the base?
Conversation
Give test_dir() a recursive option (r-lib#1605) The recursive argument allows test files in nested directories.
Hi @hadley, would you have time to review this PR for the 3.2.2 release? Thanks! |
@radbasa this feels like a big change, so it'd need to wait for the next minor release, sorry. |
find_test_scripts <- function(path, filter = NULL, invert = FALSE, ..., full.names = TRUE, start_first = NULL, recursive = FALSE) { | ||
files <- dir(path, "^test.*\\.[rR]$", full.names = full.names, recursive = recursive) |
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.
@hadley , understood. We'll wait for the next release.
If you don't mind, I'm leaving this here as a note for when you have the time to review this pull request.
This is the only significant change to the {testthat}
code. It's a simple use of the recursive
flag parameter of the dir()
function. The rest of the logical/functional changes are to expose the recursive
flag to the relevant external facing functions.
The rest of the PR are unit tests.
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.
Right, the code change is small, but the implications are large. For example, off the top of my head, how does this affect snapshot tests? Do they end up in the right place?
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.
Would it help if I add unit tests for snapshot tests, both regression for non-recursive and for the new recursive mode? I'll also think of other possible tests relevant to test_dir()
.
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.
That would definitely help. It'll still require that we wait for a minor release (since I'll need to spend some time thinking about other potential areas where this change might cause problems), but it's definitely something that will need to be explored before this PR can be merged.
Closes #1605
Allows the use of directories to organize test files.
The
recursive
argument is optional and defaults toFALSE
.testthat::test_dir("tests/testthat/")
will work as before. Just one single directory, and with the default reporter.testthat::test_dir("tests/testthat/", recursive = TRUE)
to run all of the test scripts in all directories intests/testthat/
.testthat::test_dir()
will still only see test scripts with^test.*\\.[rR]$
filenames.