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

Add support for test files in nested directories #1850

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

Conversation

radbasa
Copy link

@radbasa radbasa commented Aug 29, 2023

Closes #1605

Allows the use of directories to organize test files.

The recursive argument is optional and defaults to FALSE.

  1. testthat::test_dir("tests/testthat/") will work as before. Just one single directory, and with the default reporter.
  2. testthat::test_dir("tests/testthat/", recursive = TRUE) to run all of the test scripts in all directories in tests/testthat/. testthat::test_dir() will still only see test scripts with ^test.*\\.[rR]$ filenames.

@radbasa
Copy link
Author

radbasa commented Dec 12, 2024

Hi @hadley, would you have time to review this PR for the 3.2.2 release? Thanks!

@hadley
Copy link
Member

hadley commented Jan 6, 2025

@radbasa this feels like a big change, so it'd need to wait for the next minor release, sorry.

Comment on lines +385 to +386
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)
Copy link
Author

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.

Copy link
Member

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?

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.

Provide optional recursive argument to test_dir()
3 participants