Package com.oracle.truffle.tck
Class TruffleRunner.ParametersFactory
java.lang.Object
com.oracle.truffle.tck.TruffleRunner.ParametersFactory
- All Implemented Interfaces:
org.junit.runners.parameterized.ParametersRunnerFactory
- Enclosing class:
TruffleRunner
public static final class TruffleRunner.ParametersFactory
extends Object
implements org.junit.runners.parameterized.ParametersRunnerFactory
ParametersRunnerFactory for testing Truffle AST interpreters using
Parameterized unit tests. To use the parameters for constructing the test AST, the
test RootNode constructor may take the test class as single argument, or
alternatively the test RootNode can be a non-static inner class of the test class.
@RunWith(Parameterized.class)
@UseParametersRunnerFactory(TruffleRunner.ParametersFactory.class)
public static class ParameterizedTest {
@Parameters(name = "{0}, {1}")
public static Collection<Object[]> data() {
ArrayList<Object[]> ret = new ArrayList<>();
ret.add(new Object[]{5, "test"});
ret.add(new Object[]{-3, "asdf"});
return ret;
}
@Parameter(0) int intParam;
@Parameter(1) String stringParam;
public class TestConstArgNode extends RootNode {
private final int iArg;
private final String sArg;
@Child InteropLibrary interop;
public TestConstArgNode() {
super(null);
this.iArg = intParam;
this.sArg = stringParam;
}
@Override
public Object execute(VirtualFrame frame) {
TruffleObject obj = (TruffleObject) frame.getArguments()[0];
try {
return interop.execute(obj, iArg, sArg);
} catch (InteropException ex) {
CompilerDirectives.transferToInterpreter();
Assert.fail(ex.getMessage());
return null;
}
}
}
@Test
public void constArg(@Inject(TestConstArgNode.class) CallTarget target) {
TruffleObject arg = prepareArgumentValue();
Object ret = target.call(arg);
Assert.assertEquals(expectedRetValue(), ret);
}
}
- Since:
- 0.25
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.junit.runner.RunnercreateRunnerForTestWithParameters(org.junit.runners.parameterized.TestWithParameters test) Internal method used by the JUnit framework.
-
Constructor Details
-
ParametersFactory
public ParametersFactory()Should not be called directly. To use this class, annotate your test class with@Parameterized.UseParametersRunnerFactory(TruffleRunner.ParametersFactory.class).- Since:
- 0.25
- See Also:
-
-
Method Details
-
createRunnerForTestWithParameters
public org.junit.runner.Runner createRunnerForTestWithParameters(org.junit.runners.parameterized.TestWithParameters test) throws org.junit.runners.model.InitializationError Internal method used by the JUnit framework. Do not call directly.- Specified by:
createRunnerForTestWithParametersin interfaceorg.junit.runners.parameterized.ParametersRunnerFactory- Throws:
org.junit.runners.model.InitializationError- Since:
- 0.25
-