]> source.dussan.org Git - aspectj.git/commitdiff
Make sure Java 14-only tests using preview are not executed on JVM 15+
authorAlexander Kriegisch <Alexander@Kriegisch.name>
Sun, 14 Mar 2021 06:58:37 +0000 (13:58 +0700)
committerAlexander Kriegisch <Alexander@Kriegisch.name>
Sun, 14 Mar 2021 06:58:37 +0000 (13:58 +0700)
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>
testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava14Only.java [new file with mode: 0644]
tests/src/test/java/org/aspectj/systemtest/ajc196/Ajc196PreviewFeaturesTests.java [new file with mode: 0644]
tests/src/test/java/org/aspectj/systemtest/ajc196/Ajc196Tests.java
tests/src/test/java/org/aspectj/systemtest/ajc196/AllTestsAspectJ196.java
tests/src/test/resources/org/aspectj/systemtest/ajc196/ajc196.xml

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 (file)
index 0000000..3bdb4d6
--- /dev/null
@@ -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 (file)
index 0000000..f9c6813
--- /dev/null
@@ -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");
+  }
+
+}
index 00bae65e407cd7c325465fc431c0a046c89f0fcc..7ec22410924b9448a2722ec3578fa6a0bbf0dee4 100644 (file)
@@ -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");
+  }
 
 }
index 0cdfe92904f4d580356b7202f34deca0489f7a21..fa2a3aea26d284b5be8839dacb071e944c757399 100644 (file)
@@ -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;
        }
 }
index 69a9fd8bff6c6dea94816fc52631e9bcc430e547..3ef3457d2a6b9b8a95cad85fae347b4e2f2388ee 100644 (file)
@@ -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>
                </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>