diff options
author | Alexander Kriegisch <Alexander@Kriegisch.name> | 2021-03-14 13:58:37 +0700 |
---|---|---|
committer | Alexander Kriegisch <Alexander@Kriegisch.name> | 2021-03-14 13:58:37 +0700 |
commit | ef21abde05b925df6774f872437812fff1b3f9ee (patch) | |
tree | 4c3062a839138400f76e32876ac0346b8f77f573 | |
parent | bf48d9dd07a7ebd5ac61b66df5c478b59fca831a (diff) | |
download | aspectj-ef21abde05b925df6774f872437812fff1b3f9ee.tar.gz aspectj-ef21abde05b925df6774f872437812fff1b3f9ee.zip |
Make sure Java 14-only tests using preview are not executed on JVM 15+
Some Ajc196 tests are using preview features (see .../ajc196.xml), i.e.
they will fail on Java 15+ because code compiled with '--enable-preview'
can only run on the same JVM version, not on a more recent one. Hence,
the preview-using tests are now being excluded in order to make the
build run on Java 15, even though no Java 15 features are present in the
current 1.9.7 snapshot.
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
5 files changed, 120 insertions, 57 deletions
diff --git a/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava14Only.java b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava14Only.java new file mode 100644 index 000000000..3bdb4d6be --- /dev/null +++ b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava14Only.java @@ -0,0 +1,31 @@ +/* ******************************************************************* + * Copyright (c) 2021 Contributors + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * ******************************************************************/ +package org.aspectj.testing; + +import org.aspectj.util.LangUtil; + +/** + * Makes sure tests are running on the right level of JDK. + * + * @author Alexander Kriegisch + */ +public abstract class XMLBasedAjcTestCaseForJava14Only extends XMLBasedAjcTestCase { + + @Override + public void runTest(String title) { + if (!LangUtil.is14VMOrGreater() || LangUtil.is15VMOrGreater()) { + throw new IllegalStateException( + "These tests should be run on Java 14 only " + + "(e.g. because they use version-specific preview features)" + ); + } + super.runTest(title); + } + +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc196/Ajc196PreviewFeaturesTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc196/Ajc196PreviewFeaturesTests.java new file mode 100644 index 000000000..f9c68131e --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc196/Ajc196PreviewFeaturesTests.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2021 Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.aspectj.systemtest.ajc196; + +import org.aspectj.testing.XMLBasedAjcTestCase; +import org.aspectj.testing.XMLBasedAjcTestCaseForJava14Only; + +import junit.framework.Test; + +/** + * @author Alexander Kriegisch + */ +public class Ajc196PreviewFeaturesTests extends XMLBasedAjcTestCaseForJava14Only { + + public void testRecords2() { + runTest("using a record"); + } + + public void testInstanceofPatterns() { + runTest("instanceof patterns"); + } + + public void testAdvisingRecords() { + runTest("advising records"); + } + + public void testTextBlock1() { + runTest("textblock 1"); + } + + public void testTextBlock2() { + runTest("textblock 2"); + } + + // --- + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(Ajc196PreviewFeaturesTests.class); + } + + @Override + protected java.net.URL getSpecFile() { + return getClassResource("ajc196.xml"); + } + +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc196/Ajc196Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc196/Ajc196Tests.java index 00bae65e4..7ec224109 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc196/Ajc196Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc196/Ajc196Tests.java @@ -18,58 +18,39 @@ import junit.framework.Test; */ public class Ajc196Tests extends XMLBasedAjcTestCaseForJava14OrLater { - public void testNPE_558995() { - runTest("early resolution of supporting interfaces"); - } - - public void testRecords() { - runTest("simple record"); - checkVersion("Person", Constants.MAJOR_14, Constants.PREVIEW_MINOR_VERSION); - } - - public void testRecords2() { - runTest("using a record"); - } - - public void testInstanceofPatterns() { - runTest("instanceof patterns"); - } - - public void testAdvisingRecords() { - runTest("advising records"); - } - - public void testSwitch1() { - runTest("switch 1"); - checkVersion("Switch1", Constants.MAJOR_14, 0); - } - - public void testSwitch2() { - runTest("switch 2"); - checkVersion("Switch2", Constants.MAJOR_14, 0); - } - - public void testSwitch3() { - runTest("switch 3"); - checkVersion("Switch3", Constants.MAJOR_14, 0); - } - - public void testTextBlock1() { - runTest("textblock 1"); - } - - public void testTextBlock2() { - runTest("textblock 2"); - } - // --- - - public static Test suite() { - return XMLBasedAjcTestCase.loadSuite(Ajc196Tests.class); - } - - @Override - protected java.net.URL getSpecFile() { - return getClassResource("ajc196.xml"); - } + public void testNPE_558995() { + runTest("early resolution of supporting interfaces"); + } + + public void testRecords() { + runTest("simple record"); + checkVersion("Person", Constants.MAJOR_14, Constants.PREVIEW_MINOR_VERSION); + } + + public void testSwitch1() { + runTest("switch 1"); + checkVersion("Switch1", Constants.MAJOR_14, 0); + } + + public void testSwitch2() { + runTest("switch 2"); + checkVersion("Switch2", Constants.MAJOR_14, 0); + } + + public void testSwitch3() { + runTest("switch 3"); + checkVersion("Switch3", Constants.MAJOR_14, 0); + } + + // --- + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(Ajc196Tests.class); + } + + @Override + protected java.net.URL getSpecFile() { + return getClassResource("ajc196.xml"); + } } diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc196/AllTestsAspectJ196.java b/tests/src/test/java/org/aspectj/systemtest/ajc196/AllTestsAspectJ196.java index 0cdfe9290..fa2a3aea2 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc196/AllTestsAspectJ196.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc196/AllTestsAspectJ196.java @@ -23,6 +23,9 @@ public class AllTestsAspectJ196 { suite.addTest(Ajc196Tests.suite()); suite.addTest(SanityTestsJava14.suite()); } + if (LangUtil.is14VMOrGreater() && !LangUtil.is15VMOrGreater()) { + suite.addTest(Ajc196PreviewFeaturesTests.suite()); + } return suite; } } diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc196/ajc196.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc196/ajc196.xml index 69a9fd8bf..3ef3457d2 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc196/ajc196.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc196/ajc196.xml @@ -10,7 +10,7 @@ <ajc-test dir="features193" vm="14" title="switch 1"> <compile files="Switch1.java" options="-14"> </compile> - <run class="Switch1" vmargs="--enable-preview"> + <run class="Switch1"> <stdout> <line text="0" /> <line text="1" /> @@ -98,8 +98,6 @@ <run class="Code" vmargs="--enable-preview"> <stdout> <line text="this is a text" /> - <!-- the incidental space is removed with a trim in output matching but - the test app doesn't remove it when printing it, why? --> <line text="block" /> </stdout> </run> @@ -112,7 +110,6 @@ </compile> <run class="Code2" vmargs="--enable-preview"> <stdout> - <!-- why is the incidental space not removed here?? --> <line text="this is a text" /> <line text="block in advice" /> </stdout> |