-
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
Fix compile error with single explicit assert in switch expression branch (#1845) #2033
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2033 +/- ##
============================================
+ Coverage 80.44% 81.81% +1.36%
- Complexity 4337 4614 +277
============================================
Files 441 448 +7
Lines 13534 14468 +934
Branches 1707 1831 +124
============================================
+ Hits 10888 11837 +949
+ Misses 2008 1954 -54
- Partials 638 677 +39 ☔ View full report in Codecov by Sentry. |
f07a139
to
80f423c
Compare
if (!(code instanceof BlockStatement)) { | ||
BlockStatement block = new BlockStatement(); | ||
block.addStatement(code); | ||
expr.setCode(block); |
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.
Strange that the code block is marked as not covered, is there a test case missing?
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.
Hm, strange, shouldn't. That test below should exactly trigger this two times.
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.
Ah, of course.
It is covered, as the tests are compiled using the production code.
But that compilation does not have coverage tracking enabled.
To get the coverage with the current setup, it must use the embedded spec compiler so that the rewriter is triggered during test runtime, not during test compile-time.
@leonard84 do you think - generally - we should get the test compilation to also record coverage data would probably make sense? Not necessarily in this PR, but probably in a separate one. Should be something like using groovyOptions.forkOptions.jvmArgs
to attach the JaCoCo agent and then also submitting that to Codecov.
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.
If I'm not mistaken it should already do that.
spock/spock-specs/specs.gradle
Lines 96 to 101 in f214a8a
tasks.named("compileTestGroovy", GroovyCompile) { | |
def jacocoAgent = objects.newInstance(JacocoJavaagentProvider) | |
jacocoAgent.jacocoAgent.fileProvider(provider { file(configurations.jacocoAgentRuntime.asPath) }) | |
jacocoAgent.execResultFile = layout.buildDirectory.file("jacoco/compileTestGroovy.exec") | |
groovyOptions.forkOptions.jvmArgumentProviders.add(jacocoAgent) | |
} |
@@ -13,4 +13,14 @@ class ConditionG4Spec extends Specification { | |||
(0..<5) == [0, 1, 2, 3, 4] | |||
(0<..<5) == [1, 2, 3, 4] | |||
} | |||
|
|||
@Issue("https://github.com/spockframework/spock/issues/1845") | |||
def "explicit assert in switch expression"() { |
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 about adding examples for the other assertions switch variants?
@@ -149,6 +149,12 @@ public final void visitClosureExpression(ClosureExpression expr) { | |||
currSpecialMethodCall = NoSpecialMethodCall.INSTANCE; // unrelated closure terminates currSpecialMethodCall scope | |||
} | |||
try { | |||
Statement code = expr.getCode(); | |||
if (!(code instanceof BlockStatement)) { |
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 think this deserves a comment.
Fixes #1845