Skip to content

Fix @Verify and @VerifyAll method compilation (#2150)#2249

Merged
leonard84 merged 6 commits intomasterfrom
vampire/fix-verify-methods
Nov 23, 2025
Merged

Fix @Verify and @VerifyAll method compilation (#2150)#2249
leonard84 merged 6 commits intomasterfrom
vampire/fix-verify-methods

Conversation

@Vampire
Copy link
Member

@Vampire Vampire commented Oct 29, 2025

Fixes #2150

Copy link
Member Author

Vampire commented Oct 29, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Member Author

Vampire commented Oct 29, 2025

This hopefully fixes the mess with the @Verify and @VerifyAll methods

@Vampire Vampire force-pushed the vampire/fix-verify-methods branch 2 times, most recently from b2573a5 to 08fc4f2 Compare October 29, 2025 04:14
@codecov
Copy link

codecov bot commented Oct 29, 2025

Codecov Report

❌ Patch coverage is 95.72650% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.13%. Comparing base (158e2e4) to head (4a031cd).

Files with missing lines Patch % Lines
...kframework/compiler/AbstractDeepBlockRewriter.java 50.00% 2 Missing ⚠️
.../spockframework/compiler/model/BlockParseInfo.java 50.00% 2 Missing ⚠️
...r/condition/DefaultConditionRewriterResources.java 80.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             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     
Files with missing lines Coverage Δ
...g/spockframework/compiler/AbstractSpecVisitor.java 68.75% <100.00%> (+2.08%) ⬆️
...java/org/spockframework/compiler/AstNodeCache.java 100.00% <100.00%> (ø)
...org/spockframework/compiler/DeepBlockRewriter.java 98.24% <100.00%> (+0.05%) ⬆️
...g/spockframework/compiler/InteractionRewriter.java 91.79% <100.00%> (ø)
...n/java/org/spockframework/compiler/SpecParser.java 95.38% <100.00%> (+0.64%) ⬆️
...java/org/spockframework/compiler/SpecRewriter.java 94.17% <100.00%> (+0.41%) ⬆️
...org/spockframework/compiler/SpecialMethodCall.java 93.80% <100.00%> (+0.11%) ⬆️
...va/org/spockframework/compiler/SpockTransform.java 86.95% <100.00%> (ø)
...rg/spockframework/compiler/WhereBlockRewriter.java 94.77% <100.00%> (ø)
...k/compiler/condition/BaseVerifyMethodRewriter.java 100.00% <100.00%> (ø)
... and 11 more

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Vampire Vampire force-pushed the vampire/fix-verify-methods branch 2 times, most recently from 8e468bd to 2c088e9 Compare October 29, 2025 10:00

Block getCurrentBlock();

VariableExpression captureOldValue(Expression oldValue);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't apply outside of a spec, though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future us 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@leonard84 leonard84 added this to the 2.4-M7 milestone Nov 8, 2025
@Vampire Vampire force-pushed the vampire/fix-verify-methods branch from 2c088e9 to d50dcb4 Compare November 9, 2025 22:58
@Vampire Vampire force-pushed the vampire/fix-verify-methods branch from d50dcb4 to 3c71a10 Compare November 10, 2025 00:20
@Vampire Vampire force-pushed the vampire/fix-verify-methods branch from 3c71a10 to aaa0262 Compare November 14, 2025 01:39
@Vampire Vampire force-pushed the vampire/fix-verify-methods branch from aaa0262 to 02f92a8 Compare November 18, 2025 22:51
@Vampire Vampire requested a review from AndreasTu November 18, 2025 22:52
AndreasTu
AndreasTu previously approved these changes Nov 18, 2025
Copy link
Member

@AndreasTu AndreasTu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Thank you.

leonard84
leonard84 previously approved these changes Nov 23, 2025
@leonard84 leonard84 enabled auto-merge (squash) November 23, 2025 16:54
@leonard84 leonard84 merged commit 5f4d8c3 into master Nov 23, 2025
65 checks passed
@leonard84 leonard84 deleted the vampire/fix-verify-methods branch November 23, 2025 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Verify blows up with groovy.lang.MissingPropertyException

3 participants

Comments