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

Verify the target is given correctly to method invocations #1651

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/extensions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -899,21 +899,21 @@ class I extends AbstractMethodInterceptor { I(def s) {} }

// On SpecInfo
specInfo.addSharedInitializerInterceptor new I('shared initializer')
specInfo.sharedInitializerMethod?.addInterceptor new I('shared initializer method')
specInfo.allSharedInitializerMethods*.addInterceptor new I('shared initializer method')
specInfo.addInterceptor new I('specification')
specInfo.addSetupSpecInterceptor new I('setup spec')
specInfo.setupSpecMethods*.addInterceptor new I('setup spec method')
specInfo.allSetupSpecMethods*.addInterceptor new I('setup spec method')
specInfo.allFeatures*.addInterceptor new I('feature')
specInfo.addInitializerInterceptor new I('initializer')
specInfo.initializerMethod?.addInterceptor new I('initializer method')
specInfo.allInitializerMethods*.addInterceptor new I('initializer method')
specInfo.allFeatures*.addIterationInterceptor new I('iteration')
specInfo.addSetupInterceptor new I('setup')
specInfo.setupMethods*.addInterceptor new I('setup method')
specInfo.allSetupMethods*.addInterceptor new I('setup method')
specInfo.allFeatures*.featureMethod*.addInterceptor new I('feature method')
specInfo.addCleanupInterceptor new I('cleanup')
specInfo.cleanupMethods*.addInterceptor new I('cleanup method')
specInfo.allCleanupMethods*.addInterceptor new I('cleanup method')
specInfo.addCleanupSpecInterceptor new I('cleanup spec')
specInfo.cleanupSpecMethods*.addInterceptor new I('cleanup spec method')
specInfo.allCleanupSpecMethods*.addInterceptor new I('cleanup spec method')
specInfo.allFixtureMethods*.addInterceptor new I('fixture method')

// on FeatureInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.spockframework.runtime;

import org.opentest4j.TestAbortedException;
import org.spockframework.runtime.model.FeatureInfo;
import org.spockframework.util.ExceptionUtil;
import spock.config.RunnerConfiguration;

import org.junit.platform.engine.*;

import java.util.concurrent.atomic.AtomicReference;

