From 9de03c3ea52f78678d8c47296395d5f01d031a48 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Sat, 26 Jun 2021 16:16:18 +0700 Subject: [PATCH] Add AspectJ 1.9.7 and Java 17 test skeletons Signed-off-by: Alexander Kriegisch --- .../org/aspectj/apache/bcel/Constants.java | 6 +- .../XMLBasedAjcTestCaseForJava17Only.java | 39 +++++++++ .../XMLBasedAjcTestCaseForJava17OrLater.java | 27 ++++++ .../org/aspectj/systemtest/AllTests19.java | 2 + .../systemtest/ajc198/Ajc198TestsJava.java | 64 ++++++++++++++ .../systemtest/ajc198/AllTestsAspectJ198.java | 30 +++++++ .../ajc198/Java17PreviewFeaturesTests.java | 47 ++++++++++ .../systemtest/ajc198/SanityTestsJava17.java | 87 +++++++++++++++++++ .../org/aspectj/systemtest/ajc198/ajc198.xml | 35 ++++++++ .../systemtest/ajc198/sanity-tests-17.xml | 70 +++++++++++++++ .../main/java/org/aspectj/util/LangUtil.java | 4 + 11 files changed, 409 insertions(+), 2 deletions(-) create mode 100644 testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava17Only.java create mode 100644 testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava17OrLater.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc198/Ajc198TestsJava.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc198/AllTestsAspectJ198.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc198/Java17PreviewFeaturesTests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc198/SanityTestsJava17.java create mode 100644 tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml create mode 100644 tests/src/test/resources/org/aspectj/systemtest/ajc198/sanity-tests-17.xml diff --git a/bcel-builder/src/main/java/org/aspectj/apache/bcel/Constants.java b/bcel-builder/src/main/java/org/aspectj/apache/bcel/Constants.java index 285d024b6..1ce3682d3 100644 --- a/bcel-builder/src/main/java/org/aspectj/apache/bcel/Constants.java +++ b/bcel-builder/src/main/java/org/aspectj/apache/bcel/Constants.java @@ -96,8 +96,10 @@ public interface Constants { short MINOR_15 = 0; short MAJOR_16 = 60; short MINOR_16 = 0; -// short MAJOR_17 = 61; -// short MINOR_17 = 0; + short MAJOR_17 = 61; + short MINOR_17 = 0; +// short MAJOR_18 = 62; +// short MINOR_18 = 0; int PREVIEW_MINOR_VERSION = 65535; diff --git a/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava17Only.java b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava17Only.java new file mode 100644 index 000000000..e20ee7af7 --- /dev/null +++ b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava17Only.java @@ -0,0 +1,39 @@ +/* ******************************************************************* + * Copyright (c) 2021 Contributors + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v 2.0 + * which accompanies this distribution and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt + * ******************************************************************/ +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 XMLBasedAjcTestCaseForJava17Only extends XMLBasedAjcTestCase { + + @Override + public void setUp() throws Exception { + // Activate this block after upgrading to JDT Core Java 18 + /* + throw new IllegalStateException( + "These tests need a Java 17 level AspectJ compiler " + + "(e.g. because they use version-specific preview features). " + + "This compiler does not support preview features of a previous version anymore." + ); + */ + if (!LangUtil.is17VMOrGreater() || LangUtil.is18VMOrGreater()) { + throw new IllegalStateException( + "These tests should be run on Java 17 only " + + "(e.g. because they use version-specific preview features)" + ); + } + super.setUp(); + } + +} diff --git a/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava17OrLater.java b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava17OrLater.java new file mode 100644 index 000000000..1e18e2f7a --- /dev/null +++ b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava17OrLater.java @@ -0,0 +1,27 @@ +/* ******************************************************************* + * Copyright (c) 2021 Contributors + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v 2.0 + * which accompanies this distribution and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt + * ******************************************************************/ +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 XMLBasedAjcTestCaseForJava17OrLater extends XMLBasedAjcTestCase { + + @Override + public void setUp() throws Exception { + if (!LangUtil.is17VMOrGreater()) + throw new IllegalStateException("These tests should be run on Java 17 or later"); + super.setUp(); + } + +} diff --git a/tests/src/test/java/org/aspectj/systemtest/AllTests19.java b/tests/src/test/java/org/aspectj/systemtest/AllTests19.java index 4a52e8fe4..7223aff59 100644 --- a/tests/src/test/java/org/aspectj/systemtest/AllTests19.java +++ b/tests/src/test/java/org/aspectj/systemtest/AllTests19.java @@ -17,6 +17,7 @@ import org.aspectj.systemtest.ajc196.AllTestsAspectJ196; import junit.framework.Test; import junit.framework.TestSuite; import org.aspectj.systemtest.ajc197.AllTestsAspectJ197; +import org.aspectj.systemtest.ajc198.AllTestsAspectJ198; /** * @author Andy Clement @@ -34,6 +35,7 @@ public class AllTests19 { suite.addTest(AllTestsAspectJ195.suite()); suite.addTest(AllTestsAspectJ196.suite()); suite.addTest(AllTestsAspectJ197.suite()); + suite.addTest(AllTestsAspectJ198.suite()); suite.addTest(AllTests18.suite()); // $JUnit-END$ return suite; diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc198/Ajc198TestsJava.java b/tests/src/test/java/org/aspectj/systemtest/ajc198/Ajc198TestsJava.java new file mode 100644 index 000000000..172d6e14e --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc198/Ajc198TestsJava.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2021 Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt + *******************************************************************************/ +package org.aspectj.systemtest.ajc198; + +import junit.framework.Test; +import org.aspectj.apache.bcel.Constants; +import org.aspectj.testing.XMLBasedAjcTestCase; +import org.aspectj.testing.XMLBasedAjcTestCaseForJava17OrLater; + +/** + * @author Alexander Kriegisch + */ +public class Ajc198TestsJava extends XMLBasedAjcTestCaseForJava17OrLater { + + public void testHiddenClass() { + runTest("hidden class"); + checkVersion("HiddenClassDemo", Constants.MAJOR_17, Constants.MINOR_17); + } + + public void testTextBlock1() { + runTest("textblock 1"); + checkVersion("Code", Constants.MAJOR_17, Constants.MINOR_17); + } + + public void testTextBlock2() { + runTest("textblock 2"); + checkVersion("Code2", Constants.MAJOR_17, Constants.MINOR_17); + } + + public void testRecords() { + runTest("simple record"); + checkVersion("Person", Constants.MAJOR_17, Constants.MINOR_17); + } + + public void testRecords2() { + runTest("using a record"); + checkVersion("UsingPersonRecord", Constants.MAJOR_17, Constants.MINOR_17); + } + + public void testAdvisingRecords() { + runTest("advising records"); + checkVersion("TraceRecordComponents", Constants.MAJOR_17, Constants.MINOR_17); + } + + public void testInstanceofPatterns() { + runTest("instanceof patterns"); + checkVersion("Jep305", Constants.MAJOR_17, Constants.MINOR_17); + } + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(Ajc198TestsJava.class); + } + + @Override + protected java.net.URL getSpecFile() { + return getClassResource("ajc198.xml"); + } + +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc198/AllTestsAspectJ198.java b/tests/src/test/java/org/aspectj/systemtest/ajc198/AllTestsAspectJ198.java new file mode 100644 index 000000000..26d749222 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc198/AllTestsAspectJ198.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2021 Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt + *******************************************************************************/ +package org.aspectj.systemtest.ajc198; + +import junit.framework.Test; +import junit.framework.TestSuite; +import org.aspectj.util.LangUtil; + +/** + * @author Alexander Kriegisch + */ +public class AllTestsAspectJ198 { + + public static Test suite() { + TestSuite suite = new TestSuite("AspectJ 1.9.8 tests"); + if (LangUtil.is17VMOrGreater()) { + suite.addTest(SanityTestsJava17.suite()); + suite.addTest(Ajc198TestsJava.suite()); + } + if (LangUtil.is17VMOrGreater() && !LangUtil.is18VMOrGreater()) { + suite.addTest(Java17PreviewFeaturesTests.suite()); + } + return suite; + } +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc198/Java17PreviewFeaturesTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc198/Java17PreviewFeaturesTests.java new file mode 100644 index 000000000..fab787724 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc198/Java17PreviewFeaturesTests.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2021 Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt + *******************************************************************************/ +package org.aspectj.systemtest.ajc198; + +import junit.framework.Test; +import org.aspectj.apache.bcel.Constants; +import org.aspectj.testing.XMLBasedAjcTestCase; +import org.aspectj.testing.XMLBasedAjcTestCaseForJava17Only; + +/** + * @author Alexander Kriegisch + */ +public class Java17PreviewFeaturesTests extends XMLBasedAjcTestCaseForJava17Only { + +/* + public void testSealedClassWithLegalSubclasses() { + runTest("sealed class with legal subclasses"); + checkVersion("Employee", Constants.MAJOR_16, Constants.PREVIEW_MINOR_VERSION); + checkVersion("Manager", Constants.MAJOR_16, Constants.PREVIEW_MINOR_VERSION); + } + + public void testSealedClassWithIllegalSubclass() { + runTest("sealed class with illegal subclass"); + checkVersion("Person", Constants.MAJOR_16, Constants.PREVIEW_MINOR_VERSION); + } + + public void testWeaveSealedClass() { + runTest("weave sealed class"); + checkVersion("PersonAspect", Constants.MAJOR_16, Constants.PREVIEW_MINOR_VERSION); + } +*/ + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(Java17PreviewFeaturesTests.class); + } + + @Override + protected java.net.URL getSpecFile() { + return getClassResource("ajc198.xml"); + } + +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc198/SanityTestsJava17.java b/tests/src/test/java/org/aspectj/systemtest/ajc198/SanityTestsJava17.java new file mode 100644 index 000000000..4fac5f375 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc198/SanityTestsJava17.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2021 Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt + *******************************************************************************/ +package org.aspectj.systemtest.ajc198; + +import junit.framework.Test; +import org.aspectj.testing.XMLBasedAjcTestCase; +import org.aspectj.testing.XMLBasedAjcTestCaseForJava17OrLater; + +/* + * Some very trivial tests that help verify things are OK. + * These are a copy of the earlier Sanity Tests created for 1.6 but these supply the -10 option + * to check code generation and modification with that version specified. + * + * @author Alexander Kriegisch + */ +public class SanityTestsJava17 extends XMLBasedAjcTestCaseForJava17OrLater { + + public static final int bytecode_version_for_JDK_level = 61; + + // Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug) + public void testSimpleJava_A() { + runTest("simple - a"); + } + + public void testSimpleJava_B() { + runTest("simple - b"); + } + + public void testSimpleCode_C() { + runTest("simple - c"); + } + + public void testSimpleCode_D() { + runTest("simple - d"); + } + + public void testSimpleCode_E() { + runTest("simple - e"); + } + + public void testSimpleCode_F() { + runTest("simple - f"); + } + + public void testSimpleCode_G() { + runTest("simple - g"); + } + + public void testSimpleCode_H() { + runTest("simple - h", true); + } + + public void testSimpleCode_I() { + runTest("simple - i"); + } + + public void testVersionCorrect1() { + runTest("simple - j"); + checkVersion("A", bytecode_version_for_JDK_level, 0); + } + + public void testVersionCorrect2() { + runTest("simple - k"); + checkVersion("A", bytecode_version_for_JDK_level, 0); + } + + public void testVersionCorrect4() { + runTest("simple - m"); + // Must be 49.0 when -1.5 is specified + checkVersion("A", 49, 0); + } + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(SanityTestsJava17.class); + } + + @Override + protected java.net.URL getSpecFile() { + return getClassResource("sanity-tests-17.xml"); + } + +} diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml new file mode 100644 index 000000000..e2dc9fe5d --- /dev/null +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc198/sanity-tests-17.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc198/sanity-tests-17.xml new file mode 100644 index 000000000..70f52fafa --- /dev/null +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc198/sanity-tests-17.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/util/src/main/java/org/aspectj/util/LangUtil.java b/util/src/main/java/org/aspectj/util/LangUtil.java index c53d18989..187b895b2 100644 --- a/util/src/main/java/org/aspectj/util/LangUtil.java +++ b/util/src/main/java/org/aspectj/util/LangUtil.java @@ -190,6 +190,10 @@ public class LangUtil { return 17 <= vmVersion; } + public static boolean is18VMOrGreater() { + return 18 <= vmVersion; + } + /** * Shorthand for "if null, throw IllegalArgumentException" * -- 2.39.5