Merge pull request #1364 from ericvergnaud/fix-c#-tests

enable target specific assertXxx behaviour
This commit is contained in:
Terence Parr 2016-11-16 19:37:23 +01:00 committed by GitHub
commit 7efb6c240a
4 changed files with 41 additions and 12 deletions

View File

@ -77,7 +77,7 @@
<module>tool-testsuite</module>
<module>runtime-testsuite/annotations</module>
<module>runtime-testsuite/processors</module>
<module>runtime-testsuite-legacy</module>
<!-- <module>runtime-testsuite-legacy</module> -->
<module>runtime-testsuite</module>
</modules>

View File

@ -125,9 +125,13 @@ public abstract class BaseRuntimeTest {
descriptor.getInput(),
descriptor.showDiagnosticErrors()
);
assertEquals(descriptor.getOutput(), found);
assertEquals(descriptor.getErrors(), delegate.getParseErrors());
if(delegate instanceof RuntimeTestAssert) {
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getOutput(), found);
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getErrors(), delegate.getParseErrors());
} else {
assertEquals(descriptor.getOutput(), found);
assertEquals(descriptor.getErrors(), delegate.getParseErrors());
}
}
public void testLexer(RuntimeTestDescriptor descriptor) throws Exception {
@ -161,9 +165,15 @@ public abstract class BaseRuntimeTest {
grammar = grammarST.render();
String found = delegate.execLexer(grammarName+".g4", grammar, grammarName, descriptor.getInput(), descriptor.showDFA());
assertEquals(descriptor.getOutput(), found);
assertEquals(descriptor.getANTLRToolErrors(), delegate.getANTLRToolErrors());
assertEquals(descriptor.getErrors(), delegate.getParseErrors());
if(delegate instanceof RuntimeTestAssert) {
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getOutput(), found);
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getANTLRToolErrors(), delegate.getANTLRToolErrors());
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getErrors(), delegate.getParseErrors());
} else {
assertEquals(descriptor.getOutput(), found);
assertEquals(descriptor.getANTLRToolErrors(), delegate.getANTLRToolErrors());
assertEquals(descriptor.getErrors(), delegate.getParseErrors());
}
}
// ---- support ----

View File

@ -0,0 +1,5 @@
package org.antlr.v4.test.runtime;
public interface RuntimeTestAssert {
void assertEqualStrings(String expected, String actual);
}

View File

@ -36,6 +36,7 @@ import org.antlr.v4.runtime.TokenSource;
import org.antlr.v4.runtime.WritableToken;
import org.antlr.v4.runtime.misc.Utils;
import org.antlr.v4.test.runtime.ErrorQueue;
import org.antlr.v4.test.runtime.RuntimeTestAssert;
import org.antlr.v4.test.runtime.RuntimeTestSupport;
import org.antlr.v4.tool.ANTLRMessage;
import org.antlr.v4.tool.DefaultToolListener;
@ -56,6 +57,7 @@ import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
@ -77,7 +79,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class BaseCSharpTest implements RuntimeTestSupport {
public class BaseCSharpTest implements RuntimeTestSupport, RuntimeTestAssert {
public static final String newline = System.getProperty("line.separator");
public static final String pathSep = System.getProperty("path.separator");
@ -568,11 +570,9 @@ public class BaseCSharpTest implements RuntimeTestSupport {
}
public String execTest() {
String exec = locateExec();
String[] args = getExecTestArgs(exec);
try {
String exec = locateExec();
String[] args = isWindows() ?
new String[] { exec, new File(tmpdir, "input").getAbsolutePath() } :
new String[] { "mono", exec, new File(tmpdir, "input").getAbsolutePath() };
ProcessBuilder pb = new ProcessBuilder(args);
pb.directory(new File(tmpdir));
Process process = pb.start();
@ -599,6 +599,15 @@ public class BaseCSharpTest implements RuntimeTestSupport {
return null;
}
private String[] getExecTestArgs(String exec) {
if(isWindows())
return new String[] { exec, new File(tmpdir, "input").getAbsolutePath() } ;
else {
String mono = locateTool("mono");
return new String[] { mono, exec, new File(tmpdir, "input").getAbsolutePath() };
}
}
public void testErrors(String[] pairs, boolean printTree) {
for (int i = 0; i < pairs.length; i+=2) {
String input = pairs[i];
@ -895,6 +904,11 @@ public class BaseCSharpTest implements RuntimeTestSupport {
org.junit.Assert.assertEquals(msg, a, b);
}
@Override
public void assertEqualStrings(String a, String b) {
assertEquals(a, b);
}
protected static void assertEquals(String a, String b) {
a = absorbExpectedDifferences(a);
b = absorbActualDifferences(b);