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());
}
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);
}
Aggregations