-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -149,6 +149,12 @@ | |||||||||||||
currSpecialMethodCall = NoSpecialMethodCall.INSTANCE; // unrelated closure terminates currSpecialMethodCall scope | ||||||||||||||
} | ||||||||||||||
try { | ||||||||||||||
Statement code = expr.getCode(); | ||||||||||||||
if (!(code instanceof BlockStatement)) { | ||||||||||||||
BlockStatement block = new BlockStatement(); | ||||||||||||||
block.addStatement(code); | ||||||||||||||
expr.setCode(block); | ||||||||||||||
Check warning on line 156 in spock-core/src/main/java/org/spockframework/compiler/AbstractDeepBlockRewriter.java Codecov / codecov/patchspock-core/src/main/java/org/spockframework/compiler/AbstractDeepBlockRewriter.java#L154-L156
|
||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Ah, of course. @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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||||||||
} | ||||||||||||||
doVisitClosureExpression(expr); | ||||||||||||||
} finally { | ||||||||||||||
currClosure = oldClosure; | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. What about adding examples for the other assertions switch variants? |
||
expect: | ||
def b = 3 | ||
!!switch (b) { | ||
case 3 -> assert 1 == 1 | ||
default -> assert 1 == 1 | ||
} | ||
} | ||
} |
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.