Skip to content

Conversation

@Vampire
Copy link
Member

@Vampire Vampire commented Oct 9, 2025

This removes relying on Groovy being able to call package-private methods in other-package subclasses, which does not work anymore with Groovy 5.

Copy link
Member Author

Vampire commented Oct 9, 2025

@leonard84
Copy link
Member

leonard84 commented Oct 10, 2025

What are the implications of using a mixin?

Copy link
Member Author

Vampire commented Oct 10, 2025

The question is why the mock integration tests work differently.

But the intention of this is to prepare for the Groovy 5 PR.

By using the mixin (or a trait but there the method overload resolution is buggy unless we name the methods uniquely), we can bring in the spec internals methods at runtime.
This way the rewritten code can call them without the user seeing them in the code completion.

Up to now this was done by ensuring the methods are package-private, but Groovy 5 lost the ability to call them in that case.
Hence I searched for a replacement tactic and the mixin is what I came up with.

Except that it for some reason does not yet work in the mock integration tests and I have no idea yet why.

@leonard84
Copy link
Member

leonard84 commented Oct 10, 2025

Couldn't/Shouldn't we just generate static method calls to SpecialMethodCallTarget? I'm leery of using Groovy MOP if we don't have to.

Copy link
Member Author

Vampire commented Oct 10, 2025

Actually, that was my first try.
But I did not make it too far.
Iirc it involved also making createStaticMock public and keeping the three create mock calls also in the specification and adding the specification or the specification context as first parameter to all methods in the remaining methods.

Afair the main problem was how to properly transform the instance method call to a static method call.
Currently (and with this PR) we just have to append Impl to the method name of the method call expression.
Or how to properly replace the old expression with the new one, especially in SpecialMethodCall where only the expression is present.

Another alternative would be to generate all those ...Impl methods into the compiled specification and either there have the implementation directly or from there make the static method call. But I don't think I like that idea. :-D

Copy link
Member Author

Vampire commented Oct 10, 2025

Yeah, I think the main problem was how to replace the method call expression with a static method call expression.
I guess we would need to use a ExpressionReplacingVisitorSupport somehow.
Unfortunately it was added but never used anywhere, so I'm unsure how to properly replace the expression.
Do you know how to do it, then I'd give it another go with patching in static method calls.

Copy link
Member Author

Vampire commented Oct 13, 2025

I have no idea which minor detail I did differently this time, but trying again it worked just fine to simply use a class expression as object expression for the method call expression to get a static call as result. 🤷‍♂️

So now no MOP, but static calls.

@Vampire Vampire changed the title Move spec internals methods to a mixin Move spec internals methods to be static method calls Oct 13, 2025
@Vampire Vampire changed the base branch from master to graphite-base/2209 October 14, 2025 15:38
@Vampire Vampire force-pushed the vampire/mixin-spec-internals branch from 21bbf96 to e84ff52 Compare October 14, 2025 15:38
@Vampire Vampire changed the base branch from graphite-base/2209 to vampire/use-snapshot-id October 14, 2025 15:38
Base automatically changed from vampire/use-snapshot-id to master October 19, 2025 10:38
@Vampire Vampire force-pushed the vampire/mixin-spec-internals branch 2 times, most recently from 4f2ad96 to 74371ac Compare October 20, 2025 17:03
@codecov
Copy link

codecov bot commented Oct 20, 2025

Codecov Report

❌ Patch coverage is 88.28829% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.93%. Comparing base (3493297) to head (098924f).

Files with missing lines Patch % Lines
...java/org/spockframework/runtime/SpecInternals.java 86.59% 12 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2209   +/-   ##
=========================================
  Coverage     81.92%   81.93%           
+ Complexity     4732     4728    -4     
=========================================
  Files           463      463           
  Lines         14764    14768    +4     
  Branches       1869     1869           
=========================================
+ Hits          12096    12100    +4     
  Misses         1980     1980           
  Partials        688      688           
Files with missing lines Coverage Δ
...java/org/spockframework/compiler/AstNodeCache.java 100.00% <100.00%> (ø)
...org/spockframework/compiler/DeepBlockRewriter.java 98.19% <100.00%> (+0.01%) ⬆️
...java/org/spockframework/compiler/SpecRewriter.java 93.76% <ø> (ø)
...org/spockframework/compiler/SpecialMethodCall.java 93.63% <100.00%> (+0.17%) ⬆️
.../org/spockframework/mock/EmptyOrDummyResponse.java 86.58% <100.00%> (ø)
...k-core/src/main/java/spock/lang/Specification.java 79.16% <100.00%> (+0.90%) ⬆️
...pock-core/src/main/java/spock/mock/MockingApi.java 93.65% <100.00%> (ø)
...java/org/spockframework/runtime/SpecInternals.java 86.59% <86.59%> (ø)
🚀 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/mixin-spec-internals branch from 74371ac to 098924f Compare October 21, 2025 09:42
@Vampire Vampire requested a review from AndreasTu October 21, 2025 09:43
@Vampire Vampire force-pushed the vampire/mixin-spec-internals branch from 098924f to 5288e91 Compare October 21, 2025 15:43
@Vampire Vampire requested a review from AndreasTu October 21, 2025 15:43
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!

@AndreasTu AndreasTu enabled auto-merge (squash) October 21, 2025 16:47
@Vampire Vampire force-pushed the vampire/mixin-spec-internals branch from ae5de84 to 10be65b Compare October 21, 2025 16:57
@AndreasTu AndreasTu merged commit f0f60ab into master Oct 21, 2025
50 checks passed
@AndreasTu AndreasTu deleted the vampire/mixin-spec-internals branch October 21, 2025 18:00
@Vampire Vampire added this to the 2.4-M7 milestone Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants