Merge pull request #1364 from ericvergnaud/fix-c#-tests
enable target specific assertXxx behaviour
This commit is contained in:
commit
7efb6c240a
2
pom.xml
2
pom.xml
|
@ -77,7 +77,7 @@
|
||||||
<module>tool-testsuite</module>
|
<module>tool-testsuite</module>
|
||||||
<module>runtime-testsuite/annotations</module>
|
<module>runtime-testsuite/annotations</module>
|
||||||
<module>runtime-testsuite/processors</module>
|
<module>runtime-testsuite/processors</module>
|
||||||
<module>runtime-testsuite-legacy</module>
|
<!-- <module>runtime-testsuite-legacy</module> -->
|
||||||
<module>runtime-testsuite</module>
|
<module>runtime-testsuite</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
|
|
@ -125,9 +125,13 @@ public abstract class BaseRuntimeTest {
|
||||||
descriptor.getInput(),
|
descriptor.getInput(),
|
||||||
descriptor.showDiagnosticErrors()
|
descriptor.showDiagnosticErrors()
|
||||||
);
|
);
|
||||||
|
if(delegate instanceof RuntimeTestAssert) {
|
||||||
assertEquals(descriptor.getOutput(), found);
|
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getOutput(), found);
|
||||||
assertEquals(descriptor.getErrors(), delegate.getParseErrors());
|
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getErrors(), delegate.getParseErrors());
|
||||||
|
} else {
|
||||||
|
assertEquals(descriptor.getOutput(), found);
|
||||||
|
assertEquals(descriptor.getErrors(), delegate.getParseErrors());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLexer(RuntimeTestDescriptor descriptor) throws Exception {
|
public void testLexer(RuntimeTestDescriptor descriptor) throws Exception {
|
||||||
|
@ -161,9 +165,15 @@ public abstract class BaseRuntimeTest {
|
||||||
grammar = grammarST.render();
|
grammar = grammarST.render();
|
||||||
|
|
||||||
String found = delegate.execLexer(grammarName+".g4", grammar, grammarName, descriptor.getInput(), descriptor.showDFA());
|
String found = delegate.execLexer(grammarName+".g4", grammar, grammarName, descriptor.getInput(), descriptor.showDFA());
|
||||||
assertEquals(descriptor.getOutput(), found);
|
if(delegate instanceof RuntimeTestAssert) {
|
||||||
assertEquals(descriptor.getANTLRToolErrors(), delegate.getANTLRToolErrors());
|
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getOutput(), found);
|
||||||
assertEquals(descriptor.getErrors(), delegate.getParseErrors());
|
((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 ----
|
// ---- support ----
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package org.antlr.v4.test.runtime;
|
||||||
|
|
||||||
|
public interface RuntimeTestAssert {
|
||||||
|
void assertEqualStrings(String expected, String actual);
|
||||||
|
}
|
|
@ -36,6 +36,7 @@ import org.antlr.v4.runtime.TokenSource;
|
||||||
import org.antlr.v4.runtime.WritableToken;
|
import org.antlr.v4.runtime.WritableToken;
|
||||||
import org.antlr.v4.runtime.misc.Utils;
|
import org.antlr.v4.runtime.misc.Utils;
|
||||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
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.test.runtime.RuntimeTestSupport;
|
||||||
import org.antlr.v4.tool.ANTLRMessage;
|
import org.antlr.v4.tool.ANTLRMessage;
|
||||||
import org.antlr.v4.tool.DefaultToolListener;
|
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.XPathConstants;
|
||||||
import javax.xml.xpath.XPathExpression;
|
import javax.xml.xpath.XPathExpression;
|
||||||
import javax.xml.xpath.XPathFactory;
|
import javax.xml.xpath.XPathFactory;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
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.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
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 newline = System.getProperty("line.separator");
|
||||||
public static final String pathSep = System.getProperty("path.separator");
|
public static final String pathSep = System.getProperty("path.separator");
|
||||||
|
|
||||||
|
@ -568,11 +570,9 @@ public class BaseCSharpTest implements RuntimeTestSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String execTest() {
|
public String execTest() {
|
||||||
|
String exec = locateExec();
|
||||||
|
String[] args = getExecTestArgs(exec);
|
||||||
try {
|
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);
|
ProcessBuilder pb = new ProcessBuilder(args);
|
||||||
pb.directory(new File(tmpdir));
|
pb.directory(new File(tmpdir));
|
||||||
Process process = pb.start();
|
Process process = pb.start();
|
||||||
|
@ -599,6 +599,15 @@ public class BaseCSharpTest implements RuntimeTestSupport {
|
||||||
return null;
|
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) {
|
public void testErrors(String[] pairs, boolean printTree) {
|
||||||
for (int i = 0; i < pairs.length; i+=2) {
|
for (int i = 0; i < pairs.length; i+=2) {
|
||||||
String input = pairs[i];
|
String input = pairs[i];
|
||||||
|
@ -895,6 +904,11 @@ public class BaseCSharpTest implements RuntimeTestSupport {
|
||||||
org.junit.Assert.assertEquals(msg, a, b);
|
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) {
|
protected static void assertEquals(String a, String b) {
|
||||||
a = absorbExpectedDifferences(a);
|
a = absorbExpectedDifferences(a);
|
||||||
b = absorbActualDifferences(b);
|
b = absorbActualDifferences(b);
|
||||||
|
|
Loading…
Reference in New Issue