From: wisberg Date: Sat, 24 May 2003 12:20:52 +0000 (+0000) Subject: Better BuildModule tests following ant.jar updates. X-Git-Tag: V1_1_0~76 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=58e2610e99f2986937656480e8343ba4c2698e8e;p=aspectj.git Better BuildModule tests following ant.jar updates. These now build with assemble-all off and on, and tests were updated to check by running classes. --- diff --git a/build/testsrc/org/aspectj/internal/build/BuildModuleTest.java b/build/testsrc/org/aspectj/internal/build/BuildModuleTest.java index 6bee0a63f..5a82510aa 100644 --- a/build/testsrc/org/aspectj/internal/build/BuildModuleTest.java +++ b/build/testsrc/org/aspectj/internal/build/BuildModuleTest.java @@ -13,16 +13,21 @@ package org.aspectj.internal.build; +import org.apache.tools.ant.*; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.Java; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Commandline.Argument; +import org.aspectj.internal.tools.ant.taskdefs.*; import org.aspectj.internal.tools.ant.taskdefs.BuildModule; +import org.aspectj.internal.tools.build.*; +import org.aspectj.internal.tools.build.Modules; import java.io.File; import java.util.ArrayList; import java.util.Iterator; +import junit.framework.*; import junit.framework.TestCase; /** * @@ -51,6 +56,7 @@ public class BuildModuleTest extends TestCase { } ArrayList tempFiles = new ArrayList(); + private File jarDir; boolean building; // must be enabled for tests to run public BuildModuleTest(String name) { @@ -69,23 +75,35 @@ public class BuildModuleTest extends TestCase { } public void testBuild() { - checkBuild("build", null, null); + checkBuild("build", + Checklics.class.getName(), + new String[0], // help message + true); // ant needed } + public void testAsm() { - checkBuild("asm", null, null); + checkBuild("asm"); } public void testRuntime() { - checkBuild("runtime", null, null); + checkBuild("runtime"); } public void testAjbrowser() { - checkBuild("ajbrowser", null, null); + checkBuild("ajbrowser", + "org.aspectj.tools.ajbrowser.Main", + new String[] {"-noExit", "-version"}); // compiler version } public void testAjdt() { - checkBuild("org.aspectj.ajdt.core", "org.aspectj.tools.ajc.Main", - new String[] { "-version" }); + checkBuild("org.aspectj.ajdt.core", + "org.aspectj.tools.ajc.Main", + new String[] { "-noExit", "-version" }); + } + public void testTestingDrivers() { + checkBuild("testing-drivers", + "org.aspectj.testing.drivers.Harness", + new String[] {"-help"}); } public void testAspectjtools() { @@ -103,6 +121,33 @@ public class BuildModuleTest extends TestCase { checkBuildProduct(productDir, baseDir, distDir, jarDir); } + public void testModuleAntecedantsClipped() { + checkAntClipping("testing-drivers", true); + checkAntClipping("taskdefs", false); + } + + void checkAntClipping(String moduleName, boolean expectAnt) { + File baseDir = new File("..").getAbsoluteFile(); + File jarDir = new File("../aj-build/jars").getAbsoluteFile(); + Messager handler = new Messager(); + Modules modules = new Modules(baseDir, jarDir, false, handler); + Module td = modules.getModule(moduleName); + ArrayList list = td.findKnownJarAntecedants(); + // should include ant + boolean gotAnt = false; + for (Iterator iter = list.iterator(); iter.hasNext();) { + File lib = (File) iter.next(); + if (lib.getPath().endsWith("ant.jar")) { + gotAnt = true; + break; + } + } + String label = (expectAnt ? "expected" : "not expecting") + + " ant in antecedants for " + + moduleName; + assertTrue(label, expectAnt == gotAnt); + } + void checkBuildProduct(File productDir, File baseDir, File distDir, File jarDir) { if (!building) { System.err.println(SKIP_MESSAGE + "product " + productDir); @@ -129,39 +174,92 @@ public class BuildModuleTest extends TestCase { // now run installer and do product tests? } - void checkBuild(String module, String classname, String[] args) { - if (!building) { - System.err.println(SKIP_MESSAGE + "module " + module); - return; + File getAntJar() { + return new File("../lib/ant/lib/ant.jar"); + } + + File getJarDir() { + if (null == jarDir) { + jarDir = new File("tempJarDir"); + tempFiles.add(jarDir); } - assertTrue(null != module); - checkJavac(); - + return jarDir; + } + + BuildModule getTask(String module) { BuildModule task = new BuildModule(); Project project = new Project(); task.setProject(project); - File jarDir = new File("tempJarDir"); + File jarDir = getJarDir(); assertTrue(jarDir.canWrite() || jarDir.mkdirs()); tempFiles.add(jarDir); task.setModuledir(new Path(project, "../" + module)); task.setJardir(new Path(project, jarDir.getAbsolutePath())); - task.setFailonerror(true); + return task; + } + + void checkBuild(String module) { + checkBuild(module, null, null, false); + } + + void checkBuild(String module, + String classname, + String[] args) { + checkBuild(module, classname, args, false); + } + + void checkBuild(String module, + String classname, + String[] args, + boolean addAnt) { + if (!building) { + System.err.println(SKIP_MESSAGE + "module " + module); + return; + } + assertTrue(null != module); + checkJavac(); + + // run without assembly + BuildModule task = getTask(module); + task.setAssembleall(false); task.execute(); + File jar = new File(getJarDir(), module + ".jar"); + assertTrue("cannot read " + jar, jar.canRead()); + assertTrue("cannot delete " + jar, jar.delete()); + + // run with assembly + task = getTask(module); + task.setAssembleall(true); + task.execute(); + jar = new File(getJarDir(), module + "-all.jar"); + assertTrue("cannot read " + jar, jar.canRead()); + // verify if possible if (null == classname) { return; } Java java = new Java(); + Project project = task.getProject(); java.setProject(project); - File jar = new File(jarDir, module + ".jar"); - java.setClasspath(new Path(project, jar.getAbsolutePath())); + Path cp = new Path(project); + cp.append(new Path(project, jar.getAbsolutePath())); + if (addAnt) { + cp.append(new Path(project, getAntJar().getAbsolutePath())); + } + java.setClasspath(cp); java.setClassname(classname); for (int i = 0; i < args.length; i++) { Argument arg = java.createArg(); arg.setValue(args[i]); } - java.execute(); + java.setFailonerror(true); + try { + java.execute(); + } catch (BuildException e) { + e.printStackTrace(System.err); + assertTrue("BuildException running " + classname, false); + } } void checkJavac() {