-
Notifications
You must be signed in to change notification settings - Fork 317
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
Use conditions for reporting results #360
Conversation
for bare expectations
class = c("test_result", "condition")) | ||
|
||
withRestarts( | ||
if (results$passed) signalCondition(cond) else stop(cond), |
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.
Could also call message()
instead of signalCondition()
here.
73cb031
to
e450fbc
Compare
@hadley @jimhester: PTAL. Part of #215 (comment). |
- Return test results as named array of logical. Requires r-lib/testthat#360.
- New tweak `union`, for specifying a nonstandard way of combining queries. - All union queries now use full qualification for each column (required for `bigrquery`). - Return test results as named array of logical. Requires r-lib/testthat#360. - Use fork of `testthat`.
|
||
withRestarts( | ||
{ | ||
signalCondition(cond) |
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.
Call stop() here.
as recommended in adv-r
Now a failing expectation always raises an error, even if the StopReporter isn't active. The update of this test reflects this change in behavior.
- New feature: tweaks - New argument `tweaks` to `make_context()` (#49). - New `tweaks()`, essentially constructs a named list of tweaks but with predefined and documented argument names. - `constructor_name`, respected by the `constructor.*` tests. - `strict_identifier`, if `TRUE` all identifier must be syntactic names even if quoted. The quoting test is now split, and a part is ignored conditional to this tweak. The `roundtrip_quotes` tests also respects this tweak. - `omit_blob_tests` for DBMS that don't have a BLOB data type. - `current_needs_parens` -- some SQL dialects (e.g., BigQuery) require parentheses for the functions `current_date`, `current_time` and `current_timestamp`. - `union`, for specifying a nonstandard way of combining queries. All union queries now name each column in each subquery (required for `bigrquery`). - New tests - `dbGetInfo(Result)` (r-dbi/DBI#55). - `dbListFields()` (#26). - New "package_name" test in `test_getting_started()`. - Improved tests - Stress test now installs package in temporary library (before loading `DBI`) using `R CMD INSTALL` before loading DBI (r-dbi/RSQLite#128, #48). - Row count is now tested for equality but not identity, so that backends can return a numeric value > 2^31 at their discretion. - Call `dbRemoveTable()` instead of issuing `DROP` requests, the latter might be unsupported. - Use subqueries in queries that use `WHERE`. - Test that `dbClearResult()` on a closed result set raises a warning. - Expect a warning instead of an error for double disconnect (#50). - Move connection test that requires `dbFetch()` to `test_result()`. - Split "can_connect_and_disconnect" test. - Expect `DBI` to be in `Imports`, not in `Depends`. - Removed tests - Remove test for `dbGetException()` (r-dbi/DBI#51). - Bug fixes - Fix broken tests for quoting. - Self-testing - Test `RPostgres`, `RMySQL`, `RSQLite` and `RKazam` as part of the Travis-CI tests (#52). - Travis CI now installs rstats-db/DBI, updated namespace imports (`dbiCheckCompliance()`, `dbListResults()`). - Use fork of `testthat`. - Utilities - Return test results as named array of logical. Requires r-lib/testthat#360, gracefully degrades with the CRAN version. - Internal - Refactored the `get_info_()` tests to use a vector of names. - Use versioned dependency for DBI - Use unqualified calls to `dbBind()` again - Same as 1.0-8.
@@ -73,6 +82,28 @@ test_code <- function(description, code, env) { | |||
invisible(ok) | |||
} | |||
|
|||
report_results <- function(results) { |
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.
I think this would be better called report_expectation()
, but I'm not sure report()
is quite the right verb (but I'm not sure what would be better)
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.
Or should this all be wrapped up into expectation()
?
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.
Do you mean that expectation() should create and raise the condition object? This means that we need to be very clever in expect_that(): Catch the condition (which is created in the condition(object) call), patch it, and re-raise it. To me, this looks like too much effort for too little gain. But I agree that expectation() should return a proper condition object right away. I'll update the PR soon.
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.
Maybe we should have expectation()
(noun) to create the object, and expect()
(verb) raise the condition?
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.
We already have expect() which accepts a logical and a message; we'll need as.expectation.logical() and as.expectation.expectation() to avoid changing too much unrelated code, but otherwise this is doable. How does that sound?
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.
Then we'll add as.expectation.error(), as.expectation.skip() (as replacement for current expecation_error() and expectation_skipped()) and later as.expectation.warning() (#310).
Are you planning further refactorings? Then it would be great to merge this beforehand, otherwise I'll work further on this branch. |
I don't have anything else major planned - I think most of the other issues need this PR completed first. |
Extracted expectation_ok(), got rid of success_msg in my code, added two TODO markers. I think test_code() can be simplified considerably, so that there's basically just one handler function taking care of everything. The reporter should be able to decide if tryCatch() catches the errors or not (#356) :
I'll merge the other PR before adding NEWS to this PR. |
update_expectation(exp, srcref) | ||
} | ||
|
||
update_expectation <- function(exp, srcref, info = NULL, label = NULL) { |
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.
It feels like we should be able to eventually eliminate this function, wrapping it into the constructor
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.
Difficult without finally deprecating info and label arguments (#218).
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.
Yeah, lets look again once we've eliminated those args and refactored the expectations
Done. One more thing: expectation() is exported, you have changed its interface. Perhaps it's safer to keep success_msg (with a warning), or introduce a ... . |
Yeah, I'm not too worried about that. I think the next release will be testthat 1.0.0 so it's ok to make a few breaking changes (and I doubt this one will affect many people) |
And looks good to merge - feel free whenever you think it's ready |
Also: test_that() returns TRUE if successful (no failed expectations, errors, or skips) for programmatic use of testthat.
Bare expectations now simply stop if a test fails. The stop occurs upon the first event, unlike the StopReporter which stops after the first failed test.