diff options
author | wisberg <wisberg> | 2002-12-16 17:58:19 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2002-12-16 17:58:19 +0000 |
commit | d842c4f1139629c1f062b74ba818d233b2c31043 (patch) | |
tree | 842d3871620bc0eb60edcd95e55804d67e0f61fa /taskdefs/testsrc | |
parent | 3ce247199704eae6b2c92c6e38c69584e3250c52 (diff) | |
download | aspectj-d842c4f1139629c1f062b74ba818d233b2c31043.tar.gz aspectj-d842c4f1139629c1f062b74ba818d233b2c31043.zip |
initial version
Diffstat (limited to 'taskdefs/testsrc')
4 files changed, 366 insertions, 0 deletions
diff --git a/taskdefs/testsrc/TaskdefsModuleTests.java b/taskdefs/testsrc/TaskdefsModuleTests.java new file mode 100644 index 000000000..df92e50cd --- /dev/null +++ b/taskdefs/testsrc/TaskdefsModuleTests.java @@ -0,0 +1,28 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +// default package + +import junit.framework.*; + +public class TaskdefsModuleTests extends TestCase { + + public static Test suite() { + TestSuite suite = new TestSuite(TaskdefsModuleTests.class.getName()); + suite.addTest(org.aspectj.tools.ant.taskdefs.TaskdefsTests.suite()); + return suite; + } + + public TaskdefsModuleTests(String name) { super(name); } +} diff --git a/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java new file mode 100644 index 000000000..035c0546a --- /dev/null +++ b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java @@ -0,0 +1,251 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +package org.aspectj.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.taskdefs.Ant; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.selectors.FilenameSelector; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.IMessageHandler; +import org.aspectj.bridge.IMessageHolder; +import org.aspectj.bridge.MessageHandler; +import org.aspectj.bridge.MessageUtil; +import org.aspectj.util.FileUtil; +import org.aspectj.util.LangUtil; + +import java.io.File; + +import junit.framework.TestCase; + +/** + * + */ +public class AjcTaskTest extends TestCase { + + private static final Class NO_EXCEPTION = null; + private static final String NOFILE = "NOFILE"; + + private static File tempDir; + + private static void deleteTempDir() { + if ((null != tempDir) && tempDir.exists()) { + FileUtil.deleteContents(tempDir); + tempDir.delete(); + } + } + private static final File getTempDir() { + if (null == tempDir) { + tempDir = new File("IncrementalAjcTaskTest-temp"); + } + return tempDir; + } + + public AjcTaskTest(String name) { + super(name); + } + + public void tearDown() { + deleteTempDir(); + } + + protected AjcTask getTask(String input) { + AjcTask task = new AjcTask(); + Project p = new Project(); + task.setProject(p); + task.setDestdir(getTempDir()); + if (NOFILE.equals(input)) { + // add nothing + } else if (input.endsWith(".lst")) { + if (-1 != input.indexOf(",")) { + task.setArgfiles(input); + } else { + task.setArgfile(new File(input)); + } + } else if ((input.endsWith(".java") || input.endsWith(".aj"))) { + // not working + FilenameSelector fns = new FilenameSelector(); + fns.setName(input); + task.addFilename(fns); + } else { + File dir = new File(input); + if (dir.canRead() && dir.isDirectory()) { + task.setSourceRoots(new Path(task.getProject(), input)); + } + } + task.setVerbose(true); // XXX + return task; + } + + // ---------------------------------------- argfile + public void testDefaultList() { + AjcTask task = getTask("testdata/default.lst"); + runTest(task, NO_EXCEPTION, IMessageHolderChecker.INFOS); + } + + public void testCompileErrorList() { + AjcTask task = getTask("testdata/compileError.lst"); + runTest(task, NO_EXCEPTION, IMessageHolderChecker.ONE_ERROR); + } + + public void testCompileWarningList() { + AjcTask task = getTask("testdata/compileWarning.lst"); + runTest(task, NO_EXCEPTION, IMessageHolderChecker.ONE_WARNING); + } + + public void testNoSuchFileList() { + AjcTask task = getTask("testdata/NoSuchFile.lst"); + runTest(task, NO_EXCEPTION, IMessageHolderChecker.ONE_ERROR); + } + + // ---------------------------------------- ant drivers? + // doesn't work.. +// public void testAntScript() { +// Ant ant = new Ant(); +// ant.setProject(new Project()); +// ant.setDir(new File(".")); +// ant.setAntfile("test-build.xml"); +// ant.execute(); +// } + // ---------------------------------------- sourcefile + public void testDefaultFile() { + AjcTask task = getTask("testdata/Default.java"); + runTest(task, NO_EXCEPTION, IMessageHolderChecker.INFOS); + } + + + public void testNoFile() { + AjcTask task = getTask(NOFILE); + runTest(task, NO_EXCEPTION, IMessageHolderChecker.ONE_ERROR); + } + + // XXX find out how to feed files into MatchingTask +// public void testCompileErrorFile() { +// AjcTask task = getTask("testdata/CompilerError.java"); +// runTest(task, NO_EXCEPTION, IMessageHolderChecker.ONE_ERROR); +// } +// +// public void testCompileWarningFile() { +// AjcTask task = getTask("testdata/CompilerWarning.lst"); +// runTest(task, NO_EXCEPTION, IMessageHolderChecker.ONE_WARNING); +// } +// +// public void testNoSuchFile() { +// AjcTask task = getTask("testdata/NoSuchFile.java"); +// runTest(task, NO_EXCEPTION, IMessageHolderChecker.ONE_ERROR); +// } +// +// public void testDefaultFileComplete() { +// AjcTask task = getTask("testdata/Default.java"); +// task.setDebugLevel("none"); +// task.setDeprecation(true); +// task.setFailonerror(false); +// task.setNoExit(true); // ok to override Ant? +// task.setNoImportError(true); +// task.setNowarn(true); +// task.setNoweave(true); +// task.setPreserveAllLocals(true); +// task.setProceedOnError(true); +// task.setReferenceInfo(true); +// task.setSource("1.3"); +// task.setTarget("1.1"); +// task.setTime(true); +// task.setVerbose(true); +// task.setXlintenabled(true); +// runTest(task, NO_EXCEPTION, IMessageHolderChecker.INFOS); +// } + + protected void runTest( + AjcTask task, + Class exceptionType, + IMessageHolderChecker checker) { + Throwable thrown = null; + MessageHandler holder = new MessageHandler(); + task.setMessageHolder(holder); + try { + task.execute(); + } catch (Throwable t) { + thrown = t; + } finally { + deleteTempDir(); + } + if (null == exceptionType) { + if (null != thrown) { + assertTrue("thrown: " + render(thrown), false); + } + } else if (null == thrown) { + assertTrue("expected " + exceptionType.getName(), false); + } else if (!(exceptionType.isAssignableFrom(thrown.getClass()))) { + assertTrue("expected " + exceptionType.getName() + + " got " + render(thrown), false); + } + if (null == checker) { + checker = IMessageHolderChecker.NONE; + } + checker.check(holder); + } + + protected String render(Throwable thrown) { + return LangUtil.renderException(thrown); + } + + static class IMessageHolderChecker { // XXX export to testing-utils + /** use as value to ignore results */ + static int IGNORE = Integer.MIN_VALUE; + + static IMessageHolderChecker NONE = + new IMessageHolderChecker(0,0,0,0,0); + /** any number (0+) of info messages */ + static IMessageHolderChecker INFOS = + new IMessageHolderChecker(0,0,0,0,IGNORE); + /** one error, any number of info messages */ + static IMessageHolderChecker ONE_ERROR= + new IMessageHolderChecker(0,0,1,0,IGNORE); + /** one warning, any number of info messages */ + static IMessageHolderChecker ONE_WARNING = + new IMessageHolderChecker(0,0,0,1,IGNORE); + + int aborts, fails, errors, warnings, infos; + public IMessageHolderChecker(int aborts, int fails, int errors, int warnings, int infos) { + this.aborts = aborts; + this.fails = fails; + this.errors = errors; + this.warnings = warnings; + this.infos = infos; + } + public void check(IMessageHolder holder) { + boolean failed = true; + try { + check(holder, aborts, IMessage.ABORT); + check(holder, fails, IMessage.FAIL); + check(holder, errors, IMessage.ERROR); + check(holder, warnings,IMessage.WARNING); + check(holder, infos, IMessage.INFO); + failed = false; + } finally { + if (failed) { + MessageUtil.print(System.err, holder, "failed?"); + } + } + } + + private void check(IMessageHolder holder, int num, IMessage.Kind kind) { + if (num != IGNORE) { + assertEquals(num, holder.numMessages(kind, false)); + } + } + } +} diff --git a/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjdocTest.java b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjdocTest.java new file mode 100644 index 000000000..b58362e4c --- /dev/null +++ b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjdocTest.java @@ -0,0 +1,55 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +package org.aspectj.tools.ant.taskdefs; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.Path; + +import java.io.File; + +import junit.framework.TestCase; + +/** + * + */ +public class AjdocTest extends TestCase { + + public AjdocTest(String name) { + super(name); + } + + public void testSource14() { + new File("bin/AjdocTest").mkdirs(); + + Ajdoc task = new Ajdoc(); + Project p = new Project(); + task.setProject(p); + // XXX restore when ajdoc is restored +// task.setSource("1.4"); +// task.setSourcepath(new Path(p, "testdata")); +// task.setIncludes("Ajdoc14Source.java"); +// task.setDestdir("bin/AjdocTest"); +// task.setClasspath(new Path(p, "../lib/test/aspectjrt.jar")); + task.execute(); + } +// public void testHelp() { +// Ajdoc task = new Ajdoc(); +// Project p = new Project(); +// task.setProject(p); +// task.setSourcepath(new Path(p, "testdata")); +// task.setIncludes("none"); +// task.setDestdir("bin/AjdocTest"); +// task.execute(); +// } +} diff --git a/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/TaskdefsTests.java b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/TaskdefsTests.java new file mode 100644 index 000000000..8971936c1 --- /dev/null +++ b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/TaskdefsTests.java @@ -0,0 +1,32 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.tools.ant.taskdefs; + +import junit.framework.*; + +public class TaskdefsTests extends TestCase { + + public static Test suite() { + TestSuite suite = new TestSuite(TaskdefsTests.class.getName()); + //$JUnit-BEGIN$ + suite.addTestSuite(AjdocTest.class); + suite.addTestSuite(AjcTaskTest.class); + //$JUnit-END$ + return suite; + } + + public TaskdefsTests(String name) { super(name); } + +} |