-
Notifications
You must be signed in to change notification settings - Fork 140
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
Fix test matcher #2130
Fix test matcher #2130
Conversation
matcherTestFunctionType, | ||
matcherTestFieldType, |
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.
Fix: Create a function that has the type of the Matcher.test
field, ((AnyStruct): Bool)
, so the initialization of the field in Matcher.init
works.
staticType, ok := testFunc.StaticType(inter).(interpreter.FunctionStaticType) | ||
if !ok { | ||
typeParameterPair := invocation.TypeParameterTypes.Oldest() | ||
if typeParameterPair == nil { | ||
panic(errors.NewUnreachableError()) | ||
} | ||
|
||
parameters := staticType.Type.Parameters | ||
parameterType := typeParameterPair.Value |
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.
Fix: Use the type argument for type parameter T
of Test.newMatcher<T>
: The wrapper should check if the run-time type of argument passed to the test function (Matcher.test
has type ((AnyStruct): Bool)
) matches the type argument T
Codecov Report
@@ Coverage Diff @@
## feature/stable-cadence #2130 +/- ##
==========================================================
+ Coverage 78.00% 78.19% +0.18%
==========================================================
Files 306 306
Lines 64158 64209 +51
==========================================================
+ Hits 50047 50207 +160
+ Misses 12352 12226 -126
- Partials 1759 1776 +17
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Cadence Benchstat comparisonThis branch with compared with the base branch onflow:feature/stable-cadence commit 2d42211 Collapsed results for better readability
|
staticType, ok := testFunc.StaticType(inter).(interpreter.FunctionStaticType) | ||
if !ok { | ||
typeParameterPair := invocation.TypeParameterTypes.Oldest() | ||
if typeParameterPair == nil { |
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.
What happens if the type parameter is not provided? does it still get resolved and would be not-nil?
e.g: newMatcher(fun (_ value: AnyStruct): Bool { ... }
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.
Correct!
For example, here's a test case for it https://github.com/onflow/cadence/pull/2130/files#diff-74ad93a1435e307865ff8474567598f410879038788126ec263e27c9244edf98R152-R154 (already existed, was just moved from the test framework to the Cadence repo in #2129)
The invocation gets the types from the elaboration, we keep them there for each invocation, and type parameters bindings are inferred from uses (here, the parameter of the test function expression passed to newMatcher
).
Depends on #2129
Description
In #2125 I broke the test matcher function, but did not realize at the time, as tests are located in the
cadence-tools
repo, so only realized when updating the test framework to Stable Cadence.In #2129 I moved some of the tests to Cadence to avoid similar breakage in the future.
When merged into Stable Cadence, the tests fail, showing the test framework is broken, the creation and invocation of matchers results in erroneous run-time type mismatch errors.
This PR fixes the matcher creation and invocation.
master
branchFiles changed
in the Github PR explorer