]> source.dussan.org Git - aspectj.git/commitdiff
1.9 test changes and new module tests
authorAndy Clement <aclement@pivotal.io>
Fri, 20 Oct 2017 19:35:24 +0000 (12:35 -0700)
committerAndy Clement <aclement@pivotal.io>
Fri, 20 Oct 2017 19:35:24 +0000 (12:35 -0700)
tests/src/org/aspectj/systemtest/ajc190/AllTestsAspectJ190.java
tests/src/org/aspectj/systemtest/ajc190/ModuleTests.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc190/SanityTests19.java
tests/src/org/aspectj/systemtest/ajc190/ajc190.xml
tests/src/org/aspectj/systemtest/incremental/tools/MultiProjTestCompilerConfiguration.java

index 139e99e693e22f1270bcf60ac704b956fec56c7c..4f795f9604cba7ea61330f51759fd08cd0dc4165 100644 (file)
@@ -20,6 +20,7 @@ public class AllTestsAspectJ190 {
                // $JUnit-BEGIN$
                suite.addTest(Ajc190Tests.suite());
                suite.addTest(SanityTests19.suite());
+               suite.addTest(ModuleTests.suite());
                suite.addTest(Annotations.suite());
                // $JUnit-END$
                return suite;
diff --git a/tests/src/org/aspectj/systemtest/ajc190/ModuleTests.java b/tests/src/org/aspectj/systemtest/ajc190/ModuleTests.java
new file mode 100644 (file)
index 0000000..5b5efb1
--- /dev/null
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ * Copyright (c) 2017 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.ajc190;
+
+import java.io.File;
+
+import junit.framework.Test;
+
+import org.aspectj.apache.bcel.classfile.Attribute;
+import org.aspectj.apache.bcel.classfile.Code;
+import org.aspectj.apache.bcel.classfile.JavaClass;
+import org.aspectj.apache.bcel.classfile.Method;
+import org.aspectj.testing.XMLBasedAjcTestCase;
+
+/**
+ * Building and weaving with modules in the picture...
+ * 
+ * @author Andy Clement
+ * 
+ */
+public class ModuleTests extends org.aspectj.testing.XMLBasedAjcTestCase {
+
+       public void testBuildAModule() {
+               runTest("build a module");
+       }
+
+       public void testRunModuleClassPath() {
+               runTest("run a module - classpath");
+       }
+
+       public void testRunModuleModulePath() {
+               runTest("run a module - modulepath");
+       }
+       
+       public void testPackageAndRunModuleFromModulePath() {
+               runTest("package and run a module - modulepath");
+       }
+
+       public void testBuildModuleIncludingAspects() {
+               runTest("compile module including aspects");
+       }
+
+       public void testBinaryWeavingAModuleJar() {
+               // Pass a module on inpath, does it weave ok with a source aspect, does it run afterwards?
+               runTest("binary weaving module");
+       }
+
+       // can't really write these tests now... pure jdt seems to allow type resolution against module path for types
+       // not in modules being compiled but javac does not
+
+       public void xtestReferenceTypesFromModuleInBuildingSomeCode() {
+               runTest("compile regular code using module code");
+       }
+
+       public void xtestReferenceTypesFromModuleInBuildingSomeCodeButCantSeeThem() {
+               runTest("compile regular code using module code that isn't visible");
+       }
+
+       public void xtestBinaryWeavingInvolvingTypesOnModulePath() {
+               fail();
+       }
+
+       public void xtestLoadtimeWeavingWithModulePathContainingTypes() {
+               fail();
+       }
+       
+       /* For the specified class, check that each method has a stackmap attribute */
+       private void checkStackMapExistence(String classname, String toIgnore) throws ClassNotFoundException {
+               toIgnore = "_" + (toIgnore == null ? "" : toIgnore) + "_";
+               JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), classname);
+               Method[] methods = jc.getMethods();
+               for (int i = 0; i < methods.length; i++) {
+                       Method method = methods[i];
+                       if (toIgnore.contains("_" + method.getName() + "_")) {
+                               continue;
+                       }
+                       boolean hasStackMapAttribute = findAttribute(method.getAttributes(), "StackMapTable");
+                       if (!hasStackMapAttribute) {
+                               fail("Could not find StackMap attribute for method " + method.getName());
+                       }
+               }
+       }
+
+       private boolean findAttribute(Attribute[] attrs, String attributeName) {
+               if (attrs == null) {
+                       return false;
+               }
+               for (int i = 0; i < attrs.length; i++) {
+                       Attribute attribute = attrs[i];
+                       if (attribute.getName().equals(attributeName)) {
+                               return true;
+                       }
+                       // System.out.println(attribute.getName());
+                       if (attribute.getName().equals("Code")) {
+                               Code c = (Code) attribute;
+                               Attribute[] codeAttributes = c.getAttributes();
+                               for (int j = 0; j < codeAttributes.length; j++) {
+                                       Attribute codeAttribute = codeAttributes[j];
+                                       if (codeAttribute.getName().equals(attributeName)) {
+                                               return true;
+                                               // System.out.println(codeAttribute.getName());
+                                       }
+                               }
+                       }
+               }
+               return false;
+       }
+
+       private void checkVersion(String classname, int major, int minor) throws ClassNotFoundException {
+               JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), classname);
+               if (jc.getMajor() != major) {
+                       fail("Expected major version to be " + major + " but was " + jc.getMajor());
+               }
+               if (jc.getMinor() != minor) {
+                       fail("Expected minor version to be " + minor + " but was " + jc.getMinor());
+               }
+       }
+
+       // Check the stackmap stuff is removed when a method gets woven (for now...)
+       // public void testStackMapAttributesDeletedInWovenCode() {
+       // fail("Not implemented");
+       // }
+
+       // ///////////////////////////////////////
+       public static Test suite() {
+               return XMLBasedAjcTestCase.loadSuite(ModuleTests.class);
+       }
+
+       protected File getSpecFile() {
+               return getClassResource("ajc190.xml");
+       }
+
+}
index 3317c51d3b90fa55c4158d6b3764f81b6056e994..5544022c4caeb8ce27c22ef8c29a59e5c823a262 100644 (file)
@@ -12,14 +12,11 @@ package org.aspectj.systemtest.ajc190;
 
 import java.io.File;
 
