From ef21abde05b925df6774f872437812fff1b3f9ee Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Sun, 14 Mar 2021 13:58:37 +0700 Subject: [PATCH] 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 --- .../XMLBasedAjcTestCaseForJava14Only.java | 31 +++++++ .../ajc196/Ajc196PreviewFeaturesTests.java | 51 +++++++++++ .../systemtest/ajc196/Ajc196Tests.java | 87 ++++++++----------- .../systemtest/ajc196/AllTestsAspectJ196.java | 3 + .../org/aspectj/systemtest/ajc196/ajc196.xml | 5 +- 5 files changed, 120 insertions(+), 57 deletions(-) create mode 100644 testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava14Only.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc196/Ajc196PreviewFeaturesTests.java 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 @@ - + @@ -98,8 +98,6 @@ - @@ -112,7 +110,6 @@ - -- 2.39.5