Skip to content

Commit

Permalink
Merge pull request #92 from JKrag/master
Browse files Browse the repository at this point in the history
Added support for alternative output syntax in TestNG i.e. "expected […] but found […]"
  • Loading branch information
cbeust committed Aug 24, 2013
2 parents e0f6037 + 2f11b4d commit e867286
Showing 1 changed file with 34 additions and 24 deletions.
58 changes: 34 additions & 24 deletions src/main/org/testng/eclipse/ui/CompareResultDialog.java
Expand Up @@ -14,6 +14,10 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.CompareViewerPane;
Expand Down Expand Up @@ -86,6 +90,14 @@ public class CompareResultDialog extends Dialog {
private IDialogSettings fSettings;
protected Rectangle fNewBounds;

static List<Pattern> patternList;
static String[] regexes = {
".*expected:<(.*)> but was:<(.*)>.*",
".*expected not same with:<(.*)> but was same:<(.*)>.*",
".*expected same with:<(.*)> but was:<(.*)>.*",
".*expected \\[(.*)\\] but found \\[(.*)\\].*"
};

public CompareResultDialog(Shell parentShell, RunInfo failure) {
super(parentShell);
fgThis = this;
Expand All @@ -112,32 +124,30 @@ private void parseHamCrestTrace(String trace) {
fExpected = trace.substring(ind1 + IS.length(), ind2);
fActual = trace.substring(ind3 + WAS.length(), ind4);
}

private void parseTestNGTrace(String trace) {
String firstToken= "expected:<";
String nextTokenString= "> but was:<";
int idxStart= trace.indexOf(firstToken);
if(idxStart == -1) {
firstToken= "expected not same with:<";
idxStart= trace.indexOf(firstToken);
nextTokenString= "> but was same:<";
}
if(idxStart == -1) {
firstToken= "expected same with:<";
idxStart= trace.indexOf(firstToken);
nextTokenString= "> but was:<";
}

if(idxStart != -1) {
int idxEnd= trace.indexOf(nextTokenString); //trace.indexOf('>', idxStart);
fExpected= trace.substring(idxStart + firstToken.length(), idxEnd);
idxStart= idxEnd + nextTokenString.length();
fActual= trace.substring(idxStart, trace.lastIndexOf('>'));

static List<Pattern> getPatterns() {
if (patternList == null) {
patternList = new ArrayList<Pattern>();
for (String rgx : regexes) {
patternList.add(Pattern.compile(rgx, Pattern.DOTALL));
}
}
else {
fActual= "N/A";
fExpected= "N/A";
return patternList;
}

private void parseTestNGTrace(String trace) {
Matcher m;
for (Pattern p : getPatterns()) {
m = p.matcher(trace);
if (m.find()) {
fExpected = m.group(1);
fActual = m.group(2);
return;
}
}
fActual= "N/A";
fExpected= "N/A";
return;
}

protected Point getInitialSize() {
Expand Down

0 comments on commit e867286

Please sign in to comment.