]> source.dussan.org Git - aspectj.git/commitdiff
Add some smoke test cases for '--add-reads' and '--add-modules' 146/head
authorAlexander Kriegisch <Alexander@Kriegisch.name>
Thu, 31 Mar 2022 04:31:20 +0000 (11:31 +0700)
committerAlexander Kriegisch <Alexander@Kriegisch.name>
Thu, 31 Mar 2022 07:14:45 +0000 (14:14 +0700)
in order to show that the compiler options basically work. The test
cases are by no means exhaustive and simply verify that it works at all.

Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
tests/bugs199/add_exports/Application.java [deleted file]
tests/bugs199/github_145/add_exports/Application.java [new file with mode: 0644]
tests/bugs199/github_145/add_modules/NonModular.java [new file with mode: 0644]
tests/bugs199/github_145/add_modules/UseJDKExtendedCharsets.java [new file with mode: 0644]
tests/bugs199/github_145/add_modules/my.module/module-info.java [new file with mode: 0644]
tests/bugs199/github_145/add_modules/my.module/my/module/Modular.java [new file with mode: 0644]
tests/bugs199/github_145/add_reads/other.module/module-info.java [new file with mode: 0644]
tests/bugs199/github_145/add_reads/other.module/other/module/Application.java [new file with mode: 0644]
tests/src/test/java/org/aspectj/systemtest/ajc199/Bugs199Tests.java
tests/src/test/resources/org/aspectj/systemtest/ajc199/ajc199.xml

diff --git a/tests/bugs199/add_exports/Application.java b/tests/bugs199/add_exports/Application.java
deleted file mode 100644 (file)
index 88bd177..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-import sun.security.x509.X509CertInfo;
-
-import java.security.cert.CertificateParsingException;
-
-/**
- * https://github.com/mojohaus/aspectj-maven-plugin/issues/139
- */
-public class Application {
-  public static void main(String[] args) {
-    try {
-      new X509CertInfo(new byte[0]);
-    }
-    catch (CertificateParsingException e) {
-      System.out.println(e);
-    }
-  }
-}
diff --git a/tests/bugs199/github_145/add_exports/Application.java b/tests/bugs199/github_145/add_exports/Application.java
new file mode 100644 (file)
index 0000000..88bd177
--- /dev/null
@@ -0,0 +1,17 @@
+import sun.security.x509.X509CertInfo;
+
+import java.security.cert.CertificateParsingException;
+
+/**
+ * https://github.com/mojohaus/aspectj-maven-plugin/issues/139
+ */
+public class Application {
+  public static void main(String[] args) {
+    try {
+      new X509CertInfo(new byte[0]);
+    }
+    catch (CertificateParsingException e) {
+      System.out.println(e);
+    }
+  }
+}
diff --git a/tests/bugs199/github_145/add_modules/NonModular.java b/tests/bugs199/github_145/add_modules/NonModular.java
new file mode 100644 (file)
index 0000000..6bdaffa
--- /dev/null
@@ -0,0 +1,9 @@
+import my.module.Modular;
+
+public class NonModular {
+  Modular modular = new Modular();
+
+  public static void main(String[] args) {
+    System.out.println("Non-modular class can use modular one");
+  }
+}
diff --git a/tests/bugs199/github_145/add_modules/UseJDKExtendedCharsets.java b/tests/bugs199/github_145/add_modules/UseJDKExtendedCharsets.java
new file mode 100644 (file)
index 0000000..423d564
--- /dev/null
@@ -0,0 +1,17 @@
+import java.nio.charset.Charset;
+import sun.nio.cs.ext.ExtendedCharsets;
+
+public class UseJDKExtendedCharsets {
+  static ExtendedCharsets charsets = new ExtendedCharsets();
+  static Charset iso2022jp = charsets.charsetForName("ISO-2022-JP");
+  static Charset jis = charsets.charsetForName("jis");
+  static Charset jis_encoding = charsets.charsetForName("jis_encoding");
+
+  public static void main(String[] args) {
+    // The 3 charsets are aliases of each other
+    assert iso2022jp != null;
+    System.out.println(iso2022jp);
+    assert iso2022jp.equals(jis);
+    assert iso2022jp.equals(jis_encoding);
+  }
+}
diff --git a/tests/bugs199/github_145/add_modules/my.module/module-info.java b/tests/bugs199/github_145/add_modules/my.module/module-info.java
new file mode 100644 (file)
index 0000000..beee5b5
--- /dev/null
@@ -0,0 +1,3 @@
+module my.module {
+  //exports my.module;
+}
diff --git a/tests/bugs199/github_145/add_modules/my.module/my/module/Modular.java b/tests/bugs199/github_145/add_modules/my.module/my/module/Modular.java
new file mode 100644 (file)
index 0000000..febc7f8
--- /dev/null
@@ -0,0 +1,3 @@
+package my.module;
+
+public class Modular {}
diff --git a/tests/bugs199/github_145/add_reads/other.module/module-info.java b/tests/bugs199/github_145/add_reads/other.module/module-info.java
new file mode 100644 (file)
index 0000000..3cc4823
--- /dev/null
@@ -0,0 +1,3 @@
+module other.module {
+  exports other.module;
+}
diff --git a/tests/bugs199/github_145/add_reads/other.module/other/module/Application.java b/tests/bugs199/github_145/add_reads/other.module/other/module/Application.java
new file mode 100644 (file)
index 0000000..ff29901
--- /dev/null
@@ -0,0 +1,15 @@
+package other.module;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import my.module.Modular;
+
+public class Application {
+  List<String> list = new ArrayList<>();
+  Modular modular = new Modular();
+
+  public static void main(String[] args) {
+    System.out.println("One modular class can use another one");
+  }
+}
index a9f7f302317cc9bd49c9f1ba81fedcd98d8eed77..5b2087ed21b57c29b906d4772b90754767c0115f 100644 (file)
@@ -61,10 +61,22 @@ public class Bugs199Tests extends XMLBasedAjcTestCase {
     runTest("asynchronous proceed for nested around-advice (native, thread pool)");
   }
 
