-
Notifications
You must be signed in to change notification settings - Fork 20
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
Support for custom expectations? #22
Comments
Indeed, currently |
Hi Michael, so I figured out how to do it. If I implement it, the API would look something like this.
tinytest::tinytest(result, call, diff, short) where
options(tt.extensions = list(checkmate = c("expect_hihi","expect_haha")) This can be left to the user or you do it in your This means we are not compatible with Let me know what you think. edit I have not tested this really, and I'm not sure if/how it works when functions from your package use other functions internal to your package. I have to experiment with that as well before I know whether it really works. edit again Ok it can be made to work. It takes a bit of detailed work so probably not in the next release. |
Your approach looks good to me. I'll have a closer look next week and report back if everything works out. As both unit test frameworks come with the same naming scheme for expectations (
Do you see any other options? |
When I read the post of @markvanderloo yesterday, I thought I would suggest that you described as option 3 (using an environment variable and an option, where the environment variable takes precedence). However, there is a fourth option: remove all unit-test-framework dependent functions from checkmate, and create deliberately tiny packages which extend a given unit test package. E.g., you could introduce checkmate.testthat and checkmate.tinytest. |
Removing the expectation from checkmate would break quite some reverse dependencies so that the transition would take some months. Might still be worth it, though. |
The big gains would be that 1) checkmate itself would be totally independent from the unit testing frameworks, 2) it would be pretty easy to create extension packages as new test frameworks arise, 3) all expectation functions could have the same names in each extension package without any further machinery. As for the transition: I find the data.table-way pretty compelling. |
@mllg I need to test it but I think I can set a variable for you within R. Tinytest runs all expressions in a test file in a fresh R |
Added in 31ead00 and b04df1c. Needs testing and probably still contains bugs, but I've verified that it does not break anything existing, including reverse suggests. I would be grateful if you could kick the tyres a little with something simple (if not no problem of course). You can install the current dev version with: (note: I do not put .Rd files in the repo as they are generated by git clone https://github.com/markvanderloo/tinytest
cd tinytest
make install The API is described in ?register_tinytest_extension |
|
I decided that having separate packages for the expectations is the better solution in the long run. I've transfered the I created a similar package for |
Fixed I'm going to build a small extension package that I will use for testing but it will also serve as an example. Will not get to that until next week. Had a quick look at your package, seems to register everything right. As said, I have not actually run anything yet with an extension package yet but it should work (famous last words :-) ). Also, currently the API does not overwrite existing functions -- functions loaded earlier currently take precedence. That should change to 'functions added later take precedence (like in R)'. |
Now done in 8664bf9. Some notes:
Full spec in Closing this issue now. |
By the way, as a token of my gratitude for your suggestion and feedback, you have been immortalized in the NEWS file ;-). |
Everything seems to work now. Thanks! |
Well, I discovered some issues now:
|
I have solved issue 1 in markvanderloo/uses.tinytest.extension@291ab9e and markvanderloo/uses.tinytest.extension@ec5462b. Running Regarding issue 2, the link points to your repo, not to an example. One thing to keep in mind is that passing tests are recorded but not printed by default. You can print passes by saving the test output, Cheers for reporting, as always. |
Sorry, the link was indeed not helpful. I meant to point here: https://github.com/mllg/checkmate.tinytest/blob/master/inst/tinytest/test_cm.R. I'm unsure how to point a more isolated example for the following issue:
Note that I have 5 tests in the referenced file: 3 calling |
Thanks, fixed in 5592c36. There was some real subtle stuff going on with (lazy) eval. |
This is part of version 1.0.0 on CRAN, so closing now. |
My package checkmate extends
testthat
with > 40expect_*
functions, and I'm looking into doing something similar for tinytest. I would need a possibility to write custom expectations, but AFAICT this is currently not possible.Are there any plans to support custom expectations, or to customize the message (
testthat
hadlabel
andinfo
for that)?The text was updated successfully, but these errors were encountered: