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
    Constructor
    Description
     
    RunWithPolyglotRule(org.graalvm.polyglot.Context.Builder contextBuilder)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.junit.runners.model.Statement
    apply(org.junit.runners.model.Statement stmt, org.junit.runner.Description description)
    Internal method used by the JUnit framework.
    org.graalvm.polyglot.Context
    Get the current Context.
    com.oracle.truffle.api.TruffleLanguage<?>
    Get an instance of the TruffleLanguage that this test is running under.
    com.oracle.truffle.api.TruffleLanguage.Env
    Get an environment to access the polyglot engine using interop.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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:
      apply in interface org.junit.rules.TestRule
      Since:
      0.27
    • getPolyglotContext

      public org.graalvm.polyglot.Context getPolyglotContext()
      Get the current Context. This should only be called from code that is executed by the TruffleRunner. In particular, this method can not be called from static initializers and constructors of test classes. Use Before or BeforeClass methods instead, or put the initialization code into the constructor of the RootNode of 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 the TruffleRunner. In particular, this method can not be called from static initializers and constructors of test classes. Use Before or BeforeClass methods instead, or put the initialization code into the constructor of the RootNode of the test.
      Since:
      0.27
    • getTestLanguage

      public com.oracle.truffle.api.TruffleLanguage<?> getTestLanguage()
      Get an instance of the TruffleLanguage that this test is running under. Nodes that are used with TruffleRunner.Inject should pass this instance to their super constructor.
      Since:
      21.1