aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/test/java/org/aspectj
diff options
context:
space:
mode:
authorAlexander Kriegisch <Alexander@Kriegisch.name>2023-10-05 08:09:24 +0700
committerAlexander Kriegisch <Alexander@Kriegisch.name>2023-10-05 08:09:24 +0700
commit78ee9cebd81f1496d69bd0c933e3ee16fa02a96f (patch)
treef730564caf08786026dc6c9196fb8ba9d9fc3fc9 /tests/src/test/java/org/aspectj
parent3533dcd043ca31e6988fae714882328d23543a65 (diff)
downloadaspectj-78ee9cebd81f1496d69bd0c933e3ee16fa02a96f.tar.gz
aspectj-78ee9cebd81f1496d69bd0c933e3ee16fa02a96f.zip
Add test infrastructure for Java 21 (WIP)
The tests and their XML definitions are still copy & paste and need to be cleaned up. Separate Java 21 feature tests do not exist yet. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Diffstat (limited to 'tests/src/test/java/org/aspectj')
-rw-r--r--tests/src/test/java/org/aspectj/systemtest/ajc1920/AllTestsAspectJ1920.java3
-rw-r--r--tests/src/test/java/org/aspectj/systemtest/ajc1920/Java20PreviewFeaturesTests.java2
-rw-r--r--tests/src/test/java/org/aspectj/systemtest/ajc1921/Ajc1921TestsJava.java32
-rw-r--r--tests/src/test/java/org/aspectj/systemtest/ajc1921/AllTestsAspectJ1921.java33
-rw-r--r--tests/src/test/java/org/aspectj/systemtest/ajc1921/Bugs1921Tests.java100
-rw-r--r--tests/src/test/java/org/aspectj/systemtest/ajc1921/Java21PreviewFeaturesTests.java103
-rw-r--r--tests/src/test/java/org/aspectj/systemtest/ajc1921/SanityTestsJava21.java88
7 files changed, 359 insertions, 2 deletions
diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1920/AllTestsAspectJ1920.java b/tests/src/test/java/org/aspectj/systemtest/ajc1920/AllTestsAspectJ1920.java
index c7962c2db..a095eb758 100644
--- a/tests/src/test/java/org/aspectj/systemtest/ajc1920/AllTestsAspectJ1920.java
+++ b/tests/src/test/java/org/aspectj/systemtest/ajc1920/AllTestsAspectJ1920.java
@@ -24,10 +24,11 @@ public class AllTestsAspectJ1920 {
suite.addTest(Ajc1920TestsJava.suite());
}
// Do not run tests using a previous compiler's preview features anymore. They would all fail.
- // TODO: Comment out the following block when upgrading JDT Core to Java 20
+ /*
if (LangUtil.is20VMOrGreater() && !LangUtil.is21VMOrGreater()) {
suite.addTest(Java20PreviewFeaturesTests.suite());
}
+ */
return suite;
}
}
diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1920/Java20PreviewFeaturesTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc1920/Java20PreviewFeaturesTests.java
index e597b32ec..89a0a61c6 100644
--- a/tests/src/test/java/org/aspectj/systemtest/ajc1920/Java20PreviewFeaturesTests.java
+++ b/tests/src/test/java/org/aspectj/systemtest/ajc1920/Java20PreviewFeaturesTests.java
@@ -52,7 +52,7 @@ public class Java20PreviewFeaturesTests extends XMLBasedAjcTestCaseForJava20Only
}
public void testRecordPatternsPreview1Error() {
- // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/450 (fixed for preview 2 in Eclipse 2033-03, 4.27)
+ // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/450 (fixed for preview 2 in Eclipse 2023-03, 4.27)
runTest("record patterns error");
checkVersion("RecordPatternsPreview1Error", Constants.MAJOR_20, Constants.PREVIEW_MINOR_VERSION);
checkVersion("Box", Constants.MAJOR_20, Constants.PREVIEW_MINOR_VERSION);
diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1921/Ajc1921TestsJava.java b/tests/src/test/java/org/aspectj/systemtest/ajc1921/Ajc1921TestsJava.java
new file mode 100644
index 000000000..e7d3b9596
--- /dev/null
+++ b/tests/src/test/java/org/aspectj/systemtest/ajc1921/Ajc1921TestsJava.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2022 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.ajc1921;
+
+import junit.framework.Test;
+import org.aspectj.testing.XMLBasedAjcTestCase;
+import org.aspectj.testing.XMLBasedAjcTestCaseForJava21OrLater;
+
+/**
+ * @author Alexander Kriegisch
+ */
+public class Ajc1921TestsJava extends XMLBasedAjcTestCaseForJava21OrLater {
+
+ public void testDummyJava21() {
+ //runTest("dummy Java 21");
+ }
+
+ public static Test suite() {
+ return XMLBasedAjcTestCase.loadSuite(Ajc1921TestsJava.class);
+ }
+
+ @Override
+ protected java.net.URL getSpecFile() {
+ return getClassResource("ajc1921.xml");
+ }
+
+}
diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1921/AllTestsAspectJ1921.java b/tests/src/test/java/org/aspectj/systemtest/ajc1921/AllTestsAspectJ1921.java
new file mode 100644
index 000000000..773ac9037
--- /dev/null
+++ b/tests/src/test/java/org/aspectj/systemtest/ajc1921/AllTestsAspectJ1921.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2022 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.ajc1921;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.aspectj.util.LangUtil;
+
+/**
+ * @author Alexander Kriegisch
+ */
+public class AllTestsAspectJ1921 {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("AspectJ 1.9.21 tests");
+ suite.addTest(Bugs1921Tests.suite());
+ if (LangUtil.is21VMOrGreater()) {
+ suite.addTest(SanityTestsJava21.suite());
+ suite.addTest(Ajc1921TestsJava.suite());
+ }
+ // Do not run tests using a previous compiler's preview features anymore. They would all fail.
+ // TODO: Comment out the following block when upgrading JDT Core to Java 22
+ if (LangUtil.is21VMOrGreater() && !LangUtil.is22VMOrGreater()) {
+ suite.addTest(Java21PreviewFeaturesTests.suite());
+ }
+ return suite;
+ }
+}
diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1921/Bugs1921Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc1921/Bugs1921Tests.java
new file mode 100644
index 000000000..3c11149d3
--- /dev/null
+++ b/tests/src/test/java/org/aspectj/systemtest/ajc1921/Bugs1921Tests.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2023 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.ajc1921;
+
+import junit.framework.Test;
+import org.aspectj.testing.XMLBasedAjcTestCase;
+
+/**
+ * @author Alexander Kriegisch
+ */
+public class Bugs1921Tests extends XMLBasedAjcTestCase {
+
+ public void testSwitchWith_Integer_MAX_VALUE() {
+ runTest("switch with Integer.MAX_VALUE case");
+ }
+
+ public void testParenthesisedExpressionWithAjKeyword() {
+ runTest("parenthesised expression with AspectJ keyword");
+ }
+
+ public void testInterfaceInnerAspectImplicitlyStatic() {
+ runTest("inner aspect of interface is implicitly static");
+ }
+
+ public void testExactArrayTypeMatchCompiledTogether() {
+ runTest("exact array type matching, aspect compiled together with target class");
+ }
+
+ public void testExactArrayTypeMatchCompiledSeparately() {
+ runTest("exact array type matching, aspect compiled separately from target class");
+ }
+
+ public void testFuzzyArrayTypeMatchCompiledTogether() {
+ runTest("fuzzy array type matching, aspect compiled together with target class");
+ }
+
+ public void testFuzzyArrayTypeMatchCompiledSeparately() {
+ runTest("fuzzy array type matching, aspect compiled separately from target class");
+ }
+
+ public void test_GitHub_214() {
+ runTest("ArrayIndexOutOfBoundsException with Xlint unorderedAdviceAtShadow=warning");
+ }
+
+ /**
+ * Add correct annotations to multiple ITD methods with the same name and same number of arguments, i.e. copy the
+ * annotations correctly from the aspect into the target class instead of falsely always copying the annotations (if
+ * any) from the first ITD method found.
+ * <p>
+ * See <a href="https://github.com/eclipse-aspectj/aspectj/issues/246">GitHub issue 246</a>.
+ */
+ public void test_GitHub_246() {
+ runTest("add correct annotations to multiple ITD methods with the same name and same number of arguments");
+ }
+
+ /**
+ * Make sure to create one {@code ajc$inlineAccessMethod} for identically named (overloaded) private aspect methods.
+ * <p>
+ * See <a href="https://github.com/eclipse-aspectj/aspectj/issues/250">GitHub issue 250</a>.
+ */
+ public void test_GitHub_250() {
+ runTest("correctly handle overloaded private methods in aspects");
+ }
+
+ /**
+ * If one generic method overrides another one with a narrower return type, avoid matching bridge methods.
+ * <p>
+ * See <a href="https://github.com/spring-projects/spring-framework/issues/27761">Spring GitHub issue 27761</a>.
+ * <p>
+ * This test uses an ASM-modified class file reproducing the problem seen in Spring in plain AspectJ. Before the
+ * bugfix, it fails with <b>"advice defined in RepositoryAspect has not been applied [Xlint:adviceDidNotMatch]".</b>
+ */
+ public void test_Spring_GitHub_27761() {
+ runTest("do not match bridge methods");
+ }
+
+ /**
+ * In 1.9.20, a regression bug occurred, matching negated types like '!void' and '!String' incorrectly.
+ * <p>
+ * See <a href="https://github.com/eclipse-aspectj/aspectj/issues/257">GitHub issue 257</a>.
+ */
+ public void test_GitHub_257() {
+ runTest("handle negated type patterns correctly");
+ }
+
+ public static Test suite() {
+ return XMLBasedAjcTestCase.loadSuite(Bugs1921Tests.class);
+ }
+
+ @Override
+ protected java.net.URL getSpecFile() {
+ return getClassResource("ajc1921.xml");
+ }
+
+}
diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1921/Java21PreviewFeaturesTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc1921/Java21PreviewFeaturesTests.java
new file mode 100644
index 000000000..1088aac63
--- /dev/null
+++ b/tests/src/test/java/org/aspectj/systemtest/ajc1921/Java21PreviewFeaturesTests.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2023 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.ajc1921;
+
+import junit.framework.Test;
+import org.aspectj.apache.bcel.Constants;
+import org.aspectj.testing.XMLBasedAjcTestCase;
+import org.aspectj.testing.XMLBasedAjcTestCaseForJava21Only;
+
+/**
+ * @author Alexander Kriegisch
+ */
+public class Java21PreviewFeaturesTests extends XMLBasedAjcTestCaseForJava21Only {
+
+ public void testSwitchPatternMatchingPreview4Java() {
+ runTest("switch pattern matching preview 4 java");
+ checkVersion("SwitchPatternPreview4OK", Constants.MAJOR_21, Constants.PREVIEW_MINOR_VERSION);
+ }
+
+ public void testSwitchPatternMatchingPreview4Error() {
+ runTest("switch pattern matching preview 4 error");
+ }
+
+ public void testSwitchPatternMatchingPreview3Aspect() {
+ runTest("switch pattern matching preview 3 aspect");
+ checkVersion("SwitchPatternPreview3Aspect", Constants.MAJOR_21, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("Application", Constants.MAJOR_21, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("Shape", Constants.MAJOR_21, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("S", Constants.MAJOR_21, Constants.PREVIEW_MINOR_VERSION);
+ }
+
+ public void testSwitchPatternMatchingCaseLabelDominatedByPrecedingError() {
+ runTest("switch pattern matching error");
+ }
+
+ public void testSwitchPatternMatchingPreview3Error1() {
+ runTest("switch pattern matching preview 3 error 1");
+ }
+
+ public void testSwitchPatternMatchingPreview3Error2() {
+ runTest("switch pattern matching preview 3 error 2");
+ }
+
+ public void testRecordPatternsPreview1OK() {
+ // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/450
+ runTest("record patterns");
+ }
+
+ public void testRecordPatternsPreview1Error() {
+ // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/450 (fixed for preview 2 in Eclipse 2023-03, 4.27)
+ runTest("record patterns error");
+ checkVersion("RecordPatternsPreview1Error", Constants.MAJOR_21, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("Box", Constants.MAJOR_21, Constants.PREVIEW_MINOR_VERSION);
+ }
+
+ public void testRecordPatternsPreview1ExhaustivenessOK1() {
+ // Falsely throws 'An enhanced switch statement should be exhaustive; a default label expected' twice,
+ // see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455
+ // TODO: Remove redundant default clauses when fixed upstream
+ System.out.println("TODO: fully activate when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed");
+ runTest("record patterns exhaustiveness 1");
+ }
+
+ public void testRecordPatternsPreview1Aspect() {
+ runTest("record patterns aspect");
+ }
+
+ public void testRecordPatternsPreview1ExhaustivenessAspect() {
+ // Falsely throws 'An enhanced switch statement should be exhaustive; a default label expected' twice,
+ // see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455
+ // TODO: Remove redundant default clauses when fixed upstream
+ System.out.println("TODO: fully activate when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed");
+ runTest("record patterns exhaustiveness aspect");
+ }
+
+ public void testRecordPatternsPreview1ExhaustivenessError() {
+ // See https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455
+ runTest("record patterns exhaustiveness error");
+ }
+
+ public void testRecordPatternsPreview1ExhaustivenessOK2() {
+ // Falsely throws 'An enhanced switch statement should be exhaustive; a default label expected',
+ // see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/398
+ // TODO: activate when fixed
+ System.out.println("TODO: activate when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/398 has been fixed");
+ //runTest("record patterns exhaustiveness 2");
+ }
+
+ public static Test suite() {
+ return XMLBasedAjcTestCase.loadSuite(Java21PreviewFeaturesTests.class);
+ }
+
+ @Override
+ protected java.net.URL getSpecFile() {
+ return getClassResource("ajc1921.xml");
+ }
+
+}
diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1921/SanityTestsJava21.java b/tests/src/test/java/org/aspectj/systemtest/ajc1921/SanityTestsJava21.java
new file mode 100644
index 000000000..ed2216fdb
--- /dev/null
+++ b/tests/src/test/java/org/aspectj/systemtest/ajc1921/SanityTestsJava21.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2023 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.ajc1921;
+
+import junit.framework.Test;
+import org.aspectj.apache.bcel.Constants;
+import org.aspectj.testing.XMLBasedAjcTestCase;
+import org.aspectj.testing.XMLBasedAjcTestCaseForJava21OrLater;
+
+/*
+ * 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 -21 option
+ * to check code generation and modification with that version specified.
+ *
+ * @author Alexander Kriegisch
+ */
+public class SanityTestsJava21 extends XMLBasedAjcTestCaseForJava21OrLater {
+
+ public static final int bytecode_version_for_JDK_level = Constants.MAJOR_21;
+
+ // 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", Constants.MAJOR_1_5, 0);
+ }
+
+ public static Test suite() {
+ return XMLBasedAjcTestCase.loadSuite(SanityTestsJava21.class);
+ }
+
+ @Override
+ protected java.net.URL getSpecFile() {
+ return getClassResource("sanity-tests-21.xml");
+ }
+
+}