-
Notifications
You must be signed in to change notification settings - Fork 471
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
Groovy 3 compatibility #1075
Groovy 3 compatibility #1075
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1075 +/- ##
============================================
- Coverage 74.02% 73.99% -0.03%
- Complexity 3437 3445 +8
============================================
Files 383 385 +2
Lines 10630 10657 +27
Branches 1297 1301 +4
============================================
+ Hits 7869 7886 +17
- Misses 2299 2309 +10
Partials 462 462
Continue to review full report at Codecov.
|
The error has nothing to do with my changes. Btw. I'm curious, is there a reason you used |
@Vampire I just said that you added those tests which started to fail after switch to Groovy 3 and therefore, I suspected, you might be more situation oriented than me. But if you are not, and you don't want to face the challenge, I can understand that ;-). Btw, having your PR merged day or two later would cause it to fail before merge (or right after) ;-).
The only reason is that I notoriously forget about that extension :). I changed it in some places, thanks for you suggestion. |
spock-core/src/main/java/org/spockframework/compat/groovy2/GroovyCodeVisitorCompat.java
Outdated
Show resolved
Hide resolved
//Groovy 3 started to call go.getProperty("x") method instead of go.getX() directly for go.x | ||
Throwable throwable = new Throwable(); | ||
StackTraceElement mockCaller = throwable.getStackTrace()[3]; | ||
if (!("groovy.lang.GroovyObject$getProperty".equals(mockCaller.getClassName()) && "call".equals(mockCaller.getMethodName()))) { |
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.
Please include a //HACK:
regarding scanning the stacktrace, and maybe extend the if with a isGroovy3()
check
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.
There is a similar - already existing - "hack" with a stacktrace a few lines above for setProperty()
. I should mark it as well in that case.
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.
I overslept that case and - even it seems to work also for Groovy 2 - I agree it would be good to included isGroovy3()
runtime check for that "hack". It will minimize a chance for regression for Groovy 2 and will allow us to release 2.0-M2 with more confidence.
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.
Hmm, it turned out that the following fails with Groovy 2 and with 1.3-groovy-2.5:
def "can stub property access"() {
Person person = Stub(Person)
person.getName() >> "fred"
expect:
person.name == "fred"
person.getProperty("name") == "fred" //fails with 1.3-groovy-2.5 and 2.0-M1-groovy-2.5
}
It doesn't seem to be often used if wasn't reported, so I may left it as it for Groovy 2.5.
However, for Groovy 3 my change is needed to have even:
person.name == "fred"
passing. And along the way it fixes person.getProperty("name") == "fred"
.
Concluding, I keep the changes only for Groovy 3, waiting for some better idea to determine that in on the Groovy side (before 2.0-final is released).
spock-core/src/main/java/org/spockframework/runtime/GroovyRuntimeUtil.java
Show resolved
Hide resolved
...k-specs/src/test/groovy/org/spockframework/groovy/SourcePositionPhaseSemanticAnalysis.groovy
Outdated
Show resolved
Hide resolved
spock-specs/src/test/groovy/org/spockframework/smoke/AnonymousInnerClasses.groovy
Outdated
Show resolved
Hide resolved
spock-core/src/main/java/org/spockframework/runtime/GroovyRuntimeUtil.java
Show resolved
Hide resolved
6278da3
to
f4f93dc
Compare
To detect problems and know how problematic it will be. Compiling, but with several broken tests.
Class-based stubs.
Different exceptions in Groovy 2 and 3 are thrown.
Power assertions in Groovy 3 renders resolved values at the beginning of the expression, not in the middle of it.
Column reporting was enhanced in Groovy 3.
+= and -= are allowed in Groovy 3.0-rc2, but it should considered before 3.0-final. See https://issues.apache.org/jira/browse/GROOVY-9360 and the linked discussion. Spock's tests should adjusted to it.
It fixed mock.getProperty("foo") stubbing while preserving previous fix for property access to stubbed getters in Groovy 3.
The one related to constructor declaration. The implementation of SpecParser.constructorMayHaveBeenAddedByCompiler no longer detect specification constructor and should be enhanced to support Groovy 3. As it is not a critical bug I postponed it to work on building the same Spock code base with Groovy 2 and 3.
Those are two new tests, emerged after rebasing against master. To be reviewed and fixed.
Added compatibility layer and conditional module inclusion to keep codebase compilable (and buildable) with both Groovy 2.5 and 3.0.
Workaround on: junit-team/junit5#1909
To detect compatibility problems faster.
Groovy script execution line in stacktrace format has changed since RC2: script15791055931181262955476.groovy:3 -> Script_eb303fa8835e8a0c4ec6558372940b3d.groovy:3
Fixed meanwhile in a separate branch.
Summary
This pull request provides expermental Spock compatibility (compilation + tests) with Groovy 3.
In addition the Groovy 2.5 compatibility is kept. There are 2 variants available known from the previous Spock versions. There is a compatibility layer to cover breaking changes in Groovy 3.
The builds pass on Travis with Groovy 3.0 and 2.5 variants on supported range of Java versions.
Known issues/limitations (to be fixed - or acknowledged - before merge):
@NamedParam
annotation, dummy classesLambdaExpression
andMethodReferenceExpression
have to be on runtime classpath with Groovy 2.5 (they are used as method arguments). It brings a runtime risk ifgroovy:3.x
andspock-groovy2-compat:2.x-groovy-2.5
artifacts are accidentally mixed in one project (however, I don't know if we can do it another way).Recently merged tests in- adjusted to Groovy 3 by @VampireAnonymousInnerClasses
(Fix anonymous inner classes #1027) fails with Groovy 3 - @Vampire, you are up-to-date with the changes, maybe you would like to take a look at it?- fixed by @Vampire.CompileTimeErrorReporting."constructor declaration"
test fails with Groovy 3 - the implementation ofSpecParser.constructorMayHaveBeenAddedByCompiler()
has to be improved. It's not a critical issue, so temporarily skipped it to finish making codebase cross-compatible. Contribution with that is welcome. - diagnosed by @Vampire, tracked in GROOVY-9360Long term known issues (to be fixed before 2.0-final is released in separate PRs):
+=
and-=
in assertions (e.g.assert i += 2
). This is not compatible with Groovy 2 and Spock's assumptions. I reported it GROOVY-9360 and most likely it would be reverted before 2.0-finalupdate to Groovy 3.0-final once released- upgradedOther issues/ideas:
JavaStubs
tests could be rewritten to parameterized tests to test both interface and class-based stubsOther remarks
It is recommended to merge this pull request WITHOUT squashing, to keep the original commit separation. They contain extra information about incompatibilities and, in addition, would be easier to selectively revert something, if needed.
Feel free to comment and propose possible improvements!
This change is