-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
Feature request: infer additional check info for function calls #149
Comments
Sounds like a good idea but check-equal? outside of test-case should stay the same. Please. |
Maybe this feature would be good to add as a different name initially that worked anywhere ( |
Why? Not against the idea, just wondering if there's a specific problem you have in mind. |
My thought is that the behavior of the error message and the available information becomes fragile depending on the syntax at each use case. In comparison, I would feel less surprised if the API has a new name, perhaps with syntax (check-app/infer-name f x1 x2 ... xn <expected>) Additionally, this syntax could enclose the application with an exception handler. |
Just curious, doesn't your |
If it's a new name, it's pretty much useless, since I'll never remember to use it. Besides there's other places it would be nice, like |
It does, but after using |
I am just asking for backwards compatibility, the usual Racket guideline. So
```
(module+ test
(check-equal? (f 1 2 3) 4) )
```
should not change functional behavior though an improvement in effects (printing additional information) is okay.
|
Sure. My point is not against adding inferred information, but such inference should be uniform. In the best scenario, there should be no extra rules to demand the user memorize and write checks in a particular form just to obtain the extra information. I'd be happy if the error message is something like For example, if I temporary change Here is another thought. Given that those variables are defined locally, what if |
Functional behavior there would be the same, yes. |
The expression isn't what's useful. The expression you can see by looking at the code, it's the value that you can't see. I don't think users will have to memorize anything. This is a best-effort feature. If a user wants a guarantee that some check info will be included in the error message, they can still use
I think it's only useful to report argument info when 1) there's an obvious name to use and 2) the exact literal value passed in isn't obvious looking at the check expression. I posit that there should be this behavior:
This would be nice too. I'm less sure on the details of this, because I have test cases like this: (test-case "some-function"
(define input (setup-input ...))
(test-case "case one"
(define other-input ...)
(check-equal? (some-function input other-input) ...))
(test-case "case two"
(define other-input ...)
(check-equal? (some-function input other-input) ...))) ...and these can nest quite deep, and some test cases might not use every local variable defined in the outer test case. Maybe only the innermost test cases matter? And maybe only for test cases that span a handful of lines? I'm far less confident making assertions about what's helpful here. |
I see! If it's not a rigid syntax match |
I threw together a little proof of concept of this. There is still some space for abstracting out how to wrap the existing checks. Also things like Does this look like the right approach to this feature? https://gist.github.com/samdphillips/913a65998067967fb17c7fd567f01df8 |
@samdphillips That looks about right, although I actually recommend against adding info for expressions in the "expected" position. Focusing on the "actual" position seems like a better approach since the expected position is usually just literal data anyway. Showing too much info will dilute its value. |
There should be some check that the head of the s-expression isn't a special identifier, something like:
This could be improved by cooperating with the contract system, and possibly cooperating with other macros that are guaranteed to play well as functions, but this is at least a good conservative starting point. |
Thanks @AlexKnauth. In a project where I was exploring this idea more I (very grossly) used @jackfirth That seems reasonable. I think it may tidy up the implementation a bit too. |
I have a lot of tests that look like this:
When this fails, I'll see an error message like this:
In DrRacket this isn't so bad since the source location info lets me jump to the failing check and see that
order
is(customer-order #:price 10.00)
. But when running tests from the terminal, the failure message doesn't give very much information.I propose changing
check-equal?
(and perhaps other checks) to recognize when theactual
expression is a "simple" function call and add check infos for the arguments automatically. So a test like this:Should produce failures like this:
That is, for any check of the form
(check-equal? (function:id arg:id ...) expected:expr)
, eacharg
value should be added to the check info stack under the name'arg
.The text was updated successfully, but these errors were encountered: