]> source.dussan.org Git - aspectj.git/commitdiff
Add AspectJ 1.9.7 and Java 17 test skeletons
authorAlexander Kriegisch <Alexander@Kriegisch.name>
Sat, 26 Jun 2021 09:16:18 +0000 (16:16 +0700)
committerAlexander Kriegisch <Alexander@Kriegisch.name>
Sat, 26 Jun 2021 09:51:19 +0000 (16:51 +0700)
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
bcel-builder/src/main/java/org/aspectj/apache/bcel/Constants.java
testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava17Only.java [new file with mode: 0644]
testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava17OrLater.java [new file with mode: 0644]
tests/src/test/java/org/aspectj/systemtest/AllTests19.java
tests/src/test/java/org/aspectj/systemtest/ajc198/Ajc198TestsJava.java [new file with mode: 0644]
tests/src/test/java/org/aspectj/systemtest/ajc198/AllTestsAspectJ198.java [new file with mode: 0644]
tests/src/test/java/org/aspectj/systemtest/ajc198/Java17PreviewFeaturesTests.java [new file with mode: 0644]
tests/src/test/java/org/aspectj/systemtest/ajc198/SanityTestsJava17.java [new file with mode: 0644]
tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml [new file with mode: 0644]
tests/src/test/resources/org/aspectj/systemtest/ajc198/sanity-tests-17.xml [new file with mode: 0644]
util/src/main/java/org/aspectj/util/LangUtil.java

index 285d024b64ea25783f0642fedd4fdb9ad08ab6a9..1ce3682d3e9c18c342b3fdac148ef9ec155bf8ac 100644 (file)
@@ -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 (file)
index 0000000..e20ee7a
--- /dev/null
@@ -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 (file)
index 0000000..1e18e2f
--- /dev/null
@@ -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();
+       }
+
+}
index 4a52e8fe440c3292e2f88b2402b656c326d57f7c..7223aff59b1f6f9787b51b1a16dac757b792c919 100644 (file)
@@ -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 (file)
index 0000000..172d6e1
--- /dev/null
@@ -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 (file)
index 0000000..26d7492
--- /dev/null
@@ -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 (file)
index 0000000..fab7877
--- /dev/null
@@ -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 (file)
index 0000000..4fac5f3
--- /dev/null
@@ -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 (file)
index 0000000..e2dc9fe
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]>
+
+
+<suite>
+
+       <!-- Java ?? final, Java 16, 15 preview -->
+<!--
+       <ajc-test dir="features197/java15" vm="17" title="sealed class with legal subclasses">
+               <compile files="Person.java Employee.java Manager.java" options="&#45;&#45;enable-preview -16" />
+       </ajc-test>
+-->
+
+       <!-- Java ?? final, Java 16, 15 preview -->
+<!--
+       <ajc-test dir="features197/java15" vm="17" title="sealed class with illegal subclass">
+               <compile files="Person.java  Employee.java Manager.java PersonaNonGrata.java" options="&#45;&#45;enable-preview -16">
+                       <message kind="error" file="PersonaNonGrata.java" text="should be a permitted subtype of Person"/>
+               </compile>
+       </ajc-test>
+-->
+
+       <!-- Java ?? final, Java 16, 15 preview -->
+<!--
+       <ajc-test dir="features197/java15" vm="17" title="weave sealed class">
+               <compile files="Person.java Employee.java Manager.java TopManager.java PersonAspect.aj" options="&#45;&#45;enable-preview -16" />
+               <run class="TopManager" vmargs="&#45;&#45;enable-preview">
+                       <stdout>
+                               <line text="Hello Sir John" />
+                               <line text="CEO" />
+                       </stdout>
+               </run>
+       </ajc-test>
+-->
+
+</suite>
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 (file)
index 0000000..70f52fa
--- /dev/null
@@ -0,0 +1,70 @@
+<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]>
+
+<suite>
+
+    <!-- empty class -->
+    <ajc-test dir="bugs160/simplejava" title="simple - a">
+      <compile files="SimpleA.java" options="-17"/>
+    </ajc-test>
+
+    <!-- class with one method -->
+    <ajc-test dir="bugs160/simplejava" title="simple - b">
+      <compile files="SimpleB.java" options="-17"/>
+      <run class="SimpleB"/>
+    </ajc-test>
+
+    <!-- empty aspect -->
+    <ajc-test dir="bugs160/simplejava" title="simple - c">
+      <compile files="SimpleC.java" options="-17"/>
+    </ajc-test>
+
+    <!-- simple before -->
+    <ajc-test dir="bugs160/simplejava" title="simple - d">
+      <compile files="SimpleD.java" options="-17"/>
+    </ajc-test>
+
+    <!-- simple itd field -->
+    <ajc-test dir="bugs160/simplejava" title="simple - e">
+      <compile files="SimpleE.java" options="-17"/>
+    </ajc-test>
+
+    <!-- aspect with main calling a static method -->
+    <ajc-test dir="bugs160/simplejava" title="simple - f">
+      <compile files="SimpleF.java" options="-17"/>
+    </ajc-test>
+
+    <!-- pertarget -->
+    <ajc-test dir="bugs160/simplejava" title="simple - g">
+      <compile files="SimpleG.java" options="-17"/>
+    </ajc-test>
+
+    <!-- generic ctor itds -->
+    <ajc-test dir="bugs160/simplejava" title="simple - h">
+      <compile files="SimpleH.java" options="-17"/>
+    </ajc-test>
+
+    <!-- overriding generic itd methods -->
+    <ajc-test dir="bugs160/simplejava" title="simple - i">
+      <compile files="SimpleI.java" options="-17"/>
+    </ajc-test>
+
+    <!-- check class file version is 60.0 (Java 16) -->
+    <ajc-test dir="bugs160/simplejava" title="simple - j">
+      <compile files="SimpleJ.java" options="-17"/>
+    </ajc-test>
+
+    <!-- check class file version is 60.0 (Java 16) -->
+    <ajc-test dir="bugs160/simplejava" title="simple - k">
+      <compile files="SimpleJ.java" options="-source 16"/>
+    </ajc-test>
+
+    <!-- check class file version is 49.0 -->
+    <ajc-test dir="bugs160/simplejava" title="simple - m">
+      <compile files="SimpleJ.java" options="-1.5"/>
+    </ajc-test>
+
+    <ajc-test dir="bugs160/simplejava" title="simple - n">
+      <compile files="SimpleN.java" options="-17"/>
+    </ajc-test>
+
+</suite>
index c53d1898940245c98d260359e1b7d2301cf71579..187b895b29bacf066bd89b4e34af84309f9d4bfd 100644 (file)
@@ -190,6 +190,10 @@ public class LangUtil {
                return 17 <= vmVersion;
        }
 
+       public static boolean is18VMOrGreater() {
+               return 18 <= vmVersion;
+       }
+
        /**
         * Shorthand for "if null, throw IllegalArgumentException"
         *