-
Notifications
You must be signed in to change notification settings - Fork 340
More tests of running a nested subtest #2203
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,14 @@ | |
| Error: | ||
| ! `env` must be an environment, not the string "x". | ||
|
|
||
| # works on code like the describe() example | ||
|
|
||
| Code | ||
| filter_desc(code, c("math library", "division()", "can handle division by 0")) | ||
| Condition | ||
| Error: | ||
| ! Failed to find test with description "can handle division by 0". | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just an FYI: the (nested) |
||
|
|
||
| # preserve srcrefs | ||
|
|
||
| Code | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,7 +84,7 @@ test_that("checks its inputs", { | |
|
|
||
| # filter_desc ------------------------------------------------------------- | ||
|
|
||
| test_that("works with all tests types", { | ||
| test_that("works with all subtest types", { | ||
| code <- exprs( | ||
| test_that("foo", {}), | ||
| describe("bar", {}), | ||
|
|
@@ -95,14 +95,15 @@ test_that("works with all tests types", { | |
| expect_equal(filter_desc(code, "baz"), code[3]) | ||
| }) | ||
|
|
||
| test_that("only returns code before subtest", { | ||
| test_that("only returns non-subtest code before subtest", { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seemed worth testing to me, i.e. making sure that the |
||
| code <- exprs( | ||
| f(), | ||
| test_that("bar", {}), | ||
| describe("foo", {}), | ||
| g(), | ||
| h() | ||
| ) | ||
| expect_equal(filter_desc(code, "foo"), code[c(1, 2)]) | ||
| expect_equal(filter_desc(code, "foo"), code[c(1, 3)]) | ||
| }) | ||
|
|
||
| test_that("can select recursively", { | ||
|
|
@@ -132,6 +133,57 @@ test_that("can select recursively", { | |
| ) | ||
| }) | ||
|
|
||
| test_that("works on code like the describe() example", { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More pretty realistic usage that seems worth testing. |
||
| code <- exprs( | ||
| describe("math library", { | ||
| x1 <- 1 | ||
| x2 <- 1 | ||
| describe("addition()", { | ||
| it("can add two numbers", { | ||
| expect_equal(x1 + x2, addition(x1, x2)) | ||
| }) | ||
| }) | ||
| describe("division()", { | ||
| x1 <- 10 | ||
| x2 <- 2 | ||
| it("can divide two numbers", { | ||
| expect_equal(x1 / x2, division(x1, x2)) | ||
| }) | ||
| it("can handle division by 0") #not yet implemented | ||
| }) | ||
| }) | ||
| ) | ||
|
|
||
| expect_equal( | ||
| filter_desc( | ||
| code, | ||
| c("math library", "division()", "can divide two numbers") | ||
| ), | ||
| exprs( | ||
| describe("math library", { | ||
| x1 <- 1 | ||
| x2 <- 1 | ||
| describe("division()", { | ||
| x1 <- 10 | ||
| x2 <- 2 | ||
| it("can divide two numbers", { | ||
| expect_equal(x1 / x2, division(x1, x2)) | ||
| }) | ||
| }) | ||
| }) | ||
| ) | ||
| ) | ||
|
|
||
| # what happens for an unimplemented specification? | ||
| expect_snapshot( | ||
| error = TRUE, | ||
| filter_desc( | ||
| code, | ||
| c("math library", "division()", "can handle division by 0") | ||
| ) | ||
| ) | ||
| }) | ||
|
|
||
| test_that("preserve srcrefs", { | ||
| code <- parse( | ||
| keep.source = TRUE, | ||
|
|
||
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.
This documentation only applies to
source_file()which is marked as internal.The user-facing function(s?) that expose
descdo not yet hint at the ability to run a nested subtest or to run anit(). I know this applies totest_file()and perhaps that is the only affected function.