-
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
Open
radbasa
wants to merge
9
commits into
r-lib:main
Choose a base branch
from
Appsilon:feature/add-recursive-dirs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ca0543e
Updated source code from rlib/testthat/main (#5)
radbasa 7feb406
Merge branch 'main' into feature/add-recursive-dirs
radbasa 79d77b1
fix news.md
radbasa dde1741
cleaning up some post-merge duplication
radbasa 9b608c5
Merge branch 'main' into feature/add-recursive-dirs
radbasa 8cd37ba
Merge branch 'main' into feature/add-recursive-dirs
radbasa e3e0773
Merge branch 'main' into feature/add-recursive-dirs
radbasa da5911b
Merge branch 'main' into feature/add-recursive-dirs
radbasa c885313
Merge branch 'main' into feature/add-recursive-dirs
radbasa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: testthat | ||
Title: Unit Testing for R | ||
Version: 3.2.2.9000 | ||
Version: 3.2.2.9001 | ||
Authors@R: c( | ||
person("Hadley", "Wickham", , "[email protected]", role = c("aut", "cre")), | ||
person("Posit Software, PBC", role = c("cph", "fnd")), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello <- function() "Hello World" |
22 changes: 22 additions & 0 deletions
22
tests/testthat/test_dir_recursive/nested_folder/test-errors.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
test_that("simple", { | ||
stop("argh") | ||
}) | ||
|
||
test_that("after one success", { | ||
expect_true(TRUE) | ||
stop("argh") | ||
expect_true(TRUE) | ||
}) | ||
|
||
test_that("after one failure", { | ||
expect_true(FALSE) | ||
stop("argh") | ||
}) | ||
|
||
test_that("in the test", { | ||
expect_true(stop("Argh")) | ||
}) | ||
|
||
test_that("in expect_error", { | ||
expect_error(stop("Argh")) | ||
}) |
13 changes: 13 additions & 0 deletions
13
tests/testthat/test_dir_recursive/nested_folder/test-failures.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
test_that("just one failure", { | ||
expect_true(FALSE) | ||
}) | ||
|
||
test_that("one failure on two", { | ||
expect_false(FALSE) | ||
expect_true(FALSE) | ||
}) | ||
|
||
test_that("no failure", { | ||
expect_false(FALSE) | ||
expect_true(TRUE) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
test_that("Skips skip", { | ||
skip("Skipping to avoid certain failure") | ||
expect_true(FALSE) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
expect_equal(2, 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
test_that("logical tests act as expected", { | ||
expect_true(TRUE) | ||
expect_false(FALSE) | ||
}) | ||
|
||
test_that("logical tests ignore attributes", { | ||
expect_true(c(a = TRUE)) | ||
expect_false(c(a = FALSE)) | ||
}) | ||
|
||
test_that("equality holds", { | ||
expect_equal(5, 5) | ||
expect_identical(10, 10) | ||
}) | ||
|
||
test_that("can't access variables from other tests 2", { | ||
a <- 10 | ||
}) | ||
|
||
test_that("can't access variables from other tests 1", { | ||
expect_false(exists("a")) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test_that("empty test", NULL) | ||
|
||
test_that("empty test with error", stop("Argh")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# test that the companion helper script is sourced by test_dir | ||
test_that("helper test", { | ||
expect_equal(hello(), "Hello World") | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 therecursive
flag parameter of thedir()
function. The rest of the logical/functional changes are to expose therecursive
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.