/**
* A non-parametric feature (test) that only has a single "iteration".
* Contrary to parametric tests - where the iterations are the children - this is the actual test. The execution
Expand All @@ -29,62 +33,34 @@ public Type getType() {

@Override
public SpockExecutionContext prepare(SpockExecutionContext context) throws Exception {
return delegate.prepare(
context.withCurrentFeature(getNodeInfo())
//.withParentId(getUniqueId())
);
}

@Override
public SpockExecutionContext before(SpockExecutionContext context) throws Exception {
context = super.before(context);
ErrorInfoCollector errorInfoCollector = new ErrorInfoCollector();
context = context.withErrorInfoCollector(errorInfoCollector);
context.getRunner().runSetup(context);
errorInfoCollector.assertEmpty();

return context;
}

@Override
public void around(SpockExecutionContext context, Invocation<SpockExecutionContext> invocation) {
// Wrap the Feature invocation around the invocation of the Iteration delegate
super.around(context, ctx -> delegate.around(ctx, invocation));
context = super.prepare(context);
return context.withCurrentFeature(getNodeInfo());
}

@Override
public SpockExecutionContext execute(SpockExecutionContext context, DynamicTestExecutor dynamicTestExecutor) throws Exception {
verifyNotSkipped(getNodeInfo());
delegate.execute(context, dynamicTestExecutor);
return context;
}

@Override
public void after(SpockExecutionContext context) throws Exception {
ErrorInfoCollector errorInfoCollector = new ErrorInfoCollector();
context = context.withErrorInfoCollector(errorInfoCollector);
delegate.after(context);
// First the iteration node, then the Feature node
errorInfoCollector.assertEmpty();
super.after(context);
}

@Override
public void nodeFinished(SpockExecutionContext context, TestDescriptor testDescriptor, TestExecutionResult result) {
delegate.nodeFinished(context, testDescriptor, result);
super.nodeFinished(context, testDescriptor, result);
}

@Override
public void nodeSkipped(SpockExecutionContext context, TestDescriptor testDescriptor, SkipResult result) {
// Skipping this Feature implies that the Iteration is also skipped
delegate.nodeSkipped(context, testDescriptor, result);
super.nodeSkipped(context, testDescriptor, result);
}

@Override
public SkipResult shouldBeSkipped(SpockExecutionContext context) throws Exception {
return delegate.shouldBeSkipped(context);
AtomicReference<Throwable> result = new AtomicReference<>();
EngineExecutionListener executionListener = new EngineExecutionListener() {
@Override
public void executionSkipped(TestDescriptor testDescriptor, String reason) {
result.set(new TestAbortedException(reason));
}

@Override
public void executionFinished(TestDescriptor testDescriptor, TestExecutionResult testExecutionResult) {
testExecutionResult.getThrowable().ifPresent(result::set);
}
};

addChild(delegate);
dynamicTestExecutor.execute(delegate, executionListener);
dynamicTestExecutor.awaitFinished();

if (result.get() != null) {
ExceptionUtil.sneakyThrow(result.get());
}
return context;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ public MethodInfo getInitializerMethod() {
return initializerMethod;
}

public Iterable<MethodInfo> getAllInitializerMethods() {
if (superSpec == null) return CollectionUtil.listOf(getInitializerMethod());

return CollectionUtil.concat(superSpec.getAllInitializerMethods(), CollectionUtil.listOf(getInitializerMethod()));
}

public void setInitializerMethod(MethodInfo initializerMethod) {
this.initializerMethod = initializerMethod;
}
Expand All @@ -176,6 +182,12 @@ public MethodInfo getSharedInitializerMethod() {
return sharedInitializerMethod;
}

public Iterable<MethodInfo> getAllSharedInitializerMethods() {
if (superSpec == null) return CollectionUtil.listOf(getSharedInitializerMethod());

return CollectionUtil.concat(superSpec.getAllSharedInitializerMethods(), CollectionUtil.listOf(getSharedInitializerMethod()));
}

public void setSharedInitializerMethod(MethodInfo sharedInitializerMethod) {
this.sharedInitializerMethod = sharedInitializerMethod;
}
Expand All @@ -184,6 +196,12 @@ public List<MethodInfo> getSetupMethods() {
return setupMethods;
}

public Iterable<MethodInfo> getAllSetupMethods() {
if (superSpec == null) return getSetupMethods();

return CollectionUtil.concat(superSpec.getAllSetupMethods(), getSetupMethods());
}

public void addSetupMethod(MethodInfo setupMethod) {
setupMethods.add(setupMethod);
}
Expand All @@ -192,6 +210,12 @@ public List<MethodInfo> getCleanupMethods() {
return cleanupMethods;
}

public Iterable<MethodInfo> getAllCleanupMethods() {
if (superSpec == null) return getCleanupMethods();

return CollectionUtil.concat(superSpec.getAllCleanupMethods(), getCleanupMethods());
}

public void addCleanupMethod(MethodInfo cleanupMethod) {
cleanupMethods.add(cleanupMethod);
}
Expand All @@ -200,6 +224,12 @@ public List<MethodInfo> getSetupSpecMethods() {
return setupSpecMethods;
}

public Iterable<MethodInfo> getAllSetupSpecMethods() {
if (superSpec == null) return getSetupSpecMethods();

return CollectionUtil.concat(superSpec.getAllSetupSpecMethods(), getSetupSpecMethods());
}

public void addSetupSpecMethod(MethodInfo setupSpecMethod) {
setupSpecMethods.add(setupSpecMethod);
}
Expand All @@ -208,6 +238,12 @@ public List<MethodInfo> getCleanupSpecMethods() {
return cleanupSpecMethods;
}

public Iterable<MethodInfo> getAllCleanupSpecMethods() {
if (superSpec == null) return getCleanupSpecMethods();

return CollectionUtil.concat(superSpec.getAllCleanupSpecMethods(), getCleanupSpecMethods());
}

public void addCleanupSpecMethod(MethodInfo cleanupSpecMethod) {
cleanupSpecMethods.add(cleanupSpecMethod);
}
Expand Down
Loading