private static final File tempDir;
private static final String aspectjtoolsJar;
private static final String testdataDir;
+ private static final StringBuffer MESSAGES = new StringBuffer();
static {
tempDir = new File("IncrementalAjcTaskTest-temp");
}
}
+ public static void collectMessage(String s) {
+ MESSAGES.append(s);
+ }
+
private static void deleteTempDir() {
if ((null != tempDir) && tempDir.exists()) {
FileUtil.deleteContents(tempDir);
public void tearDown() {
deleteTempDir();
+ MESSAGES.setLength(0);
}
public void testLimitTo() {
return task;
}
+ /** used in testMessageHolderClassName */
+ public static class Holder extends MessageHandler {
+ public Holder() {}
+ public boolean handleMessage(IMessage message) {
+ IMessage.Kind kind = message.getKind();
+ if (IMessage.ERROR.isSameOrLessThan(kind)) {
+ String m = kind.toString();
+ AjcTaskTest.collectMessage(m.substring(0,1));
+ }
+ return true;
+ }
+ }
+
+ public void testMessageHolderClassName() {
+ AjcTask task = getTask("compileError.lst");
+ task.setFailonerror(false);
+ MESSAGES.setLength(0);
+ runTest(task, null, MessageHolderChecker.ONE_ERROR,
+ Holder.class.getName());
+ String result = MESSAGES.toString();
+ MESSAGES.setLength(0);
+ assertEquals("messages", "e", result);
+ }
+
public void testDefaultListForkedNoTools() {
AjcTask task = getTask("default.lst");
task.setFork(true);
assertTrue("expecting aspectj in classpath",
(-1 != classpath.indexOf("aspectjrt.jar")));
}
-
+
// ---------------------------------------- sourcefile
// XXX need to figure out how to specify files directly programmatically
// public void testDefaultFile() {
runTest(task, NO_EXCEPTION, MessageHolderChecker.ONE_ERROR_ONE_ABORT);
}
-
- // XXX find out how to feed files into MatchingTask
-
public void testCompileErrorFile() {
AjcTask task = getTask("compileError.lst");
task.setFailonerror(false);
runTest(task, NO_EXCEPTION, MessageHolderChecker.INFOS);
}
+ protected void runTest(
+ AjcTask task,
+ Class exceptionType,
+ MessageHolderChecker checker,
+ String messageHolderClass) {
+ task.setMessageHolderClass(messageHolderClass);
+ runTest(task, exceptionType, checker, (MessageHandler) null);
+ }
+
protected void runTest(
AjcTask task,
Class exceptionType,
MessageHolderChecker checker) {
- Throwable thrown = null;
MessageHandler holder = new MessageHandler();
task.setMessageHolder(holder);
+ runTest(task, exceptionType, checker, holder);
+ }
+
+ protected void runTest(
+ AjcTask task,
+ Class exceptionType,
+ MessageHolderChecker checker,
+ MessageHandler holder) {
+ Throwable thrown = null;
// re-run forked iff tools.jar and expect to pass
boolean rerunForked
= ((null != aspectjtoolsJar)
assertTrue(label + "expected " + exceptionType.getName()
+ " got " + render(thrown), false);
}
- if (null == checker) {
- checker = MessageHolderChecker.NONE;
+ if (null != holder) {
+ if (null == checker) {
+ checker = MessageHolderChecker.NONE;
+ }
+ checker.check(holder, label);
}
- checker.check(holder, label);
if (!rerunForked) {
break;
} else {