summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/OutjarTest.java6
-rw-r--r--org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/Ajc.java5
-rw-r--r--org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java22
-rw-r--r--org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/CompilationResult.java29
-rw-r--r--org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/MainTest.java2
-rw-r--r--testing/newsrc/org/aspectj/testing/AjcTest.java42
-rw-r--r--testing/newsrc/org/aspectj/testing/CompileSpec.java13
-rw-r--r--testing/newsrc/org/aspectj/testing/OutputLine.java36
-rw-r--r--testing/newsrc/org/aspectj/testing/OutputSpec.java56
-rw-r--r--testing/newsrc/org/aspectj/testing/RunSpec.java15
-rw-r--r--testing/newsrc/org/aspectj/testing/WeaveSpec.java167
-rw-r--r--testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java12
12 files changed, 385 insertions, 20 deletions
diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/OutjarTest.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/OutjarTest.java
index 866fa523c..ee3be8814 100644
--- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/OutjarTest.java
+++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/OutjarTest.java
@@ -50,7 +50,7 @@ public class OutjarTest extends AjcTestCase {
String[] args = new String[] {"-aspectpath", aspectjarName, "-injars", injarName, "-outjar", injarName};
Message error = new Message(WeaverMessages.format(WeaverMessages.OUTJAR_IN_INPUT_PATH));
Message fail = new Message("Usage:");
- MessageSpec spec = new MessageSpec(null,null,newMessageList(error),newMessageList(fail));
+ MessageSpec spec = new MessageSpec(null,null,newMessageList(error),newMessageList(fail),null);
CompilationResult result = ajc(baseDir,args);
// System.out.println(result);
assertMessages(result,spec);
@@ -71,7 +71,7 @@ public class OutjarTest extends AjcTestCase {
String[] args = new String[] {"-aspectpath", aspectjarName, "-inpath", injarName, "-outjar", injarName};
Message error = new Message(WeaverMessages.format(WeaverMessages.OUTJAR_IN_INPUT_PATH));
Message fail = new Message("Usage:");
- MessageSpec spec = new MessageSpec(null,null,newMessageList(error),newMessageList(fail));
+ MessageSpec spec = new MessageSpec(null,null,newMessageList(error),newMessageList(fail),null);
CompilationResult result = ajc(baseDir,args);
// System.out.println(result);
assertMessages(result,spec);
@@ -92,7 +92,7 @@ public class OutjarTest extends AjcTestCase {
String[] args = new String[] {"-aspectpath", aspectjarName, "-inpath", injarName, "-outjar", aspectjarName};
Message error = new Message(WeaverMessages.format(WeaverMessages.OUTJAR_IN_INPUT_PATH));
Message fail = new Message("Usage:");
- MessageSpec spec = new MessageSpec(null,null,newMessageList(error),newMessageList(fail));
+ MessageSpec spec = new MessageSpec(null,null,newMessageList(error),newMessageList(fail),null);
CompilationResult result = ajc(baseDir,args);
// System.out.println(result);
assertMessages(result,spec);
diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/Ajc.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/Ajc.java
index abf7eb568..992f8877b 100644
--- a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/Ajc.java
+++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/Ajc.java
@@ -156,6 +156,7 @@ public class Ajc {
List errors = new ArrayList();
List warnings = new ArrayList();
List infos = new ArrayList();
+ List weaves = new ArrayList();
try {
if (!isIncremental && shouldEmptySandbox) {
@@ -170,13 +171,13 @@ public class Ajc {
main.runMain(args,false);
}
addMessagesTo(infos,holder.getMessages(IMessage.INFO,false));
- addMessagesTo(infos,holder.getMessages(IMessage.WEAVEINFO,false));
addMessagesTo(warnings,holder.getWarnings());
addMessagesTo(errors,holder.getErrors());
addMessagesTo(fails,holder.getMessages(IMessage.FAIL,true));
+ addMessagesTo(weaves,holder.getMessages(IMessage.WEAVEINFO,false));
String stdOut = new String(out.toByteArray());
String stdErr = new String(err.toByteArray());
- result = new CompilationResult(args,stdOut,stdErr,infos,errors,warnings,fails);
+ result = new CompilationResult(args,stdOut,stdErr,infos,errors,warnings,fails,weaves);
} finally {
System.setOut(systemOut);
System.setErr(systemErr);
diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java
index 168179a9d..9e4346674 100644
--- a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java
+++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java
@@ -238,6 +238,7 @@ public class AjcTestCase extends TestCase {
null,
Collections.EMPTY_LIST,
Collections.EMPTY_LIST,
+ Collections.EMPTY_LIST,
Collections.EMPTY_LIST);
boolean ignoreInfos = true;
@@ -245,6 +246,7 @@ public class AjcTestCase extends TestCase {
public List infos;
public List warnings;
public List errors;
+ public List weaves;
/**
* Set to true to enable or disable comparison of information messages.
@@ -272,7 +274,7 @@ public class AjcTestCase extends TestCase {
* @param fails The set of fail or abort messages to test for - can pass null to indicate
* empty set.
*/
- public MessageSpec(List infos, List warnings, List errors, List fails) {
+ public MessageSpec(List infos, List warnings, List errors, List fails, List weaves) {
if (infos != null) {
this.infos = infos;
ignoreInfos = false;
@@ -282,6 +284,7 @@ public class AjcTestCase extends TestCase {
this.warnings = ((warnings == null) ? Collections.EMPTY_LIST : warnings);
this.errors = ((errors == null) ? Collections.EMPTY_LIST : errors);
this.fails = ((fails == null) ? Collections.EMPTY_LIST : fails);
+ this.weaves = ((weaves == null) ? Collections.EMPTY_LIST : weaves);
}
/**
@@ -290,7 +293,7 @@ public class AjcTestCase extends TestCase {
* abort messages in a CompilationResult will be a test failure.
*/
public MessageSpec(List infos, List warnings, List errors) {
- this(infos,warnings,errors,null);
+ this(infos,warnings,errors,null,null);
}
/**
@@ -300,7 +303,7 @@ public class AjcTestCase extends TestCase {
* messages will be ignored.
*/
public MessageSpec(List warnings, List errors) {
- this(null,warnings,errors,null);
+ this(null,warnings,errors,null,null);
}
}
@@ -377,20 +380,23 @@ public class AjcTestCase extends TestCase {
List missingInfos = copyAll(expected.infos);
List missingWarnings = copyAll(expected.warnings);
List missingErrors = copyAll(expected.errors);
+ List missingWeaves = copyAll(expected.weaves);
List extraFails = copyAll(result.getFailMessages());
List extraInfos = copyAll(result.getInfoMessages());
List extraWarnings = copyAll(result.getWarningMessages());
List extraErrors = copyAll(result.getErrorMessages());
+ List extraWeaves = copyAll(result.getWeaveMessages());
compare(expected.fails,result.getFailMessages(),missingFails,extraFails);
compare(expected.warnings,result.getWarningMessages(),missingWarnings,extraWarnings);
compare(expected.errors,result.getErrorMessages(),missingErrors,extraErrors);
if (!expected.isIgnoringInfoMessages()) {
compare(expected.infos,result.getInfoMessages(),missingInfos,extraInfos);
}
+ compare(expected.weaves,result.getWeaveMessages(),missingWeaves,extraWeaves);
boolean infosEmpty = expected.isIgnoringInfoMessages() ? true: (missingInfos.isEmpty() && extraInfos.isEmpty());
- if ( !(missingFails.isEmpty() && missingWarnings.isEmpty() && missingErrors.isEmpty() &&
- extraFails.isEmpty() && extraWarnings.isEmpty() && extraErrors.isEmpty() && infosEmpty)) {
+ if ( !(missingFails.isEmpty() && missingWarnings.isEmpty() && missingErrors.isEmpty() && missingWeaves.isEmpty() &&
+ extraFails.isEmpty() && extraWarnings.isEmpty() && extraErrors.isEmpty() && extraWeaves.isEmpty() && infosEmpty)) {
StringBuffer failureReport = new StringBuffer(message);
failureReport.append("\n");
if (!expected.isIgnoringInfoMessages()) {
@@ -399,12 +405,14 @@ public class AjcTestCase extends TestCase {
addMissing(failureReport,"warning",missingWarnings);
addMissing(failureReport,"error",missingErrors);
addMissing(failureReport,"fail",missingFails);
+ addMissing(failureReport,"weaveInfo",missingWeaves);
if (!expected.isIgnoringInfoMessages()) {
addExtra(failureReport,"info",extraInfos);
}
addExtra(failureReport,"warning",extraWarnings);
addExtra(failureReport,"error",extraErrors);
addExtra(failureReport,"fail",extraFails);
+ addExtra(failureReport,"weaveInfo",extraWeaves);
failureReport.append("\ncommand was: ajc");
String[] args = result.getArgs();
for (int i = 0; i < args.length; i++) {
@@ -477,6 +485,10 @@ public class AjcTestCase extends TestCase {
return null;
}
+ public File getSandboxDirectory() {
+ return ajc.getSandboxDirectory();
+ }
+
/**
* Indicate whether or not the sandbox should be emptied before the next compile.
* @see org.aspectj.tools.ajc.Ajc#setShouldEmptySandbox(boolean)
diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/CompilationResult.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/CompilationResult.java
index 31e2afdfc..c88529f1e 100644
--- a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/CompilationResult.java
+++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/CompilationResult.java
@@ -39,6 +39,7 @@ public class CompilationResult {
private List /*IMessage*/ errorMessages;
private List /*IMessage*/ warningMessages;
private List /*IMessage*/ failMessages;
+ private List /*IMessage*/ weaveMessages;
/**
* Build a compilation result - called by the Ajc.compile and
@@ -52,7 +53,8 @@ public class CompilationResult {
List infoMessages,
List errorMessages,
List warningMessages,
- List failMessages) {
+ List failMessages,
+ List weaveMessages) {
this.args = args;
this.stdOut = stdOut;
this.stdErr = stdErr;
@@ -60,6 +62,7 @@ public class CompilationResult {
this.errorMessages = (errorMessages == null) ? Collections.EMPTY_LIST : errorMessages;
this.warningMessages = (warningMessages == null) ? Collections.EMPTY_LIST : warningMessages;
this.failMessages = (failMessages == null) ? Collections.EMPTY_LIST : failMessages;
+ this.weaveMessages = (weaveMessages == null) ? Collections.EMPTY_LIST : weaveMessages;
}
/**
@@ -78,7 +81,7 @@ public class CompilationResult {
/**
* True if the compiler issued any messages of any kind.
*/
- public boolean hasMessages() { return (hasInfoMessages() || hasErrorMessages() || hasWarningMessages() || hasFailMessages()); }
+ public boolean hasMessages() { return (hasInfoMessages() || hasErrorMessages() || hasWarningMessages() || hasFailMessages() || hasWeaveMessages()); }
/**
* True if the compiler issued one or more informational messages.
*/
@@ -95,7 +98,11 @@ public class CompilationResult {
* True if the compiler issued one or more fail or abort messages.
*/
public boolean hasFailMessages() { return !failMessages.isEmpty(); }
-
+ /**
+ * True if the compiler issued one or more weave info messages.
+ */
+ public boolean hasWeaveMessages() { return !weaveMessages.isEmpty(); }
+
/**
* The informational messages produced by the compiler. The list
* entries are the <code>IMessage</code> objects created during the
@@ -137,6 +144,8 @@ public class CompilationResult {
*/
public List /*IMessage*/ getFailMessages() { return failMessages; }
+ public List /*IMessage*/ getWeaveMessages() { return weaveMessages; }
+
/**
* Returns string containing message count summary, list of messages
* by type, and the actual ajc compilation command that was issued.
@@ -144,7 +153,7 @@ public class CompilationResult {
public String toString() {
StringBuffer buff = new StringBuffer();
buff.append("AspectJ Compilation Result:\n");
- int totalMessages = infoMessages.size() + warningMessages.size() + errorMessages.size() + failMessages.size();
+ int totalMessages = infoMessages.size() + warningMessages.size() + errorMessages.size() + failMessages.size() + weaveMessages.size();
buff.append(totalMessages);
buff.append(" messages");
if (totalMessages > 0) {
@@ -156,7 +165,9 @@ public class CompilationResult {
buff.append(errorMessages.size());
buff.append(" error, ");
buff.append(failMessages.size());
- buff.append(" fail)");
+ buff.append(" fail, )");
+ buff.append(weaveMessages.size());
+ buff.append(" weaveInfo");
}
buff.append("\n");
int msgNo = 1;
@@ -191,6 +202,14 @@ public class CompilationResult {
buff.append(iter.next().toString());
buff.append("\n");
}
+ msgNo = 1;
+ for (Iterator iter = weaveMessages.iterator(); iter.hasNext();) {
+ buff.append("[weaveInfo ");
+ buff.append(msgNo++);
+ buff.append("] ");
+ buff.append(iter.next().toString());
+ buff.append("\n");
+ }
buff.append("\ncommand was: 'ajc");
for (int i = 0; i < args.length; i++) {
buff.append(' ');
diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/MainTest.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/MainTest.java
index aa2110c03..1df49e47f 100644
--- a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/MainTest.java
+++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/MainTest.java
@@ -37,6 +37,6 @@ public class MainTest extends AjcTestCase {
xoptionText = xoptionText.substring("{compiler.name}".length());
CompilationResult result = ajc(null,new String[] {"-X"});
assertMessages(result,"Expecting xoptions usage message",
- new MessageSpec(null,null,null,newMessageList(new Message(xoptionText))));
+ new MessageSpec(null,null,null,newMessageList(new Message(xoptionText)),null));
}
}
diff --git a/testing/newsrc/org/aspectj/testing/AjcTest.java b/testing/newsrc/org/aspectj/testing/AjcTest.java
index 923505fa2..cdd8fc0a2 100644
--- a/testing/newsrc/org/aspectj/testing/AjcTest.java
+++ b/testing/newsrc/org/aspectj/testing/AjcTest.java
@@ -24,6 +24,19 @@ import org.aspectj.tools.ajc.AjcTestCase;
* Window - Preferences - Java - Code Style - Code Templates
*/
public class AjcTest {
+
+ private static boolean is13VMOrGreater = true;
+ private static boolean is14VMOrGreater = true;
+ private static boolean is15VMOrGreater = false;
+
+ static {
+ String vm = System.getProperty("java.vm.version");
+ if (vm.startsWith("1.3")) {
+ is14VMOrGreater = false;
+ } else if (vm.startsWith("1.5")) {
+ is15VMOrGreater = true;
+ }
+ }
private List testSteps = new ArrayList();
@@ -32,6 +45,7 @@ public class AjcTest {
private String title;
private String keywords;
private String comment;
+ private String vmLevel = "1.4";
public AjcTest() {
}
@@ -42,8 +56,9 @@ public class AjcTest {
}
public void runTest(AjcTestCase testCase) {
+ if (!canRunOnThisVM()) return;
try {
- System.out.print("TEST: " + getTitle() + "\t");
+ System.out.print("TEST: " + getTitle() + "\t");
for (Iterator iter = testSteps.iterator(); iter.hasNext();) {
ITestStep step = (ITestStep) iter.next();
step.setBaseDir(getDir());
@@ -55,6 +70,18 @@ public class AjcTest {
}
}
+ private boolean canRunOnThisVM() {
+ if (vmLevel.equals("1.3")) return true;
+ boolean canRun = true;
+ if (vmLevel.equals("1.4")) canRun = is14VMOrGreater;
+ if (vmLevel.equals("1.5")) canRun = is15VMOrGreater;
+ if (!canRun) {
+ System.out.println("***SKIPPING TEST***" + getTitle()+ " needs " + getVmLevel()
+ + ", currently running on " + System.getProperty("java.vm.version"));
+ }
+ return canRun;
+ }
+
/**
* @return Returns the comment.
*/
@@ -117,4 +144,17 @@ public class AjcTest {
this.title = title;
}
+ /**
+ * @param vmLevel The vmLevel to set.
+ */
+ public void setVmLevel(String vmLevel) {
+ this.vmLevel = vmLevel;
+ }
+
+ /**
+ * @return Returns the vmLevel.
+ */
+ public String getVmLevel() {
+ return vmLevel;
+ }
}
diff --git a/testing/newsrc/org/aspectj/testing/CompileSpec.java b/testing/newsrc/org/aspectj/testing/CompileSpec.java
index 1dd29f412..6f28ab31c 100644
--- a/testing/newsrc/org/aspectj/testing/CompileSpec.java
+++ b/testing/newsrc/org/aspectj/testing/CompileSpec.java
@@ -63,11 +63,15 @@ public class CompileSpec implements ITestStep {
public void setBaseDir(String dir) {
this.baseDir = dir;
}
+
+ protected String getBaseDir() { return baseDir; }
public void setTest(AjcTest t) {
this.myTest = t;
}
+ protected AjcTest getTest() { return myTest; }
+
/**
* @return Returns the aspectpath.
*/
@@ -186,7 +190,7 @@ public class CompileSpec implements ITestStep {
public String getExtdirs() { return extdirs;}
public void setExtdirs(String extdirs) { this.extdirs = extdirs; }
- private String[] buildArgs() {
+ protected String[] buildArgs() {
StringBuffer args = new StringBuffer();
// add any set options, and then files to compile at the end
if (getAspectpath() != null) {
@@ -264,11 +268,12 @@ public class CompileSpec implements ITestStep {
return ret;
}
- private AjcTestCase.MessageSpec buildMessageSpec() {
+ protected AjcTestCase.MessageSpec buildMessageSpec() {
List infos = null;
List warnings = new ArrayList();
List errors = new ArrayList();
List fails = new ArrayList();
+ List weaveInfos = new ArrayList();
for (Iterator iter = expected.iterator(); iter.hasNext();) {
ExpectedMessageSpec exMsg = (ExpectedMessageSpec) iter.next();
String kind = exMsg.getKind();
@@ -283,9 +288,11 @@ public class CompileSpec implements ITestStep {
fails.add(exMsg.toMessage());
} else if (kind.equals("abort")) {
fails.add(exMsg.toMessage());
+ } else if (kind.equals("weave")) {
+ weaveInfos.add(exMsg.toMessage());
}
}
- return new AjcTestCase.MessageSpec(infos,warnings,errors,fails);
+ return new AjcTestCase.MessageSpec(infos,warnings,errors,fails,weaveInfos);
}
}
diff --git a/testing/newsrc/org/aspectj/testing/OutputLine.java b/testing/newsrc/org/aspectj/testing/OutputLine.java
new file mode 100644
index 000000000..6c5a0f3d1
--- /dev/null
+++ b/testing/newsrc/org/aspectj/testing/OutputLine.java
@@ -0,0 +1,36 @@
+/* *******************************************************************
+ * Copyright (c) 2005 IBM Corporation
+ * 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:
+ * Adrian Colyer,
+ * ******************************************************************/
+package org.aspectj.testing;
+
+/**
+ * @author colyer
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class OutputLine {
+
+ private String text;
+
+ /**
+ * @return Returns the text.
+ */
+ public String getText() {
+ return text;
+ }
+ /**
+ * @param text The text to set.
+ */
+ public void setText(String text) {
+ this.text = text;
+ }
+}
diff --git a/testing/newsrc/org/aspectj/testing/OutputSpec.java b/testing/newsrc/org/aspectj/testing/OutputSpec.java
new file mode 100644
index 000000000..abeae90d2
--- /dev/null
+++ b/testing/newsrc/org/aspectj/testing/OutputSpec.java
@@ -0,0 +1,56 @@
+/* *******************************************************************
+ * Copyright (c) 2005 IBM Corporation
+ * 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:
+ * Adrian Colyer,
+ * ******************************************************************/
+package org.aspectj.testing;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import org.aspectj.tools.ajc.AjcTestCase;
+
+public class OutputSpec {
+
+ private List expectedOutputLines = new ArrayList();
+
+ public void addLine(OutputLine line) {
+ expectedOutputLines.add(line.getText());
+ }
+
+ public void matchAgainst(String output) {
+ boolean matches = false;
+ StringTokenizer strTok = new StringTokenizer(output,"\n");
+ if (strTok.countTokens() == expectedOutputLines.size()) {
+ matches = true;
+ for (Iterator iter = expectedOutputLines.iterator(); iter.hasNext();) {
+ String line = (String) iter.next();
+ String outputLine = strTok.nextToken().trim();
+ if (!line.equals(outputLine)) {
+ matches = false;
+ break;
+ }
+ }
+ }
+ if (!matches) {
+ StringBuffer failMessage = new StringBuffer();
+ failMessage.append("Expecting output:\n");
+ for (Iterator iter = expectedOutputLines.iterator(); iter.hasNext();) {
+ String line = (String) iter.next();
+ failMessage.append(line);
+ failMessage.append("\n");
+ }
+ failMessage.append("But found output:\n");
+ failMessage.append(output);
+ failMessage.append("\n");
+ AjcTestCase.fail(failMessage.toString());
+ }
+ }
+}
diff --git a/testing/newsrc/org/aspectj/testing/RunSpec.java b/testing/newsrc/org/aspectj/testing/RunSpec.java
index 431e5b094..980f22240 100644
--- a/testing/newsrc/org/aspectj/testing/RunSpec.java
+++ b/testing/newsrc/org/aspectj/testing/RunSpec.java
@@ -30,6 +30,8 @@ public class RunSpec implements ITestStep {
private String baseDir;
private String options;
private AjcTest myTest;
+ private OutputSpec stdErrSpec;
+ private OutputSpec stdOutSpec;
public RunSpec() {
}
@@ -43,6 +45,12 @@ public class RunSpec implements ITestStep {
}
String[] args = buildArgs();
AjcTestCase.RunResult rr = inTestCase.run(getClassToRun(),args,null);
+ if (stdErrSpec != null) {
+ stdErrSpec.matchAgainst(rr.getStdErr());
+ }
+ if (stdOutSpec != null) {
+ stdOutSpec.matchAgainst(rr.getStdOut());
+ }
}
public void addExpectedMessage(ExpectedMessageSpec message) {
@@ -64,6 +72,13 @@ public class RunSpec implements ITestStep {
public void setOptions(String options) {
this.options = options;
}
+
+ public void addStdErrSpec(OutputSpec spec) {
+ this.stdErrSpec = spec;
+ }
+ public void addStdOutSpec(OutputSpec spec) {
+ this.stdOutSpec = spec;
+ }
/**
* @return Returns the classToRun.
*/
diff --git a/testing/newsrc/org/aspectj/testing/WeaveSpec.java b/testing/newsrc/org/aspectj/testing/WeaveSpec.java
new file mode 100644
index 000000000..7f0c17683
--- /dev/null
+++ b/testing/newsrc/org/aspectj/testing/WeaveSpec.java
@@ -0,0 +1,167 @@
+/* *******************************************************************
+ * Copyright (c) 2005 IBM Corporation
+ * 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:
+ * Adrian Colyer,
+ * ******************************************************************/
+package org.aspectj.testing;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+
+import org.aspectj.tools.ajc.AjcTestCase;
+import org.aspectj.tools.ajc.CompilationResult;
+
+/**
+ * @author colyer
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class WeaveSpec extends CompileSpec {
+
+ private String classesFiles;
+ private String aspectsFiles;
+ private List classFilesFromClasses;
+
+ /* (non-Javadoc)
+ * @see org.aspectj.testing.ITestStep#execute(org.aspectj.tools.ajc.AjcTestCase)
+ */
+ public void execute(AjcTestCase inTestCase) {
+ String failMessage = "test \"" + getTest().getTitle() + "\" failed";
+ try {
+ File base = new File(getBaseDir());
+ classFilesFromClasses = new ArrayList();
+ setFiles(classesFiles);
+ String[] args = buildArgs();
+ CompilationResult result = inTestCase.ajc(base,args);
+ inTestCase.assertNoMessages(result,failMessage);
+ File sandbox = inTestCase.getSandboxDirectory();
+ createJar(sandbox,"classes.jar",true);
+
+ inTestCase.setShouldEmptySandbox(false);
+ setFiles(aspectsFiles);
+ String options = getOptions();
+ if (options == null) {
+ setOptions("-Xreweavable");
+ } else if (options.indexOf("-Xreweavable") == -1) {
+ setOptions(options + ",-Xreweavable");
+ }
+ setClasspath("classes.jar");
+ args = buildArgs();
+ result = inTestCase.ajc(base,args);
+ inTestCase.assertNoMessages(result,failMessage);
+ createJar(sandbox,"aspects.jar",false);
+
+ args = buildWeaveArgs();
+ inTestCase.setShouldEmptySandbox(false);
+ result = inTestCase.ajc(base,args);
+ AjcTestCase.MessageSpec messageSpec = buildMessageSpec();
+ inTestCase.assertMessages(result,failMessage,messageSpec);
+ inTestCase.setShouldEmptySandbox(false); // so subsequent steps in same test see my results
+ } catch (IOException e) {
+ AjcTestCase.fail(failMessage + " " + e);
+ }
+ }
+
+ public void setClassesFiles(String files) {
+ this.classesFiles = files;
+ }
+
+ public void setAspectsFiles(String files) {
+ this.aspectsFiles = files;
+ }
+
+ /**
+ * Find all the .class files under the dir, package them into a jar file,
+ * and then delete them.
+ * @param inDir
+ * @param name
+ */
+ private void createJar(File inDir, String name, boolean isClasses) throws IOException {
+ File outJar = new File(inDir,name);
+ FileOutputStream fos = new FileOutputStream(outJar);
+ JarOutputStream jarOut = new JarOutputStream(fos);
+ List classFiles = new ArrayList();
+ List toExclude = isClasses ? Collections.EMPTY_LIST : classFilesFromClasses;
+ collectClassFiles(inDir,classFiles,toExclude);
+ if (isClasses) classFilesFromClasses = classFiles;
+ String prefix = inDir.getPath() + File.separator;
+ for (Iterator iter = classFiles.iterator(); iter.hasNext();) {
+ File f = (File) iter.next();
+ String thisPath = f.getPath();
+ if (thisPath.startsWith(prefix)) {
+ thisPath = thisPath.substring(prefix.length());
+ }
+ JarEntry entry = new JarEntry(thisPath);
+ jarOut.putNextEntry(entry);
+ copyFile(f,jarOut);
+ jarOut.closeEntry();
+ }
+ jarOut.flush();
+ jarOut.close();
+ }
+
+ private void collectClassFiles(File inDir, List inList, List toExclude) {
+ File[] contents = inDir.listFiles();
+ for (int i = 0; i < contents.length; i++) {
+ if (contents[i].getName().endsWith(".class")) {
+ if (!toExclude.contains(contents[i])) {
+ inList.add(contents[i]);
+ }
+ } else if (contents[i].isDirectory()) {
+ collectClassFiles(contents[i],inList, toExclude);
+ }
+ }
+ }
+
+ private void copyFile(File f, OutputStream dest) throws IOException {
+ FileInputStream fis = new FileInputStream(f);
+ byte[] buf = new byte[4096];
+ int read = -1;
+ while((read = fis.read(buf)) != -1) {
+ dest.write(buf,0,read);
+ }
+ }
+
+ private String[] buildWeaveArgs() {
+ StringBuffer args = new StringBuffer();
+ if (getOptions() != null) {
+ StringTokenizer strTok = new StringTokenizer(getOptions(),",");
+ while (strTok.hasMoreTokens()) {
+ args.append(strTok.nextToken());
+ args.append(" ");
+ }
+ }
+ args.append("-inpath ");
+ args.append("classes.jar");
+ args.append(File.pathSeparator);
+ args.append("aspects.jar");
+ args.append(" ");
+ args.append("-aspectpath ");
+ args.append("aspects.jar");
+ String argumentString = args.toString();
+ StringTokenizer strTok = new StringTokenizer(argumentString," ");
+ String[] ret = new String[strTok.countTokens()];
+ for (int i = 0; i < ret.length; i++) {
+ ret[i] = strTok.nextToken();
+ }
+ return ret;
+ }
+
+}
diff --git a/testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java b/testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java
index 62cda6904..32379c775 100644
--- a/testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java
+++ b/testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java
@@ -140,6 +140,18 @@ public abstract class XMLBasedAjcTestCase extends AjcTestCase {
digester.addObjectCreate("*/message",ExpectedMessageSpec.class);
digester.addSetProperties("*/message");
digester.addSetNext("*/message","addExpectedMessage","org.aspectj.testing.ExpectedMessageSpec");
+ digester.addObjectCreate("suite/ajc-test/weave",WeaveSpec.class);
+ digester.addSetProperties("suite/ajc-test/weave");
+ digester.addSetNext("suite/ajc-test/weave","addTestStep","org.aspectj.testing.ITestStep");
+ digester.addObjectCreate("suite/ajc-test/run/stderr",OutputSpec.class);
+ digester.addSetProperties("suite/ajc-test/run/stderr");
+ digester.addSetNext("suite/ajc-test/run/stderr","addStdErrSpec","org.aspectj.testing.OutputSpec");
+ digester.addObjectCreate("suite/ajc-test/run/stdout",OutputSpec.class);
+ digester.addSetProperties("suite/ajc-test/run/stdout");
+ digester.addSetNext("suite/ajc-test/run/stdout","addStdOutSpec","org.aspectj.testing.OutputSpec");
+ digester.addObjectCreate("*/line",OutputLine.class);
+ digester.addSetProperties("*/line");
+ digester.addSetNext("*/line","addLine","org.aspectj.testing.OutputLine");
return digester;
}