-import junit.framework.Test;
-
-import org.aspectj.apache.bcel.classfile.Attribute;
-import org.aspectj.apache.bcel.classfile.Code;
 import org.aspectj.apache.bcel.classfile.JavaClass;
-import org.aspectj.apache.bcel.classfile.Method;
 import org.aspectj.testing.XMLBasedAjcTestCase;
 
+import junit.framework.Test;
+
 /*
  * 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 -1.9 option
@@ -88,46 +85,46 @@ public class SanityTests19 extends org.aspectj.testing.XMLBasedAjcTestCase {
        // }
 
        /* For the specified class, check that each method has a stackmap attribute */
-       private void checkStackMapExistence(String classname, String toIgnore) throws ClassNotFoundException {
-               toIgnore = "_" + (toIgnore == null ? "" : toIgnore) + "_";
-               JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), classname);
-               Method[] methods = jc.getMethods();
-               for (int i = 0; i < methods.length; i++) {
-                       Method method = methods[i];
-                       if (toIgnore.contains("_" + method.getName() + "_")) {
-                               continue;
-                       }
-                       boolean hasStackMapAttribute = findAttribute(method.getAttributes(), "StackMapTable");
-                       if (!hasStackMapAttribute) {
-                               fail("Could not find StackMap attribute for method " + method.getName());
-                       }
-               }
-       }
-
-       private boolean findAttribute(Attribute[] attrs, String attributeName) {
-               if (attrs == null) {
-                       return false;
-               }
-               for (int i = 0; i < attrs.length; i++) {
-                       Attribute attribute = attrs[i];
-                       if (attribute.getName().equals(attributeName)) {
-                               return true;
-                       }
-                       // System.out.println(attribute.getName());
-                       if (attribute.getName().equals("Code")) {
-                               Code c = (Code) attribute;
-                               Attribute[] codeAttributes = c.getAttributes();
-                               for (int j = 0; j < codeAttributes.length; j++) {
-                                       Attribute codeAttribute = codeAttributes[j];
-                                       if (codeAttribute.getName().equals(attributeName)) {
-                                               return true;
-                                               // System.out.println(codeAttribute.getName());
-                                       }
-                               }
-                       }
-               }
-               return false;
-       }
+//     private void checkStackMapExistence(String classname, String toIgnore) throws ClassNotFoundException {
+//             toIgnore = "_" + (toIgnore == null ? "" : toIgnore) + "_";
+//             JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), classname);
+//             Method[] methods = jc.getMethods();
+//             for (int i = 0; i < methods.length; i++) {
+//                     Method method = methods[i];
+//                     if (toIgnore.contains("_" + method.getName() + "_")) {
+//                             continue;
+//                     }
+//                     boolean hasStackMapAttribute = findAttribute(method.getAttributes(), "StackMapTable");
+//                     if (!hasStackMapAttribute) {
+//                             fail("Could not find StackMap attribute for method " + method.getName());
+//                     }
+//             }
+//     }
+
+//     private boolean findAttribute(Attribute[] attrs, String attributeName) {
+//             if (attrs == null) {
+//                     return false;
+//             }
+//             for (int i = 0; i < attrs.length; i++) {
+//                     Attribute attribute = attrs[i];
+//                     if (attribute.getName().equals(attributeName)) {
+//                             return true;
+//                     }
+//                     // System.out.println(attribute.getName());
+//                     if (attribute.getName().equals("Code")) {
+//                             Code c = (Code) attribute;
+//                             Attribute[] codeAttributes = c.getAttributes();
+//                             for (int j = 0; j < codeAttributes.length; j++) {
+//                                     Attribute codeAttribute = codeAttributes[j];
+//                                     if (codeAttribute.getName().equals(attributeName)) {
+//                                             return true;
+//                                             // System.out.println(codeAttribute.getName());
+//                                     }
+//                             }
+//                     }
+//             }
+//             return false;
+//     }
 
        private void checkVersion(String classname, int major, int minor) throws ClassNotFoundException {
                JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), classname);
