Search in sources :

Example 1 with ResultVerifier

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

the class IdentityFunctionTest method createIdentitySnippet.

static Snippet createIdentitySnippet(String lang) {
    LanguageProvider tli = context.getInstalledProviders().get(lang);
    Value value = tli.createIdentityFunction(context.getContext());
    if (!value.canExecute()) {
        throw new AssertionError(String.format("Result of createIdentityFunction for tck provider %s did not return an executable value. Returned value '%s'.", lang, value));
    }
    return (Snippet.newBuilder("identity", tli.createIdentityFunction(context.getContext()), ANY).parameterTypes(ANY).resultVerifier(new ResultVerifier() {

        public void accept(SnippetRun snippetRun) throws PolyglotException {
            final PolyglotException exception = snippetRun.getException();
            if (exception != null) {
                throw exception;
            }
            Value parameter = snippetRun.getParameters().get(0);
            TypeDescriptor parameterType = TypeDescriptor.forValue(parameter);
            TypeDescriptor resultType = TypeDescriptor.forValue(snippetRun.getResult());
            if (!resultType.isAssignable(parameterType) || !resultType.isAssignable(resultType)) {
                throw new AssertionError(String.format("Identity function return type must parameter type. Expected %s got %s.", parameterType, resultType));
            }
        }
    }).build());
}
Also used : LanguageProvider(org.graalvm.polyglot.tck.LanguageProvider) ResultVerifier(org.graalvm.polyglot.tck.ResultVerifier) TypeDescriptor(org.graalvm.polyglot.tck.TypeDescriptor) Value(org.graalvm.polyglot.Value) PolyglotException(org.graalvm.polyglot.PolyglotException)

Example 2 with ResultVerifier

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

the class TestUtil method validateResult.

static void validateResult(final TestRun testRun, final Value result, final PolyglotException exception) {
    ResultVerifier verifier = testRun.getSnippet().getResultVerifier();
    validateResult(verifier, testRun, result, exception);
}
Also used : ResultVerifier(org.graalvm.polyglot.tck.ResultVerifier)

Aggregations

ResultVerifier (org.graalvm.polyglot.tck.ResultVerifier)2 PolyglotException (org.graalvm.polyglot.PolyglotException)1 Value (org.graalvm.polyglot.Value)1 LanguageProvider (org.graalvm.polyglot.tck.LanguageProvider)1 TypeDescriptor (org.graalvm.polyglot.tck.TypeDescriptor)1