Skip to content

Commit 03b1d6c

Browse files
authored
Fix too many arguments set as data values in iteration info (#1690)
The iteration info holds a list of the data values for the current iteration. The data driver logic had an error where it gave all parameter infos to the data driver instead of only the ones representing data variables. Data drivers only deal with data variables, not with additional arguments that are supplied by extensions. Due to that the data values in the iteration info had additional MISSING_ARGUMENT entries for the additional arguments which then also broke things like unroll patterns, conditional annotations accessing data values and so on
1 parent 55503c3 commit 03b1d6c

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

spock-core/src/main/java/org/spockframework/runtime/PlatformParameterizedSpecRunner.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void runParameterizedFeature(SpockExecutionContext context, ParameterizedFeature
4444
try (IDataIterator dataIterator = new DataIteratorFactory(supervisor).createFeatureDataIterator(context)) {
4545
IIterationRunner iterationRunner = createIterationRunner(context, childExecutor);
4646
IDataDriver dataDriver = feature.getDataDriver();
47-
dataDriver.runIterations(dataIterator, iterationRunner, feature.getFeatureMethod().getParameters());
47+
dataDriver.runIterations(dataIterator, iterationRunner, feature.getFeatureMethod().getParameters().subList(0, feature.getDataVariables().size()));
4848
childExecutor.awaitFinished();
4949
} catch (InterruptedException ie) {
5050
throw ie;
@@ -58,9 +58,9 @@ private IIterationRunner createIterationRunner(SpockExecutionContext context, Pa
5858
private final AtomicInteger iterationIndex = new AtomicInteger(0);
5959

6060
@Override
61-
public CompletableFuture<ExecutionResult> runIteration(Object[] args, int estimatedNumIterations) {
61+
public CompletableFuture<ExecutionResult> runIteration(Object[] dataValues, int estimatedNumIterations) {
6262
int currIterationIndex = iterationIndex.getAndIncrement();
63-
IterationInfo iterationInfo = createIterationInfo(context, currIterationIndex, args, estimatedNumIterations);
63+
IterationInfo iterationInfo = createIterationInfo(context, currIterationIndex, dataValues, estimatedNumIterations);
6464
IterationNode iterationNode = new IterationNode(
6565
context.getParentId().append("iteration", String.valueOf(currIterationIndex)),
6666
context.getRunContext().getConfiguration(RunnerConfiguration.class), iterationInfo);

spock-core/src/main/java/org/spockframework/runtime/extension/IDataDriver.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ public interface IDataDriver {
5050
*
5151
* @param dataIterator the data iterator giving access to the data from the data providers. The data iterator is not to be closed by this method.
5252
* @param iterationRunner the iteration runner that will be used to run the test method for each iteration.
53-
* @param parameters the parameters of the test method
53+
* @param parameters the parameters of the test method representing data variables
5454
*/
5555
void runIterations(IDataIterator dataIterator, IIterationRunner iterationRunner, List<ParameterInfo> parameters);
5656

5757
/**
58-
* Prepares the arguments for invocation of the test method.
58+
* Prepares the arguments for the data variables for invocation of the test method.
5959
* <p>
60-
* It is possible to have fewer arguments produced by the data driver than the number of parameters.
60+
* It is possible to have fewer arguments produced by the data driver than the number of data variables.
6161
* In this case, the missing arguments are filled with {@link MethodInfo#MISSING_ARGUMENT}.
6262
* <p>
6363
* Custom implementations of IDataDriver should use this method to prepare the argument array.

spock-core/src/main/java/org/spockframework/runtime/extension/builtin/RepeatUntilFailureExtension.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public void runIterations(IDataIterator dataIterator, IIterationRunner iteration
3636
List<Object[]> data = new ArrayList<>(estimatedNumIterations);
3737
dataIterator.forEachRemaining(data::add);
3838
for (int attempt = 0; attempt < maxAttempts; attempt++) {
39-
for (Object[] args : data) {
39+
for (Object[] dataValues : data) {
4040
try {
41-
ExecutionResult executionResult = iterationRunner.runIteration(args, maxIterations).get();
41+
ExecutionResult executionResult = iterationRunner.runIteration(dataValues, maxIterations).get();
4242
if (executionResult == ExecutionResult.FAILED) {
4343
return;
4444
}

spock-specs/src/test/groovy/org/spockframework/smoke/parameterization/MethodParameters.groovy

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import org.spockframework.EmbeddedSpecification
2121
import org.spockframework.runtime.SpockExecutionException
2222
import org.spockframework.runtime.extension.ExtensionAnnotation
2323
import org.spockframework.runtime.extension.IAnnotationDrivenExtension
24+
import org.spockframework.runtime.model.FeatureInfo
2425
import org.spockframework.runtime.model.MethodInfo
25-
import org.spockframework.runtime.model.MethodKind
2626
import spock.lang.Issue
2727
import spock.lang.Rollup
2828
import spock.lang.Unroll
@@ -256,6 +256,28 @@ def foo() {
256256
]
257257
}
258258

259+
@Foo
260+
def "method arguments in data driven feature methods can be provided by extensions"(a) {
261+
expect:
262+
x == 1
263+
y == 2
264+
a == 'foo'
265+
266+
where:
267+
x = 1
268+
y = 2
269+
}
270+
271+
@Foo
272+
def "additional method arguments do not influence data values in iteration info"(a) {
273+
expect:
274+
specificationContext.currentIteration.dataValues == [1, 2]
275+
276+
where:
277+
x = 1
278+
y = 2
279+
}
280+
259281
static class FooExtension implements IAnnotationDrivenExtension<Foo> {
260282
@Override
261283
void visitFixtureAnnotation(Foo annotation, MethodInfo fixtureMethod) {
@@ -266,6 +288,16 @@ def foo() {
266288
it.proceed()
267289
}
268290
}
291+
292+
@Override
293+
void visitFeatureAnnotation(Foo annotation, FeatureInfo feature) {
294+
feature.featureMethod.addInterceptor {
295+
assert it.arguments.size() == 3
296+
assert it.arguments[2] == MISSING_ARGUMENT
297+
it.arguments[2] = 'foo'
298+
it.proceed()
299+
}
300+
}
269301
}
270302
}
271303

0 commit comments

Comments
 (0)