index c2cb7cee88946ab484a18779510d7f6539f9540e..c2da5de602ee3197ae56b23313cc866d844520e0 100644 (file)
@@ -2,10 +2,82 @@
 
 <suite>
 
+  <ajc-test dir="bugs190/modules/aaa" title="build a module">
+    <compile files="module-info.java com/foo1/C1.java" options="-1.9"/>
+  </ajc-test>
+
+  <ajc-test dir="bugs190/modules/bbb" title="run a module - classpath">
+    <compile files="module-info.java aaa/bbb/A.java" options="-1.9"/>
+    <run class="aaa.bbb.A">
+    <stdout>
+    <line text="A running"/>
+    </stdout>
+    </run>
+  </ajc-test>
+
+  <ajc-test dir="bugs190/modules/bbb" title="run a module - modulepath">
+    <compile files="module-info.java aaa/bbb/A.java" options="-1.9"/>
+    <run modulepath="$sandbox" module="my.module/aaa.bbb.A">
+    <stdout>
+    <line text="A running"/>
+    </stdout>
+    </run>
+  </ajc-test>
+  
+  <ajc-test dir="bugs190/modules/bbb" title="package and run a module - modulepath">
+    <compile files="module-info.java aaa/bbb/A.java" options="-1.9" outjar="my.module.jar"/>
+       <file deletefile="module-info.java"/>
+    <file deletefile="aaa"/>
+    <run modulepath="my.module.jar" module="my.module/aaa.bbb.A">
+    <stdout>
+    <line text="A running"/>
+    </stdout>
+    </run>
+   </ajc-test>
+  
+  <ajc-test dir="bugs190/modules/ccc" title="compile regular code using module code">
+    <compile files="module-info.java aaa/bbb/A.java" options="-1.9" outjar="modules/my.module.jar"/>
+    <file deletefile="module-info.java"/>
+    <file deletefile="aaa"/>
+    <compile files="InvokeA.java" options="-1.9" modulepath="$sandbox/modules/my.module.jar"/>
+  </ajc-test>
+  
+  <ajc-test dir="bugs190/modules/ddd" title="compile regular code using module code that isn't visible">
+    <compile files="module-info.java aaa/bbb/A.java" options="-1.9" outjar="modules/my.module.jar"/>
+    <compile files="InvokeA.java" options="-1.9" modulepath="$sandbox/modules/my.module.jar">
+               <message kind="error" text="package aaa.bbb is not visible"/>
+    </compile>
+  </ajc-test>
+
+
+  <ajc-test dir="bugs190/modules/eee" title="binary weaving module">
+    <compile files="module-info.java aaa/bbb/A.java" options="-1.9" outjar="my.module.jar"/>
+    <file deletefile="module-info.java"/>
+    <file deletefile="aaa"/>
+    <compile files="Azpect.java" inpath="my.module.jar" outjar="my.module.woven.jar"/>
+    <run modulepath="my.module.woven.jar" module="my.module/aaa.bbb.A">
+      <stdout>
+      <line text="Azpect running"/>
+      <line text="A running"/>
+      </stdout>
+    </run>
+  </ajc-test>
+
+
   <ajc-test dir="bugs190/520135" title="funny signature with method reference">
     <compile files="FailsApectJ.java" options="-1.8"/>
   </ajc-test>
 
+  <ajc-test dir="bugs190/modules/fff" title="compile module including aspects">
+    <compile files="module-info.java pkg/Demo.java otherpkg/Azpect.java" modulepath="$runtime" outjar="demomodule.jar" options="-1.9"/>
+    <run modulepath="$runtime:demomodule.jar" module="demo/pkg.Demo">
+      <stdout>
+      <line text="Azpect running"/>
+      <line text="Demo running"/>
+      </stdout>
+    </run>
+  </ajc-test>
+  
   <ajc-test dir="bugs190/modules" title="weave module">
     <compile files="aspect1/Azpect1.java" inpath="module1/module-one.jar" outjar="runner.jar" options="-1.8"/>
     <java classpath="runner.jar" class="a.b.c.Code"/>
index a07bd87aa5140278021866aa1c05fd1d3826a8c6..cd80218b2636b756bdaf703e90897b9c8c8574d7 100644 (file)
@@ -262,4 +262,14 @@ public class MultiProjTestCompilerConfiguration implements ICompilerConfiguratio
                return this.processorPath;
        }
 
+       @Override
+       public String getModulepath() {
+               return null;
+       }
+
+       @Override
+       public String getModuleSourcepath() {
+               return null;
+       }
+
 }