Skip to content

Commit

Permalink
Move current block clearing to PlatformSpecRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
leonard84 committed Apr 28, 2024
1 parent 7b972d5 commit e0c19c7
Show file tree
Hide file tree
Showing 24 changed files with 275 additions and 442 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,6 @@ public void visitMethodAgain(Method method) {
if (methodHasDeepNonGroupedCondition) {
defineErrorRethrower(method.getStatements());
}

if (method instanceof FeatureMethod)
clearCurrentBlockOnExit(method.getStatements());
}


Expand Down Expand Up @@ -604,22 +601,6 @@ private TryCatchStatement createCleanupTryCatch(CleanupBlock block, VariableExpr
return tryCatchStat;
}

// Wraps the feature method in a try-finally to clear the current block on exit.
private void clearCurrentBlockOnExit(List<Statement> statements) {
MethodCallExpression setCurrentBlockToNull = createDirectMethodCall(new ClassExpression(nodeCache.SpockRuntime),
nodeCache.SpockRuntime_ClearCurrentBlock, new ArgumentListExpression(getSpecificationContext()));

List<Statement> innerStatements = new ArrayList<>(statements);

TryCatchStatement tryCatchStat =
new TryCatchStatement(
new BlockStatement(innerStatements, null),
new ExpressionStatement(setCurrentBlockToNull));

statements.clear();
statements.add(tryCatchStat);
}

