Browse Source

1.9 test changes and new module tests

tags/V1_9_0_RC3
Andy Clement 6 years ago
parent
commit
d6025b5d3d

+ 1
- 0
tests/src/org/aspectj/systemtest/ajc190/AllTestsAspectJ190.java View 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;

+ 138
- 0
tests/src/org/aspectj/systemtest/ajc190/ModuleTests.java View File

@@ -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");
}

}

+ 42
- 45
tests/src/org/aspectj/systemtest/ajc190/SanityTests19.java View 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);

+ 72
- 0
tests/src/org/aspectj/systemtest/ajc190/ajc190.xml View 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"/>

+ 10
- 0
tests/src/org/aspectj/systemtest/incremental/tools/MultiProjTestCompilerConfiguration.java View 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;
}

}

Loading…
Cancel
Save