aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraclement <aclement>2006-12-22 15:38:07 +0000
committeraclement <aclement>2006-12-22 15:38:07 +0000
commitd7222a776d529bc84dee4d2da4796bb01b0659d9 (patch)
treefa3626fed00bbf4a447ae0c7edb7cf38e2000f44
parentdb930ff50582bc069f293e5da9b972c9c6a13353 (diff)
downloadaspectj-d7222a776d529bc84dee4d2da4796bb01b0659d9.tar.gz
aspectj-d7222a776d529bc84dee4d2da4796bb01b0659d9.zip
166580, comment #6: harness now allows you to specify if ordering is important in expected output
-rw-r--r--testing/newsrc/org/aspectj/testing/OutputSpec.java79
-rw-r--r--testing/newsrc/org/aspectj/testing/RunSpec.java6
-rw-r--r--testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java1
3 files changed, 70 insertions, 16 deletions
diff --git a/testing/newsrc/org/aspectj/testing/OutputSpec.java b/testing/newsrc/org/aspectj/testing/OutputSpec.java
index d45208af8..b4bba2a99 100644
--- a/testing/newsrc/org/aspectj/testing/OutputSpec.java
+++ b/testing/newsrc/org/aspectj/testing/OutputSpec.java
@@ -26,6 +26,14 @@ public class OutputSpec {
}
public void matchAgainst(String output) {
+ matchAgainst(output, "yes");
+ }
+
+ public void matchAgainst(String output, String ordered) {
+ if (ordered != null && ordered.equals("no")) {
+ unorderedMatchAgainst(output);
+ return;
+ }
boolean matches = false;
int lineNo = 0;
StringTokenizer strTok = new StringTokenizer(output,"\n");
@@ -43,23 +51,64 @@ public class OutputSpec {
}
} else { lineNo = -1; }
if (!matches) {
- StringBuffer failMessage = new StringBuffer();
- failMessage.append("\n expecting output:\n");
- int l = 0;
- for (Iterator iter = expectedOutputLines.iterator(); iter.hasNext();) {
- String line = (String) iter.next();
- failMessage.append(line);
- failMessage.append("\n");
+ createFailureMessage(output, lineNo, strTok.countTokens());
+ }
+ }
+
+ public void unorderedMatchAgainst(String output) {
+ List outputFound = getOutputFound(output);
+ if(outputFound.size() != expectedOutputLines.size()) {
+ createFailureMessage(output, -1, outputFound.size());
+ return;
+ }
+ List expected = new ArrayList();
+ expected.addAll(expectedOutputLines);
+ List found = new ArrayList();
+ found.addAll(outputFound);
+ for (Iterator iterator = outputFound.iterator(); iterator.hasNext();) {
+ String lineFound = (String) iterator.next();
+ for (Iterator iterator2 = expectedOutputLines.iterator(); iterator2.hasNext();) {
+ String lineExpected = (String) iterator2.next();
+ if (lineFound.indexOf(lineExpected)!= -1) {
+ found.remove(lineFound);
+ expected.remove(lineExpected);
+ continue;
+ }
}
- failMessage.append(" but found output:\n");
- failMessage.append(output);
- failMessage.append("\n");
- if (lineNo==-1)
- failMessage.append("Expected "+expectedOutputLines.size()+" lines of output but there are "+strTok.countTokens());
- else
- failMessage.append("First difference is on line " + lineNo);
+ }
+ if (!found.isEmpty() || !expected.isEmpty()) {
+ createFailureMessage(output,-2,outputFound.size());
+ }
+ }
+
+ private void createFailureMessage(String output, int lineNo, int sizeFound) {
+ StringBuffer failMessage = new StringBuffer();
+ failMessage.append("\n expecting output:\n");
+ int l = 0;
+ for (Iterator iter = expectedOutputLines.iterator(); iter.hasNext();) {
+ String line = (String) iter.next();
+ failMessage.append(line);
failMessage.append("\n");
- AjcTestCase.fail(failMessage.toString());
}
+ failMessage.append(" but found output:\n");
+ failMessage.append(output);
+ failMessage.append("\n");
+ if (lineNo==-1) {
+ failMessage.append("Expected "+expectedOutputLines.size()+" lines of output but there are "+sizeFound);
+ } else if (lineNo >= 0) {
+ failMessage.append("First difference is on line " + lineNo);
+ }
+ failMessage.append("\n");
+ AjcTestCase.fail(failMessage.toString());
+ }
+
+ private List getOutputFound(String output) {
+ List found = new ArrayList();
+ StringTokenizer strTok = new StringTokenizer(output,"\n");
+ while(strTok.hasMoreTokens()) {
+ String outputLine = strTok.nextToken().trim();
+ found.add(outputLine);
+ }
+ return found;
}
}
diff --git a/testing/newsrc/org/aspectj/testing/RunSpec.java b/testing/newsrc/org/aspectj/testing/RunSpec.java
index 7318a4315..12de57268 100644
--- a/testing/newsrc/org/aspectj/testing/RunSpec.java
+++ b/testing/newsrc/org/aspectj/testing/RunSpec.java
@@ -35,6 +35,7 @@ public class RunSpec implements ITestStep {
private String baseDir;
private String options;
private String cpath;
+ private String orderedStderr;
private AjcTest myTest;
private OutputSpec stdErrSpec;
private OutputSpec stdOutSpec;
@@ -61,7 +62,7 @@ public class RunSpec implements ITestStep {
AjcTestCase.RunResult rr = inTestCase.run(getClassToRun(),args,getClasspath(),useLtw);
if (stdErrSpec != null) {
- stdErrSpec.matchAgainst(rr.getStdErr());
+ stdErrSpec.matchAgainst(rr.getStdErr(),orderedStderr);
}
if (stdOutSpec != null) {
stdOutSpec.matchAgainst(rr.getStdOut());
@@ -136,6 +137,9 @@ public class RunSpec implements ITestStep {
public void addStdOutSpec(OutputSpec spec) {
this.stdOutSpec = spec;
}
+ public void setOrderedStderr(String orderedStderr) {
+ this.orderedStderr = orderedStderr;
+ }
/**
* @return Returns the classToRun.
*/
diff --git a/testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java b/testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java
index dc9bbe296..4e1c06e36 100644
--- a/testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java
+++ b/testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java
@@ -169,6 +169,7 @@ public abstract class XMLBasedAjcTestCase extends AjcTestCase {
digester.addSetProperties("suite/ajc-test/run","class","classToRun");
digester.addSetProperties("suite/ajc-test/run","ltw","ltwFile");
digester.addSetProperties("suite/ajc-test/run","xlintfile","xlintFile");
+ digester.addSetProperties("suite/ajc-test/run/stderr","ordered","orderedStderr");
digester.addSetNext("suite/ajc-test/run","addTestStep","org.aspectj.testing.ITestStep");
digester.addObjectCreate("*/message",ExpectedMessageSpec.class);
digester.addSetProperties("*/message");