diff --git a/sdk/src/org.graalvm.polyglot.tck/src/org/graalvm/polyglot/tck/ResultVerifier.java b/sdk/src/org.graalvm.polyglot.tck/src/org/graalvm/polyglot/tck/ResultVerifier.java index 9d9981e5c7d2..291119a9fc73 100644 --- a/sdk/src/org.graalvm.polyglot.tck/src/org/graalvm/polyglot/tck/ResultVerifier.java +++ b/sdk/src/org.graalvm.polyglot.tck/src/org/graalvm/polyglot/tck/ResultVerifier.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -67,8 +67,9 @@ public interface ResultVerifier extends Consumer { * verifier. * * @param snippetRun the snippet execution data. The {@link SnippetRun} provides the actual - * snippet parameters, the execution result or the {@link PolyglotException} thrown - * by the execution. + * snippet parameters, the execution result, or the {@link PolyglotException} thrown + * by the execution. If the snippet execution throws an + * {@link IllegalArgumentException}, it's converted to {@link PolyglotException}. * @throws PolyglotException may propagate the {@link PolyglotException} from the snippetRun * @throws AssertionError may throw an {@link AssertionError} as a result of a verification * @since 0.30 @@ -115,7 +116,10 @@ public Value getResult() { } /** - * Returns the {@link PolyglotException} thrown during snippet execution. + * Returns the {@link PolyglotException} thrown during snippet execution. If the snippet + * execution throws an {@link IllegalArgumentException}, this exception is first converted + * to a {@link PolyglotException}, and the resulting {@link PolyglotException} is provided + * by this method. * * @return the {@link PolyglotException} thrown during the execution or null in case of * successful execution. diff --git a/truffle/CHANGELOG.md b/truffle/CHANGELOG.md index ce7e2fc999db..fa51704ce056 100644 --- a/truffle/CHANGELOG.md +++ b/truffle/CHANGELOG.md @@ -2,6 +2,10 @@ This changelog summarizes major changes between Truffle versions relevant to languages implementors building upon the Truffle framework. The main focus is on APIs exported by Truffle. +## Version 22.3.0 + +* (GR-35797) The [SnippetRun#getException()](https://www.graalvm.org/truffle/javadoc/org/graalvm/polyglot/tck/ResultVerifier.SnippetRun.html#getException--) now provides an `IllegalArgumentException` thrown during the snippet execution. The `IllegalArgumentException` is converted to a `PolyglotException` before it is returned. + ## Version 22.2.0 * GR-33829 Added support on libgraal for caching encoded graphs across Truffle compilations to speedup partial evaluation. The cache is enabled by default and can be enabled/disabled with the `--engine.EncodedGraphCache` option. diff --git a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ErrorTypeTest.java b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ErrorTypeTest.java index 5a73e5a9a40f..99175176a7f8 100644 --- a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ErrorTypeTest.java +++ b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ErrorTypeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -44,6 +44,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -52,7 +53,6 @@ import java.util.Objects; import java.util.Set; import java.util.TreeSet; -import java.util.function.Function; import org.graalvm.polyglot.PolyglotException; import org.junit.BeforeClass; import org.junit.Test; @@ -74,7 +74,7 @@ public class ErrorTypeTest { public static Collection createErrorTypeTests() { context = new TestContext(ErrorTypeTest.class); final Set requiredLanguages = TestUtil.getRequiredLanguages(context); - final Collection testRuns = new TreeSet<>((a, b) -> a.toString().compareTo(b.toString())); + final Collection testRuns = new TreeSet<>(Comparator.comparing(TestRun::toString)); for (String snippetLanguage : requiredLanguages) { Collection snippets = context.getExpressions(null, null, snippetLanguage); Map> overloads = computeOverloads(snippets); @@ -113,7 +113,7 @@ private static void computeSnippets( if (snippetLanguage.equals(parLanguage)) { continue; } - final Collection> valueConstructors = new TreeSet<>((a, b) -> a.getValue().getId().compareTo(b.getValue().getId())); + final Collection> valueConstructors = new TreeSet<>(Comparator.comparing(a -> a.getValue().getId())); for (Snippet valueConstructor : context.getValueConstructors(null, parLanguage)) { valueConstructors.add(new AbstractMap.SimpleImmutableEntry<>(parLanguage, valueConstructor)); } @@ -136,12 +136,7 @@ private static void computeSnippets( private static Map> computeOverloads(final Collection snippets) { final Map> res = new HashMap<>(); for (Snippet snippet : snippets) { - res.computeIfAbsent(snippet.getId(), new Function>() { - @Override - public Collection apply(String id) { - return new ArrayList<>(); - } - }).add(snippet); + res.computeIfAbsent(snippet.getId(), id -> new ArrayList<>()).add(snippet); } return (Map>) (Map) res; } @@ -244,18 +239,24 @@ public void testErrorType() { Assume.assumeThat(testRun, TEST_RESULT_MATCHER); boolean passed = false; try { + PolyglotException polyglotException = null; try { testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray()); - } catch (PolyglotException pe) { + } catch (PolyglotException e) { + polyglotException = e; + } catch (IllegalArgumentException e) { + polyglotException = context.getContext().asValue(e).as(PolyglotException.class); + } + if (polyglotException != null) { try { - TestUtil.validateResult(testRun, null, pe, true); + TestUtil.validateResult(testRun, polyglotException); } catch (PolyglotException | AssertionError e) { - if (pe.equals(e)) { + if (polyglotException.equals(e)) { passed = true; } else { throw new AssertionError( TestUtil.formatErrorMessage( - "Unexpected Exception: " + e.getMessage() + ", expected: " + pe.getMessage(), + "Unexpected Exception: " + e.getMessage() + ", expected: " + polyglotException.getMessage(), testRun, context), e); diff --git a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ExpressionTest.java b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ExpressionTest.java index b62fc8d3f932..e6084a31d300 100644 --- a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ExpressionTest.java +++ b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ExpressionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -43,7 +43,6 @@ import java.util.AbstractMap; import java.util.Collection; import java.util.Objects; -import java.util.function.Function; import org.graalvm.polyglot.Value; import org.junit.Assume; import org.junit.BeforeClass; @@ -51,7 +50,6 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.graalvm.polyglot.PolyglotException; -import org.graalvm.polyglot.tck.Snippet; import org.junit.AfterClass; @RunWith(Parameterized.class) @@ -67,18 +65,8 @@ public static Collection createExpressionTests() { final Collection testRuns = TestUtil.createTestRuns( TestUtil.getRequiredLanguages(context), TestUtil.getRequiredValueLanguages(context), - new Function>() { - @Override - public Collection apply(String lang) { - return context.getExpressions(null, null, lang); - } - }, - new Function>() { - @Override - public Collection apply(String lang) { - return context.getValueConstructors(null, lang); - } - }); + lang -> context.getExpressions(null, null, lang), + lang -> context.getValueConstructors(null, lang)); if (testRuns.isEmpty()) { // BeforeClass and AfterClass annotated methods are not called when there are no tests // to run. But we need to free TestContext. @@ -108,12 +96,18 @@ public void testExpression() { Assume.assumeThat(testRun, TEST_RESULT_MATCHER); boolean success = false; try { + Value result = null; try { - final Value result = testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray()); - TestUtil.validateResult(testRun, result, null, true); + result = testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray()); + } catch (IllegalArgumentException e) { + TestUtil.validateResult(testRun, context.getContext().asValue(e).as(PolyglotException.class)); success = true; - } catch (PolyglotException pe) { - TestUtil.validateResult(testRun, null, pe, true); + } catch (PolyglotException e) { + TestUtil.validateResult(testRun, e); + success = true; + } + if (result != null) { + TestUtil.validateResult(testRun, result, true); success = true; } } catch (PolyglotException | AssertionError e) { diff --git a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/IdentityFunctionTest.java b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/IdentityFunctionTest.java index dc3ca65f1ce2..6cd769bb3cb1 100644 --- a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/IdentityFunctionTest.java +++ b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/IdentityFunctionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -40,12 +40,6 @@ */ package com.oracle.truffle.tck.tests; -import java.util.AbstractMap; -import java.util.Arrays; -import java.util.Collection; -import java.util.Objects; -import java.util.function.Function; - import org.graalvm.polyglot.PolyglotException; import org.graalvm.polyglot.Value; import org.graalvm.polyglot.tck.LanguageProvider; @@ -57,6 +51,11 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import java.util.AbstractMap; +import java.util.Collection; +import java.util.List; +import java.util.Objects; + @RunWith(Parameterized.class) public class IdentityFunctionTest { @@ -70,18 +69,8 @@ public static Collection createExpressionTests() { final Collection testRuns = TestUtil.createTestRuns( TestUtil.getRequiredLanguages(context), TestUtil.getRequiredValueLanguages(context), - new Function>() { - @Override - public Collection apply(String lang) { - return Arrays.asList(createIdentitySnippet(lang)); - } - }, - new Function>() { - @Override - public Collection apply(String lang) { - return context.getValueConstructors(null, lang); - } - }); + lang -> List.of(createIdentitySnippet(lang)), + lang -> context.getValueConstructors(null, lang)); if (testRuns.isEmpty()) { // BeforeClass and AfterClass annotated methods are not called when there are no tests // to run. But we need to free TestContext. @@ -116,12 +105,18 @@ public void testIdentityFunction() { Assume.assumeThat(testRun, TEST_RESULT_MATCHER); boolean success = false; try { + Value result = null; try { - final Value result = testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray()); - TestUtil.validateResult(testRun, result, null, true); + result = testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray()); + } catch (IllegalArgumentException e) { + TestUtil.validateResult(testRun, context.getContext().asValue(e).as(PolyglotException.class)); success = true; - } catch (PolyglotException pe) { - TestUtil.validateResult(testRun, null, pe, true); + } catch (PolyglotException e) { + TestUtil.validateResult(testRun, e); + success = true; + } + if (result != null) { + TestUtil.validateResult(testRun, result, true); success = true; } } catch (PolyglotException | AssertionError e) { diff --git a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/InlineExecutionTest.java b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/InlineExecutionTest.java index 1a093ffaa5f3..0bdf56e86e27 100644 --- a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/InlineExecutionTest.java +++ b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/InlineExecutionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -43,6 +43,7 @@ import com.oracle.truffle.tck.common.inline.InlineVerifier; import java.util.AbstractMap; import java.util.Collection; +import java.util.Comparator; import java.util.Objects; import java.util.TreeSet; @@ -66,7 +67,7 @@ public class InlineExecutionTest { @Parameterized.Parameters(name = "{0}") public static Collection createScriptTests() { context = new TestContext(InlineExecutionTest.class); - final Collection res = new TreeSet<>((a, b) -> a.toString().compareTo(b.toString())); + final Collection res = new TreeSet<>(Comparator.comparing(TestRun::toString)); for (String lang : TestUtil.getRequiredLanguages(context)) { for (InlineSnippet snippet : context.getInlineScripts(lang)) { res.add(new InlineTestRun(new AbstractMap.SimpleImmutableEntry<>(lang, snippet.getScript()), snippet)); @@ -110,12 +111,18 @@ public void testInline() throws Exception { context.getContext().initialize(testRun.getID()); context.setInlineSnippet(testRun.getID(), inlineSnippet, verifier); try { + Value result = null; try { - final Value result = testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray()); - TestUtil.validateResult(testRun, result, null, true); + result = testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray()); + } catch (IllegalArgumentException e) { + TestUtil.validateResult(testRun, context.getContext().asValue(e).as(PolyglotException.class)); success = true; - } catch (PolyglotException pe) { - TestUtil.validateResult(testRun, null, pe, true); + } catch (PolyglotException e) { + TestUtil.validateResult(testRun, e); + success = true; + } + if (result != null) { + TestUtil.validateResult(testRun, result, true); success = true; } if (verifier != null && verifier.exception != null) { @@ -143,14 +150,14 @@ private class TestResultVerifier implements InlineVerifier.ResultVerifier { public void verify(Object ret) { Value result = context.getValue(ret); InlineSnippet inlineSnippet = testRun.getInlineSnippet(); - TestUtil.validateResult(inlineSnippet.getResultVerifier(), testRun, result, null, true); + TestUtil.validateResult(inlineSnippet.getResultVerifier(), testRun, result, true); } @Override public void verify(PolyglotException pe) { InlineSnippet inlineSnippet = testRun.getInlineSnippet(); try { - TestUtil.validateResult(inlineSnippet.getResultVerifier(), testRun, null, pe, true); + TestUtil.validateResult(inlineSnippet.getResultVerifier(), testRun, pe); } catch (Exception exc) { exception = exc; } diff --git a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/InvalidSyntaxTest.java b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/InvalidSyntaxTest.java index e5ec07734040..25a63b4b71c5 100644 --- a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/InvalidSyntaxTest.java +++ b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/InvalidSyntaxTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -42,6 +42,7 @@ import java.util.AbstractMap; import java.util.Collection; +import java.util.Comparator; import java.util.Objects; import java.util.TreeSet; @@ -63,7 +64,7 @@ public class InvalidSyntaxTest { @Parameterized.Parameters(name = "{0}") public static Collection createInvalidSyntaxTests() { context = new TestContext(InvalidSyntaxTest.class); - final Collection result = new TreeSet<>((a, b) -> ((String) a[0]).compareTo(((String) b[0]))); + final Collection result = new TreeSet<>(Comparator.comparing(a -> ((String) a[0]))); for (String language : TestUtil.getRequiredLanguages(context)) { for (Source src : context.getInstalledProviders().get(language).createInvalidSyntaxScripts(context.getContext())) { result.add(new Object[]{ diff --git a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ScriptTest.java b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ScriptTest.java index 46be5760c506..5e6f7910eb59 100644 --- a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ScriptTest.java +++ b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ScriptTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -43,6 +43,7 @@ import java.util.AbstractMap; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.Objects; import java.util.TreeSet; import org.graalvm.polyglot.Value; @@ -64,7 +65,7 @@ public class ScriptTest { @Parameterized.Parameters(name = "{0}") public static Collection createScriptTests() { context = new TestContext(ScriptTest.class); - final Collection res = new TreeSet<>((a, b) -> a.toString().compareTo(b.toString())); + final Collection res = new TreeSet<>(Comparator.comparing(TestRun::toString)); for (String lang : TestUtil.getRequiredLanguages(context)) { for (Snippet script : context.getScripts(null, lang)) { res.add(new TestRun(new AbstractMap.SimpleImmutableEntry<>(lang, script), Collections.emptyList())); @@ -99,12 +100,18 @@ public void testScript() { Assume.assumeThat(testRun, TEST_RESULT_MATCHER); boolean success = false; try { + Value result = null; try { - final Value result = testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray()); - TestUtil.validateResult(testRun, result, null, true); + result = testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray()); + } catch (IllegalArgumentException e) { + TestUtil.validateResult(testRun, context.getContext().asValue(e).as(PolyglotException.class)); success = true; - } catch (PolyglotException pe) { - TestUtil.validateResult(testRun, null, pe, true); + } catch (PolyglotException e) { + TestUtil.validateResult(testRun, e); + success = true; + } + if (result != null) { + TestUtil.validateResult(testRun, result, true); success = true; } } finally { diff --git a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/StatementTest.java b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/StatementTest.java index 3c7d2a740a68..504886df1488 100644 --- a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/StatementTest.java +++ b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/StatementTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -43,13 +43,11 @@ import java.util.AbstractMap; import java.util.Collection; import java.util.Objects; -import java.util.function.Function; import org.graalvm.polyglot.Value; import org.junit.BeforeClass; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.graalvm.polyglot.PolyglotException; -import org.graalvm.polyglot.tck.Snippet; import org.junit.AfterClass; import org.junit.Assume; import org.junit.Test; @@ -67,18 +65,8 @@ public static Collection createControlFlowTests() { final Collection testRuns = TestUtil.createTestRuns( TestUtil.getRequiredLanguages(context), TestUtil.getRequiredValueLanguages(context), - new Function>() { - @Override - public Collection apply(String lang) { - return context.getStatements(null, null, lang); - } - }, - new Function>() { - @Override - public Collection apply(String lang) { - return context.getValueConstructors(null, lang); - } - }); + lang -> context.getStatements(null, null, lang), + lang -> context.getValueConstructors(null, lang)); if (testRuns.isEmpty()) { // BeforeClass and AfterClass annotated methods are not called when there are no tests // to run. But we need to free TestContext. @@ -108,12 +96,18 @@ public void testStatement() { Assume.assumeThat(testRun, TEST_RESULT_MATCHER); boolean success = false; try { + Value result = null; try { - final Value result = testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray()); - TestUtil.validateResult(testRun, result, null, true); + result = testRun.getSnippet().getExecutableValue().execute(testRun.getActualParameters().toArray()); + } catch (IllegalArgumentException e) { + TestUtil.validateResult(testRun, context.getContext().asValue(e).as(PolyglotException.class)); success = true; - } catch (PolyglotException pe) { - TestUtil.validateResult(testRun, null, pe, true); + } catch (PolyglotException e) { + TestUtil.validateResult(testRun, e); + success = true; + } + if (result != null) { + TestUtil.validateResult(testRun, result, true); success = true; } } catch (PolyglotException | AssertionError e) { diff --git a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/TestUtil.java b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/TestUtil.java index fec4b23159a3..2eb2fd83d28f 100644 --- a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/TestUtil.java +++ b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/TestUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -44,6 +44,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -89,14 +90,7 @@ static Set getRequiredLanguages(final TestContext context) { if (LANGUAGE != null && !installedProviders.contains(LANGUAGE)) { throw providerNotFound("tck.language", Collections.singleton(LANGUAGE), installedProviders); } - return filterLanguages( - context, - LANGUAGE == null ? null : new Predicate() { - @Override - public boolean test(String lang) { - return LANGUAGE.equals(lang); - } - }); + return filterLanguages(context, LANGUAGE == null ? null : LANGUAGE::equals); } static Set getRequiredValueLanguages(final TestContext context) { @@ -109,12 +103,7 @@ static Set getRequiredValueLanguages(final TestContext context requiredValues.removeAll(installedProviders); throw providerNotFound("tck.values", requiredValues, installedProviders); } - predicate = new Predicate<>() { - @Override - public boolean test(String lang) { - return requiredValues.contains(lang); - } - }; + predicate = requiredValues::contains; } else { predicate = null; } @@ -130,7 +119,7 @@ static Collection createTestRuns( final Set requiredValueLanguages, final Function> snippetsProvider, final Function> valuesProvider) { - final Collection testRuns = new TreeSet<>((a, b) -> a.toString().compareTo(b.toString())); + final Collection testRuns = new TreeSet<>(Comparator.comparing(TestRun::toString)); for (String opLanguage : requiredLanguages) { for (Snippet operator : snippetsProvider.apply(opLanguage)) { for (String parLanguage : requiredValueLanguages) { @@ -141,7 +130,7 @@ static Collection createTestRuns( final List>> applicableParams = findApplicableParameters(operator, valueConstructors); boolean canBeInvoked = true; for (List> param : applicableParams) { - canBeInvoked &= !param.isEmpty(); + canBeInvoked = !param.isEmpty(); if (!canBeInvoked) { break; } @@ -155,30 +144,26 @@ static Collection createTestRuns( return testRuns; } - static void validateResult( - final TestRun testRun, - final Value result, - final PolyglotException exception, - boolean fastAssertions) { + static void validateResult(TestRun testRun, Value result, boolean fastAssertions) { ResultVerifier verifier = testRun.getSnippet().getResultVerifier(); - validateResult(verifier, testRun, result, exception, fastAssertions); + validateResult(verifier, testRun, result, fastAssertions); } - static void validateResult( - final ResultVerifier verifier, - final TestRun testRun, - final Value result, - final PolyglotException exception, - boolean fastAssertions) { - if (exception == null) { - verifier.accept(ResultVerifier.SnippetRun.create(testRun.getSnippet(), testRun.getActualParameters(), result)); - assertValue(result, fastAssertions); - } else { - verifier.accept(ResultVerifier.SnippetRun.create(testRun.getSnippet(), testRun.getActualParameters(), exception)); - Value exceptionObject = exception.getGuestObject(); - if (exceptionObject != null) { - assertValue(exceptionObject, fastAssertions); - } + static void validateResult(TestRun testRun, PolyglotException exception) { + ResultVerifier verifier = testRun.getSnippet().getResultVerifier(); + validateResult(verifier, testRun, exception); + } + + static void validateResult(ResultVerifier verifier, TestRun testRun, Value result, boolean fastAssertions) { + verifier.accept(ResultVerifier.SnippetRun.create(testRun.getSnippet(), testRun.getActualParameters(), result)); + assertValue(result, fastAssertions); + } + + static void validateResult(ResultVerifier verifier, TestRun testRun, PolyglotException polyglotException) { + verifier.accept(ResultVerifier.SnippetRun.create(testRun.getSnippet(), testRun.getActualParameters(), polyglotException)); + Value exceptionObject = polyglotException.getGuestObject(); + if (exceptionObject != null) { + assertValue(exceptionObject, true); } } diff --git a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ValueTest.java b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ValueTest.java index dfcbc32bc70c..c63b13962996 100644 --- a/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ValueTest.java +++ b/truffle/src/com.oracle.truffle.tck.tests/src/com/oracle/truffle/tck/tests/ValueTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -105,7 +105,7 @@ public void testValues() { boolean success = false; try { Value value = testRun.getActualParameters().get(0); - TestUtil.validateResult(testRun, value, null, false); + TestUtil.validateResult(testRun, value, false); success = true; } finally { TEST_RESULT_MATCHER.accept(new AbstractMap.SimpleImmutableEntry<>(testRun, success));