You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is reasonable for users of testworks to want to be able to create their own assetions so that they can perform a custom check and, if it fails, a nice error message that is informative.
This would replace something like:
definefunctionstatic-type-check?(lambda :: <&method>,
expected-type :: <type-estimate-values>)
=> (stc :: <boolean>)
// Useful thing to put in the body of a test: infer the return values// of lambda, and ask if they match expected-type.localmethod final-computation-type(c :: <&method>)
// What is the type of the final computation? (I.e., the return.)let cache = make(<type-cache>);
type-estimate-in-cache(c, cache); // fill cache w/types
type-estimate-in-cache(final-computation(body(c)), cache) // just the last guyend;
let found-type = final-computation-type(lambda);
if (type-estimate=?(expected-type, found-type))
#telsewhen (*static-type-check?-verbose?*)
// Sometimes you want a diagnostic for the failure cases.
dynamic-bind (*print-method-bodies?* = #t)
format-out("\nFor %=:\nExpected type: %=\n Inferred type: %=\n\n",
lambda, expected-type, found-type)
endend;
#fendend;
definemacrotypist-inference-test-definer// Define manual compiler test & remember the name in typist inference registry
{ define typist-inference-test ?test-name:name
?subtests
end }
=> {
define test ?test-name ()
with-testing-context (#f)
?subtests
endend }
subtests:
// ;-separated test specs expand into a conjunction of test results
{ } => { }
{ ?subtest; ... } => { ?subtest ... }
subtest:
// Wrap with try ... end and hand off to static-type-check? to match// against the values specification.
{ } => { }
{ ?:expression TYPE: ?val:* }
=> { assert-true(static-type-check?(compile-to-method(?expression),
make(<type-estimate-values>, ?val))); }
end;
We don't want to just know if the test was returning #t or #f. We want to know if one value as type-estimate=? with the other, and if not, a useful error message that gives both values.
The text was updated successfully, but these errors were encountered:
I think there's nothing preventing someone from writing their own assert-type-estimate= macro that does the complicated test and then ends up calling either assert-true(#t) or assert-true(#f, "what the test was and the reason it failed"). Am I misunderstanding the request?
(We should definitely make a fail("reason") function if we don't have one already.)
It is reasonable for users of testworks to want to be able to create their own assetions so that they can perform a custom check and, if it fails, a nice error message that is informative.
This would replace something like:
We don't want to just know if the test was returning
#t
or#f
. We want to know if one value astype-estimate=?
with the other, and if not, a useful error message that gives both values.The text was updated successfully, but these errors were encountered: