Package com.oracle.truffle.tck
Class TruffleRunner.RunWithPolyglotRule
java.lang.Object
com.oracle.truffle.tck.TruffleRunner.RunWithPolyglotRule
- All Implemented Interfaces:
org.junit.rules.TestRule
- Enclosing class:
TruffleRunner
public static final class TruffleRunner.RunWithPolyglotRule
extends Object
implements org.junit.rules.TestRule
JUnit rule to run the tests in the context of a polyglot engine. This can be used as a
ClassRule or as a Rule.
If used as ClassRule, a single context is created for all unit tests in this class,
and all tests (and also other methods like BeforeClass, Before After
and AfterClass) are executed in this context.
If used as Rule, a new context is created for each unit test. The Before and
After actions are also executed in this context. No context is available in the
BeforeClass and AfterClass methods.
- Since:
- 0.27
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.junit.runners.model.Statementapply(org.junit.runners.model.Statement stmt, org.junit.runner.Description description) Internal method used by the JUnit framework.org.graalvm.polyglot.ContextGet the currentContext.com.oracle.truffle.api.TruffleLanguage<?> Get an instance of theTruffleLanguagethat this test is running under.com.oracle.truffle.api.TruffleLanguage.EnvGet an environment to access the polyglot engine using interop.
-
Constructor Details
-
RunWithPolyglotRule
public RunWithPolyglotRule()- Since:
- 0.27
-
RunWithPolyglotRule
public RunWithPolyglotRule(org.graalvm.polyglot.Context.Builder contextBuilder) - Parameters:
contextBuilder- a custom context builder- Since:
- 19.0
-
-
Method Details
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement stmt, org.junit.runner.Description description) Internal method used by the JUnit framework. Do not call directly.- Specified by:
applyin interfaceorg.junit.rules.TestRule- Since:
- 0.27
-
getPolyglotContext
public org.graalvm.polyglot.Context getPolyglotContext()Get the currentContext. This should only be called from code that is executed by theTruffleRunner. In particular, this method can not be called from static initializers and constructors of test classes. UseBeforeorBeforeClassmethods instead, or put the initialization code into the constructor of theRootNodeof the test.- Since:
- 0.27
-
getTruffleTestEnv
public com.oracle.truffle.api.TruffleLanguage.Env getTruffleTestEnv()Get an environment to access the polyglot engine using interop. This can be used to run setup tasks, and to do mock interop access into the polyglot engine. This should only be called from code that is executed by theTruffleRunner. In particular, this method can not be called from static initializers and constructors of test classes. UseBeforeorBeforeClassmethods instead, or put the initialization code into the constructor of theRootNodeof the test.- Since:
- 0.27
-
getTestLanguage
public com.oracle.truffle.api.TruffleLanguage<?> getTestLanguage()Get an instance of theTruffleLanguagethat this test is running under. Nodes that are used withTruffleRunner.Injectshould pass this instance to their super constructor.- Since:
- 21.1
-