private CatchStatement createThrowableAssignmentAndRethrowCatchStatement(VariableExpression assignmentVar) {
Parameter catchParameter = new Parameter(nodeCache.Throwable, SPOCK_TMP_THROWABLE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ void runFeatureMethod(SpockExecutionContext context) {

Object[] dataValues = context.getCurrentIteration().getDataValues();
invoke(context, context.getCurrentInstance(), featureIteration, dataValues);
getSpecificationContext(context).setCurrentBlock(null);
}

void runCleanup(SpockExecutionContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ where: x << []
then:
result.source == '''\
public void $spock_feature_0_0(java.lang.Object dataPipe, java.lang.Object dataVariable) {
try {
this.getSpecificationContext().getMockController().leaveScope()
}
finally {
org.spockframework.runtime.SpockRuntime.clearCurrentBlock(this.getSpecificationContext())}
this.getSpecificationContext().getMockController().leaveScope()
}
public java.lang.Object $spock_feature_0_0prov0() {
Expand Down Expand Up @@ -167,11 +163,7 @@ public java.lang.Object $spock_feature_0_0proc(java.lang.Object $spock_p0) {
then:
result.source == '''\
public void $spock_feature_0_0(java.lang.Object dataPipe, java.lang.Object dataVariable) {
try {
this.getSpecificationContext().getMockController().leaveScope()
}
finally {
org.spockframework.runtime.SpockRuntime.clearCurrentBlock(this.getSpecificationContext())}
this.getSpecificationContext().getMockController().leaveScope()
}
public java.lang.Object $spock_feature_0_0prov0() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
TRYCATCHBLOCK L4 L5 L5 java/lang/Throwable
TRYCATCHBLOCK L4 L5 L6 null
TRYCATCHBLOCK L5 L7 L6 null
TRYCATCHBLOCK L8 L9 L10 null
L11
L8
NOP
INVOKESTATIC apackage/TestSpec.$getCallSiteArray ()[Lorg/codehaus/groovy/runtime/callsite/CallSite;
ASTORE 1
L8
ALOAD 1
LDC 0
AALOAD
Expand All @@ -27,7 +25,7 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
INVOKESTATIC org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType (Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
CHECKCAST org/spockframework/runtime/ErrorCollector
ASTORE 2
L12
L9
ALOAD 2
POP
ALOAD 1
Expand All @@ -39,7 +37,7 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
INVOKESTATIC org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType (Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
CHECKCAST org/spockframework/runtime/ValueRecorder
ASTORE 3
L13
L10
ALOAD 3
POP
ALOAD 0
Expand Down Expand Up @@ -85,11 +83,11 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
INVOKESTATIC org/spockframework/runtime/SpockRuntime.verifyCondition (Lorg/spockframework/runtime/ErrorCollector;Lorg/spockframework/runtime/ValueRecorder;Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V
ACONST_NULL
POP
GOTO L14
GOTO L11
L1
FRAME FULL [apackage/TestSpec [Lorg/codehaus/groovy/runtime/callsite/CallSite; org/spockframework/runtime/ErrorCollector org/spockframework/runtime/ValueRecorder] [java/lang/Throwable]
ASTORE 4
L15
L12
ALOAD 2
ALOAD 3
LDC "true"
Expand All @@ -102,16 +100,16 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
POP
NOP
L3
GOTO L14
L14
GOTO L11
L11
FRAME SAME
GOTO L16
GOTO L13
L2
FRAME SAME1 java/lang/Throwable
ASTORE 5
ALOAD 5
ATHROW
L16
L13
FRAME SAME
ALOAD 0
INVOKEVIRTUAL org/spockframework/lang/SpecInternals.getSpecificationContext ()Lorg/spockframework/lang/ISpecificationContext;
Expand Down Expand Up @@ -177,11 +175,11 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
LINENUMBER 6 L4
ICONST_1
POP
GOTO L17
GOTO L14
L5
FRAME SAME1 java/lang/Throwable
ASTORE 6
L18
L15
ALOAD 0
INVOKEVIRTUAL org/spockframework/lang/SpecInternals.getSpecificationContext ()Lorg/spockframework/lang/ISpecificationContext;
LDC Lorg/spockframework/runtime/SpecificationContext;.class
Expand All @@ -193,16 +191,16 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
POP
NOP
L7
GOTO L17
L17
GOTO L14
L14
FRAME SAME
GOTO L19
GOTO L16
L6
FRAME SAME1 java/lang/Throwable
ASTORE 7
ALOAD 7
ATHROW
L19
L16
FRAME SAME
ALOAD 0
INVOKEVIRTUAL org/spockframework/lang/SpecInternals.getSpecificationContext ()Lorg/spockframework/lang/ISpecificationContext;
Expand Down Expand Up @@ -252,8 +250,8 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
INVOKESTATIC org/spockframework/runtime/SpockRuntime.callEnterBlock (Lorg/spockframework/runtime/SpecificationContext;Lorg/spockframework/runtime/model/BlockInfo;)V
ACONST_NULL
POP
L20
LINENUMBER 8 L20
L17
LINENUMBER 8 L17
ALOAD 1
LDC 12
AALOAD
Expand Down Expand Up @@ -299,40 +297,13 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
INVOKEVIRTUAL org/spockframework/mock/runtime/MockController.leaveScope ()V
ACONST_NULL
POP
L21
GOTO L9
L9
FRAME SAME
ALOAD 0
INVOKEVIRTUAL org/spockframework/lang/SpecInternals.getSpecificationContext ()Lorg/spockframework/lang/ISpecificationContext;
LDC Lorg/spockframework/runtime/SpecificationContext;.class
INVOKESTATIC org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType (Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
CHECKCAST org/spockframework/runtime/SpecificationContext
INVOKESTATIC org/spockframework/runtime/SpockRuntime.clearCurrentBlock (Lorg/spockframework/runtime/SpecificationContext;)V
ACONST_NULL
POP
GOTO L22
L10
FRAME FULL [apackage/TestSpec [Lorg/codehaus/groovy/runtime/callsite/CallSite;] [java/lang/Throwable]
ASTORE 8
ALOAD 0
INVOKEVIRTUAL org/spockframework/lang/SpecInternals.getSpecificationContext ()Lorg/spockframework/lang/ISpecificationContext;
LDC Lorg/spockframework/runtime/SpecificationContext;.class
INVOKESTATIC org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType (Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
CHECKCAST org/spockframework/runtime/SpecificationContext
INVOKESTATIC org/spockframework/runtime/SpockRuntime.clearCurrentBlock (Lorg/spockframework/runtime/SpecificationContext;)V
ACONST_NULL
POP
ALOAD 8
ATHROW
L22
FRAME APPEND [org/spockframework/runtime/ErrorCollector org/spockframework/runtime/ValueRecorder]
L18
RETURN
LOCALVARIABLE this Lapackage/TestSpec; L11 L22 0
LOCALVARIABLE $spock_errorCollector Lorg/spockframework/runtime/ErrorCollector; L12 L21 2
LOCALVARIABLE $spock_valueRecorder Lorg/spockframework/runtime/ValueRecorder; L13 L21 3
LOCALVARIABLE $spock_condition_throwable Ljava/lang/Throwable; L15 L3 4
LOCALVARIABLE $spock_ex Ljava/lang/Throwable; L18 L7 6
LOCALVARIABLE this Lapackage/TestSpec; L8 L18 0
LOCALVARIABLE $spock_errorCollector Lorg/spockframework/runtime/ErrorCollector; L9 L18 2
LOCALVARIABLE $spock_valueRecorder Lorg/spockframework/runtime/ValueRecorder; L10 L18 3
LOCALVARIABLE $spock_condition_throwable Ljava/lang/Throwable; L12 L3 4
LOCALVARIABLE $spock_ex Ljava/lang/Throwable; L15 L7 6
MAXSTACK = 9
MAXLOCALS = 9
MAXLOCALS = 8
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
TRYCATCHBLOCK L4 L5 L5 java/lang/Throwable
TRYCATCHBLOCK L4 L5 L6 null
TRYCATCHBLOCK L5 L7 L6 null
TRYCATCHBLOCK L8 L9 L10 null
L8
LDC Lorg/spockframework/runtime/ErrorRethrower;.class
INVOKEDYNAMIC getProperty(Ljava/lang/Class;)Ljava/lang/Object; [
Expand All @@ -30,7 +29,7 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
0
]
ASTORE 1
L11
L9
ALOAD 1
POP
LDC Lorg/spockframework/runtime/ValueRecorder;.class
Expand All @@ -49,7 +48,7 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
0
]
ASTORE 2
L12
L10
ALOAD 2
POP
ALOAD 0
Expand Down Expand Up @@ -109,11 +108,11 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
INVOKESTATIC org/spockframework/runtime/SpockRuntime.verifyCondition (Lorg/spockframework/runtime/ErrorCollector;Lorg/spockframework/runtime/ValueRecorder;Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V
ACONST_NULL
POP
GOTO L13
GOTO L11
L1
FRAME FULL [apackage/TestSpec org/spockframework/runtime/ErrorCollector org/spockframework/runtime/ValueRecorder] [java/lang/Throwable]
ASTORE 3
L14
L12
ALOAD 1
ALOAD 2
LDC "true"
Expand All @@ -126,16 +125,16 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
POP
NOP
L3
GOTO L13
L13
GOTO L11
L11
FRAME SAME
GOTO L15
GOTO L13
L2
FRAME SAME1 java/lang/Throwable
ASTORE 4
ALOAD 4
ATHROW
L15
L13
FRAME SAME
ALOAD 0
INVOKEVIRTUAL org/spockframework/lang/SpecInternals.getSpecificationContext ()Lorg/spockframework/lang/ISpecificationContext;
Expand Down Expand Up @@ -230,11 +229,11 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
LINENUMBER 6 L4
ICONST_1
POP
GOTO L16
GOTO L14
L5
FRAME SAME1 java/lang/Throwable
ASTORE 5
L17
L15
ALOAD 0
INVOKEVIRTUAL org/spockframework/lang/SpecInternals.getSpecificationContext ()Lorg/spockframework/lang/ISpecificationContext;
INVOKEDYNAMIC cast(Lorg/spockframework/lang/ISpecificationContext;)Lorg/spockframework/runtime/SpecificationContext; [
Expand All @@ -250,16 +249,16 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
POP
NOP
L7
GOTO L16
L16
GOTO L14
L14
FRAME SAME
GOTO L18
GOTO L16
L6
FRAME SAME1 java/lang/Throwable
ASTORE 6
ALOAD 6
ATHROW
L18
L16
FRAME SAME
ALOAD 0
INVOKEVIRTUAL org/spockframework/lang/SpecInternals.getSpecificationContext ()Lorg/spockframework/lang/ISpecificationContext;
Expand Down Expand Up @@ -337,8 +336,8 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
INVOKESTATIC org/spockframework/runtime/SpockRuntime.callEnterBlock (Lorg/spockframework/runtime/SpecificationContext;Lorg/spockframework/runtime/model/BlockInfo;)V
ACONST_NULL
POP
L19
LINENUMBER 8 L19
L17
LINENUMBER 8 L17
ALOAD 0
ACONST_NULL
ACONST_NULL
Expand Down Expand Up @@ -409,49 +408,14 @@ public class apackage/TestSpec extends spock/lang/Specification implements groov
INVOKEVIRTUAL org/spockframework/mock/runtime/MockController.leaveScope ()V
ACONST_NULL
POP
L20
GOTO L9
L9
FRAME SAME
ALOAD 0
INVOKEVIRTUAL org/spockframework/lang/SpecInternals.getSpecificationContext ()Lorg/spockframework/lang/ISpecificationContext;
INVOKEDYNAMIC cast(Lorg/spockframework/lang/ISpecificationContext;)Lorg/spockframework/runtime/SpecificationContext; [
// handle kind 0x6 : INVOKESTATIC
org/codehaus/groovy/vmplugin/v8/IndyInterface.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;I)Ljava/lang/invoke/CallSite;
// arguments:
"()",
0
]
INVOKESTATIC org/spockframework/runtime/SpockRuntime.clearCurrentBlock (Lorg/spockframework/runtime/SpecificationContext;)V
ACONST_NULL
POP
GOTO L21
L10
FRAME FULL [apackage/TestSpec] [java/lang/Throwable]
ASTORE 7
ALOAD 0
INVOKEVIRTUAL org/spockframework/lang/SpecInternals.getSpecificationContext ()Lorg/spockframework/lang/ISpecificationContext;
INVOKEDYNAMIC cast(Lorg/spockframework/lang/ISpecificationContext;)Lorg/spockframework/runtime/SpecificationContext; [
// handle kind 0x6 : INVOKESTATIC
org/codehaus/groovy/vmplugin/v8/IndyInterface.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;I)Ljava/lang/invoke/CallSite;
// arguments:
"()",
0
]
INVOKESTATIC org/spockframework/runtime/SpockRuntime.clearCurrentBlock (Lorg/spockframework/runtime/SpecificationContext;)V
ACONST_NULL
POP
ALOAD 7
ATHROW
L21
LINENUMBER 9 L21
FRAME APPEND [org/spockframework/runtime/ErrorCollector org/spockframework/runtime/ValueRecorder]
L18
LINENUMBER 9 L18
RETURN
LOCALVARIABLE this Lapackage/TestSpec; L8 L21 0
LOCALVARIABLE $spock_errorCollector Lorg/spockframework/runtime/ErrorCollector; L11 L20 1
LOCALVARIABLE $spock_valueRecorder Lorg/spockframework/runtime/ValueRecorder; L12 L20 2
LOCALVARIABLE $spock_condition_throwable Ljava/lang/Throwable; L14 L3 3
LOCALVARIABLE $spock_ex Ljava/lang/Throwable; L17 L7 5
LOCALVARIABLE this Lapackage/TestSpec; L8 L18 0
LOCALVARIABLE $spock_errorCollector Lorg/spockframework/runtime/ErrorCollector; L9 L18 1
LOCALVARIABLE $spock_valueRecorder Lorg/spockframework/runtime/ValueRecorder; L10 L18 2
LOCALVARIABLE $spock_condition_throwable Ljava/lang/Throwable; L12 L3 3
LOCALVARIABLE $spock_ex Ljava/lang/Throwable; L15 L7 5
MAXSTACK = 9
MAXLOCALS = 8
MAXLOCALS = 7
}
Loading

0 comments on commit e0c19c7

Please sign in to comment.