Search in sources :

Example 1 with InlineSnippet

use of org.graalvm.polyglot.tck.InlineSnippet in project graal by oracle.

the class InlineExecutionTest method createScriptTests.

@Parameterized.Parameters(name = "{0}")
public static Collection<InlineTestRun> createScriptTests() {
    context = new TestContext();
    final Collection<InlineTestRun> res = new LinkedHashSet<>();
    for (String lang : TestUtil.getRequiredLanguages(context)) {
        for (InlineSnippet snippet : context.getInlineScripts(lang)) {
            res.add(new InlineTestRun(new AbstractMap.SimpleImmutableEntry<>(lang, snippet.getScript()), snippet));
        }
    }
    return res;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InlineSnippet(org.graalvm.polyglot.tck.InlineSnippet)

Example 2 with InlineSnippet

use of org.graalvm.polyglot.tck.InlineSnippet in project graal by oracle.

the class InlineExecutionTest method testInline.

@Test
public void testInline() throws Exception {
    Assume.assumeThat(testRun, TEST_RESULT_MATCHER);
    boolean success = false;
    InlineSnippet inlineSnippet = testRun.getInlineSnippet();
    TestResultVerifier verifier;
    if (testRun.getInlineSnippet().getResultVerifier() != null) {
        verifier = new TestResultVerifier();
    } else {
        verifier = null;
    }
    context.getContext().initialize(testRun.getID());
    context.setInlineSnippet(testRun.getID(), inlineSnippet, verifier);
    try {
        try {
            final Value result = testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray());
            TestUtil.validateResult(testRun, result, null);
            success = true;
        } catch (PolyglotException pe) {
            TestUtil.validateResult(testRun, null, pe);
            success = true;
        }
        if (verifier != null && verifier.exception != null) {
            success = false;
            throw verifier.exception;
        }
    } finally {
        context.setInlineSnippet(null, null, null);
        TEST_RESULT_MATCHER.accept(new AbstractMap.SimpleImmutableEntry<>(testRun, success));
    }
}
Also used : AbstractMap(java.util.AbstractMap) InlineSnippet(org.graalvm.polyglot.tck.InlineSnippet) Value(org.graalvm.polyglot.Value) PolyglotException(org.graalvm.polyglot.PolyglotException) Test(org.junit.Test)

Aggregations

InlineSnippet (org.graalvm.polyglot.tck.InlineSnippet)2 AbstractMap (java.util.AbstractMap)1 LinkedHashSet (java.util.LinkedHashSet)1 PolyglotException (org.graalvm.polyglot.PolyglotException)1 Value (org.graalvm.polyglot.Value)1 Test (org.junit.Test)1