summaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
authoracolyer <acolyer>2005-02-11 12:45:58 +0000
committeracolyer <acolyer>2005-02-11 12:45:58 +0000
commit382b7330f47d14164896671a4bf3c7ec3acf069b (patch)
treeeb876e06a8d30f600b3e4e5bb2a4c46dc913d39f /testing
parent8cefe0a7e3480dc34df6fe27610cc25ceb1a5179 (diff)
downloadaspectj-382b7330f47d14164896671a4bf3c7ec3acf069b.tar.gz
aspectj-382b7330f47d14164896671a4bf3c7ec3acf069b.zip
better support for weaveInfo message, <weave> step, and stderr/out validation from runs.
Diffstat (limited to 'testing')
-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
7 files changed, 337 insertions, 4 deletions
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;
}