Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Vampire
Copy link
Member

@Vampire Vampire commented Oct 29, 2024

Fixes #1845

Copy link

codecov bot commented Oct 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.81%. Comparing base (2c7db77) to head (983f794).
Report is 174 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

@Vampire Vampire force-pushed the issue-1845 branch 8 times, most recently from f07a139 to 80f423c Compare November 5, 2024 13:43
if (!(code instanceof BlockStatement)) {
BlockStatement block = new BlockStatement();
block.addStatement(code);
expr.setCode(block);
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

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.

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"() {
Copy link
Member

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)) {
Copy link
Member

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.

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.

Assertions in Switch Expressions lead to compiler error
3 participants