Fix @Verify and @VerifyAll method compilation (#2150)#2249
Conversation
|
This hopefully fixes the mess with the |
b2573a5 to
08fc4f2
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2249 +/- ##
============================================
+ Coverage 82.07% 82.13% +0.05%
- Complexity 4754 4786 +32
============================================
Files 465 468 +3
Lines 14872 14942 +70
Branches 1877 1888 +11
============================================
+ Hits 12206 12272 +66
- Misses 1978 1983 +5
+ Partials 688 687 -1
🚀 New features to boost your workflow:
|
8e468bd to
2c088e9
Compare
spock-specs/src/test/groovy/org/spockframework/smoke/VerifyMethodsSpecification.groovy
Show resolved
Hide resolved
...moke/ast/condition/VerifyAllMethodsAstSpec/interactions_are_illegal_in_verify_methods.groovy
Outdated
Show resolved
Hide resolved
spock-core/src/main/java/org/spockframework/compiler/DeepBlockRewriter.java
Show resolved
Hide resolved
spock-core/src/main/java/org/spockframework/compiler/SpecParser.java
Outdated
Show resolved
Hide resolved
spock-core/src/main/java/org/spockframework/compiler/SpecParser.java
Outdated
Show resolved
Hide resolved
spock-core/src/main/java/org/spockframework/compiler/condition/BaseVerifyMethodTransform.java
Outdated
Show resolved
Hide resolved
spock-core/src/main/java/org/spockframework/compiler/condition/VerifyMethodRewriter.java
Outdated
Show resolved
Hide resolved
...specs/src/test/groovy/org/spockframework/smoke/ast/condition/BaseVerifyMethodsAstSpec.groovy
Outdated
Show resolved
Hide resolved
...specs/src/test/groovy/org/spockframework/smoke/ast/condition/BaseVerifyMethodsAstSpec.groovy
Outdated
Show resolved
Hide resolved
|
|
||
| Block getCurrentBlock(); | ||
|
|
||
| VariableExpression captureOldValue(Expression oldValue); |
There was a problem hiding this comment.
These don't apply outside of a spec, though.
There was a problem hiding this comment.
That's correct for captureOldValue and getMockInvocationMatcher, but I wanted to reuse the DeepBlockRewriter as it does exactly what we want and trying to reimplement part of its logic is exactly why the current state is as broken as it is. The DeepBlockRewriter needs those and I didn't want to rip apart the whole DeepBlockRewriter into two halves.
For the non-spec method case, these just throw UnsupportedOperationException and return null respectiviely, which is fine, as the code paths in the DeepBlockRewriter that call these methods can never be hit from those verify method transforms, as captureOldValue can only be triggered from then: block and getMockInvocationMatcher is only called in feature methods and on rewriting interactions, which are now explicitly forbidden in those verification methods just like in expect blocks.
Another possibility would be to have them in a sub-interface and make an instance-of check and cast in the DeepBlockRewriter, but I thought this solution is better and also more performant.
There was a problem hiding this comment.
Shouldn't we at least use a more useful error message in that case, i.e., that it is only supported by SpecRewriter/ within a Specification?
There was a problem hiding this comment.
For whom?
If the error happens, it is a Spock implementation bug.
The user is not able to trigger this error from a verification method.
If this is ever changed - which is pretty unlikely - then this spot will most probably be adapted anyway.
There was a problem hiding this comment.
Ok, I changed it to throw new UnsupportedOperationException("This should only be called when processing a then-block"); for the old-case.
For the mock invocation matcher I didn't because I lied. :-)
That I did not already throw an UOE there is, because it does get called, but then the result is ignored in case of a VerifyBlock.
And the order cannot be swapped, because the result is used for an up-front check whether it is an interaction at all, before then complaining that you must not have one in expect or verify.
...specs/src/test/groovy/org/spockframework/smoke/ast/condition/BaseVerifyMethodsAstSpec.groovy
Outdated
Show resolved
Hide resolved
...moke/ast/condition/VerifyAllMethodsAstSpec/interactions_are_illegal_in_verify_methods.groovy
Outdated
Show resolved
Hide resolved
...ondition/VerifyAllMethodsAstSpec/transforms_conditions_in_methods_inside_spec_classes.groovy
Outdated
Show resolved
Hide resolved
2c088e9 to
d50dcb4
Compare
d50dcb4 to
3c71a10
Compare
...specs/src/test/groovy/org/spockframework/smoke/ast/condition/BaseVerifyMethodsAstSpec.groovy
Show resolved
Hide resolved
3c71a10 to
aaa0262
Compare
aaa0262 to
02f92a8
Compare

Fixes #2150