-  public void testAddExports() {
+  public void testAddExports_gh145() {
     runTest("use --add-exports");
   }
 
+  public void testAddReads_gh145() {
+    runTest("use --add-reads");
+  }
+
+  public void testAddModules_gh145() {
+    runTest("use --add-modules");
+  }
+
+  public void testAddModulesJDK_gh145() {
+    runTest("use --add-modules with non-public JDK module");
+  }
+
   public static Test suite() {
     return XMLBasedAjcTestCase.loadSuite(Bugs199Tests.class);
   }
index 9a9ac2d47e2852e2083ca6e1aa1e327fc4442978..7c38db68e5bedd94f490ece148d752bca1182205 100644 (file)
                </run>
        </ajc-test>
 
-       <ajc-test dir="bugs199/add_exports" title="use --add-exports" vm="9">
-               <compile files="Application.java" options="-11 --add-exports java.base/sun.security.x509=ALL-UNNAMED" />
-               <run class="Application" vmargs="--add-exports java.base/sun.security.x509=ALL-UNNAMED">
+       <ajc-test dir="bugs199/github_145/add_exports" title="use --add-exports" vm="9">
+               <compile
+                       files="Application.java"
+                       options="-9 --add-exports java.base/sun.security.x509=ALL-UNNAMED"
+               />
+               <run
+                       class="Application"
+                       vmargs="--add-exports java.base/sun.security.x509=ALL-UNNAMED"
+               >
                        <stdout>
                                <line text="java.security.cert.CertificateParsingException: java.io.IOException"/>
                        </stdout>
                </run>
        </ajc-test>
 
+       <ajc-test dir="bugs199/github_145" title="use --add-reads" vm="9">
+               <compile
+                       files="add_modules/my.module/module-info.java add_modules/my.module/my/module/Modular.java"
+                       options="-9"
+                       outjar="my.module.jar"
+               />
+               <compile
+                       files="add_reads/other.module/module-info.java add_reads/other.module/other/module/Application.java"
+                       options="-9 --add-reads other.module=my.module --add-exports my.module/my.module=other.module"
+                       modulepath="$sandbox/my.module.jar"
+                       outjar="other.module.jar"
+               />
+               <run
+                       class="other.module.Application"
+                       vmargs="--add-reads other.module=my.module"
+                       modulepath="$sandbox/my.module.jar:$sandbox/other.module.jar"
+               >
+                       <stdout>
+                               <line text="One modular class can use another one"/>
+                       </stdout>
+               </run>
+       </ajc-test>
+
+       <ajc-test dir="bugs199/github_145/add_modules" title="use --add-modules" vm="9">
+               <compile
+                       files="my.module/module-info.java my.module/my/module/Modular.java"
+                       options="-9"
+                       outjar="my.module.jar"
+               />
+               <compile
+                       files="NonModular.java"
+                       options="-9 --add-modules my.module --add-exports my.module/my.module=ALL-UNNAMED"
+                       modulepath="$sandbox/my.module.jar"
+               />
+               <run class="NonModular" modulepath="$sandbox/my.module.jar">
+                       <stdout>
+                               <line text="Non-modular class can use modular one"/>
+                       </stdout>
+               </run>
+       </ajc-test>
+
+       <ajc-test dir="bugs199/github_145/add_modules" title="use --add-modules with non-public JDK module" vm="9">
+               <!--
+                       Javac, AJC: no errors. ECJ: "invalid module name: jdk.charsets"
+
+                       This is because ECJ does not add internal JDK modules as root modules, but AJC does. This was not so much
+                       intentional in AJC, but simply due to the hacky implementation. Anyway, it works and makes AJC more
+                       Javac-compliant than ECJ, which is nice.
+               -->
+               <compile files="UseJDKExtendedCharsets.java" options="-9 --add-modules jdk.charsets --add-exports jdk.charsets/sun.nio.cs.ext=ALL-UNNAMED" />
+               <run class="UseJDKExtendedCharsets" vmargs="-ea --add-modules jdk.charsets --add-exports jdk.charsets/sun.nio.cs.ext=ALL-UNNAMED">
+                       <stdout>
+                               <line text="ISO-2022-JP"/>
+                       </stdout>
+               </run>
+       </ajc-test>
+
 </suite>