forked from jasder/antlr
factor antlr() out of target test files into single spot
This commit is contained in:
parent
b5b69b60d0
commit
007a445be4
|
@ -498,39 +498,6 @@ public abstract class BaseBrowserTest {
|
|||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
public void testErrors(String[] pairs, boolean printTree) {
|
||||
for (int i = 0; i < pairs.length; i+=2) {
|
||||
String input = pairs[i];
|
||||
String expect = pairs[i+1];
|
||||
|
||||
String[] lines = input.split("\n");
|
||||
String fileName = getFilenameFromFirstLineOfGrammar(lines[0]);
|
||||
ErrorQueue equeue = antlr(fileName, fileName, input, false);
|
||||
|
||||
String actual = equeue.toString(true);
|
||||
actual = actual.replace(tmpdir + File.separator, "");
|
||||
System.err.println(actual);
|
||||
String msg = input;
|
||||
msg = msg.replace("\n","\\n");
|
||||
msg = msg.replace("\r","\\r");
|
||||
msg = msg.replace("\t","\\t");
|
||||
|
||||
assertEquals("error in: "+msg,expect,actual);
|
||||
}
|
||||
}
|
||||
|
||||
public String getFilenameFromFirstLineOfGrammar(String line) {
|
||||
String fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
int grIndex = line.lastIndexOf("grammar");
|
||||
int semi = line.lastIndexOf(';');
|
||||
if ( grIndex>=0 && semi>=0 ) {
|
||||
int space = line.indexOf(' ', grIndex);
|
||||
fileName = line.substring(space+1, semi)+Tool.GRAMMAR_EXTENSION;
|
||||
}
|
||||
if ( fileName.length()==Tool.GRAMMAR_EXTENSION.length() ) fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
return fileName;
|
||||
}
|
||||
|
||||
List<ANTLRMessage> getMessagesOfType(List<ANTLRMessage> msgs, Class<? extends ANTLRMessage> c) {
|
||||
List<ANTLRMessage> filtered = new ArrayList<ANTLRMessage>();
|
||||
for (ANTLRMessage m : msgs) {
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package org.antlr.v4.test.runtime;
|
||||
|
||||
import org.antlr.v4.Tool;
|
||||
import org.antlr.v4.runtime.misc.Pair;
|
||||
import org.antlr.v4.runtime.misc.Utils;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.ANTLRMessage;
|
||||
import org.antlr.v4.tool.DefaultToolListener;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
@ -18,6 +22,7 @@ import java.io.IOException;
|
|||
import java.lang.reflect.Modifier;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
@ -44,6 +49,9 @@ public abstract class BaseRuntimeTest {
|
|||
"Node", "Safari", "Firefox", "Explorer", "Chrome"
|
||||
};
|
||||
|
||||
/** ANTLR isn't thread-safe to process grammars so we use a global lock for testing */
|
||||
public static final Object antlrLock = new Object();
|
||||
|
||||
protected RuntimeTestSupport delegate;
|
||||
protected RuntimeTestDescriptor descriptor;
|
||||
|
||||
|
@ -52,8 +60,10 @@ public abstract class BaseRuntimeTest {
|
|||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
// @org.junit.Rule
|
||||
// public final Timeout eachTimeout = new Timeout(60000);
|
||||
public static void mkdir(String dir) {
|
||||
File f = new File(dir);
|
||||
f.mkdirs();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
@ -178,6 +188,76 @@ public abstract class BaseRuntimeTest {
|
|||
}
|
||||
}
|
||||
|
||||
/** Write a grammar to tmpdir and run antlr */
|
||||
public static ErrorQueue antlrOnString(String workdir,
|
||||
String targetName,
|
||||
String grammarFileName,
|
||||
String grammarStr,
|
||||
boolean defaultListener,
|
||||
String... extraOptions)
|
||||
{
|
||||
mkdir(workdir);
|
||||
BaseJavaTest.writeFile(workdir, grammarFileName, grammarStr);
|
||||
return antlrOnString(workdir, targetName, grammarFileName, defaultListener, extraOptions);
|
||||
}
|
||||
|
||||
/** Run ANTLR on stuff in workdir and error queue back */
|
||||
public static ErrorQueue antlrOnString(String workdir,
|
||||
String targetName,
|
||||
String grammarFileName,
|
||||
boolean defaultListener,
|
||||
String... extraOptions)
|
||||
{
|
||||
final List<String> options = new ArrayList<>();
|
||||
Collections.addAll(options, extraOptions);
|
||||
if ( targetName!=null ) {
|
||||
options.add("-Dlanguage="+targetName);
|
||||
}
|
||||
if ( !options.contains("-o") ) {
|
||||
options.add("-o");
|
||||
options.add(workdir);
|
||||
}
|
||||
if ( !options.contains("-lib") ) {
|
||||
options.add("-lib");
|
||||
options.add(workdir);
|
||||
}
|
||||
if ( !options.contains("-encoding") ) {
|
||||
options.add("-encoding");
|
||||
options.add("UTF-8");
|
||||
}
|
||||
options.add(new File(workdir,grammarFileName).toString());
|
||||
|
||||
final String[] optionsA = new String[options.size()];
|
||||
options.toArray(optionsA);
|
||||
Tool antlr = new Tool(optionsA);
|
||||
ErrorQueue equeue = new ErrorQueue(antlr);
|
||||
antlr.addListener(equeue);
|
||||
if (defaultListener) {
|
||||
antlr.addListener(new DefaultToolListener(antlr));
|
||||
}
|
||||
synchronized (antlrLock) {
|
||||
antlr.processGrammarsOnCommandLine();
|
||||
}
|
||||
|
||||
List<String> errors = new ArrayList<>();
|
||||
|
||||
if ( !defaultListener && !equeue.errors.isEmpty() ) {
|
||||
for (int i = 0; i < equeue.errors.size(); i++) {
|
||||
ANTLRMessage msg = equeue.errors.get(i);
|
||||
ST msgST = antlr.errMgr.getMessageTemplate(msg);
|
||||
errors.add(msgST.render());
|
||||
}
|
||||
}
|
||||
if ( !defaultListener && !equeue.warnings.isEmpty() ) {
|
||||
for (int i = 0; i < equeue.warnings.size(); i++) {
|
||||
ANTLRMessage msg = equeue.warnings.get(i);
|
||||
// antlrToolErrors.append(msg); warnings are hushed
|
||||
}
|
||||
}
|
||||
|
||||
return equeue;
|
||||
}
|
||||
|
||||
// ---- support ----
|
||||
|
||||
public static RuntimeTestDescriptor[] getRuntimeTestDescriptors(Class<?> clazz, String targetName) {
|
||||
|
@ -198,11 +278,6 @@ public abstract class BaseRuntimeTest {
|
|||
return descriptors.toArray(new RuntimeTestDescriptor[0]);
|
||||
}
|
||||
|
||||
protected void mkdir(String dir) {
|
||||
File f = new File(dir);
|
||||
f.mkdirs();
|
||||
}
|
||||
|
||||
public static void writeFile(String dir, String fileName, String content) {
|
||||
try {
|
||||
Utils.writeFile(dir+"/"+fileName, content, "UTF-8");
|
||||
|
|
|
@ -56,14 +56,12 @@ import org.antlr.v4.runtime.atn.LexerATNSimulator;
|
|||
import org.antlr.v4.runtime.dfa.DFA;
|
||||
import org.antlr.v4.runtime.misc.IntegerList;
|
||||
import org.antlr.v4.runtime.misc.Interval;
|
||||
import org.antlr.v4.runtime.misc.Utils;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.antlr.v4.semantics.SemanticPipeline;
|
||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||
import org.antlr.v4.tool.ANTLRMessage;
|
||||
import org.antlr.v4.tool.DOTGenerator;
|
||||
import org.antlr.v4.tool.DefaultToolListener;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.GrammarSemanticsMessage;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
|
@ -93,7 +91,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static org.antlr.v4.test.runtime.java.BaseJavaTest.antlrLock;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -346,53 +344,6 @@ public class BaseCppTest implements RuntimeTestSupport {
|
|||
return "Cpp";
|
||||
}
|
||||
|
||||
/** Return true if all is ok, no errors */
|
||||
protected ErrorQueue antlr(String fileName, String grammarFileName, String grammarStr, boolean defaultListener, String... extraOptions) {
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, fileName, grammarStr);
|
||||
final List<String> options = new ArrayList<String>();
|
||||
Collections.addAll(options, extraOptions);
|
||||
options.add("-Dlanguage=" + getLanguage());
|
||||
options.add("-o");
|
||||
options.add(tmpdir);
|
||||
options.add("-lib");
|
||||
options.add(tmpdir);
|
||||
options.add(new File(tmpdir,grammarFileName).toString());
|
||||
|
||||
final String[] optionsA = new String[options.size()];
|
||||
options.toArray(optionsA);
|
||||
Tool antlr = newTool(optionsA);
|
||||
ErrorQueue equeue = new ErrorQueue(antlr);
|
||||
antlr.addListener(equeue);
|
||||
if (defaultListener) {
|
||||
antlr.addListener(new DefaultToolListener(antlr));
|
||||
}
|
||||
synchronized (antlrLock) {
|
||||
antlr.processGrammarsOnCommandLine();
|
||||
}
|
||||
|
||||
if ( !defaultListener && !equeue.errors.isEmpty() ) {
|
||||
for (int i = 0; i < equeue.errors.size(); i++) {
|
||||
ANTLRMessage msg = equeue.errors.get(i);
|
||||
antlrToolErrors.append(msg.toString());
|
||||
}
|
||||
try {
|
||||
antlrToolErrors.append(new String(Utils.readFile(tmpdir+"/"+grammarFileName)));
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
antlrToolErrors.append(ioe.toString());
|
||||
}
|
||||
}
|
||||
if ( !defaultListener && !equeue.warnings.isEmpty() ) {
|
||||
for (int i = 0; i < equeue.warnings.size(); i++) {
|
||||
ANTLRMessage msg = equeue.warnings.get(i);
|
||||
// antlrToolErrors.append(msg); warnings are hushed
|
||||
}
|
||||
}
|
||||
|
||||
return equeue;
|
||||
}
|
||||
|
||||
protected String execLexer(String grammarFileName,
|
||||
String grammarStr,
|
||||
String lexerName,
|
||||
|
@ -498,7 +449,7 @@ public class BaseCppTest implements RuntimeTestSupport {
|
|||
String... extraOptions)
|
||||
{
|
||||
ErrorQueue equeue =
|
||||
antlr(grammarFileName, grammarFileName, grammarStr, defaultListener, extraOptions);
|
||||
antlrOnString(getTmpDir(), "Cpp", grammarFileName, grammarStr, defaultListener, extraOptions);
|
||||
if (!equeue.errors.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -744,39 +695,6 @@ public class BaseCppTest implements RuntimeTestSupport {
|
|||
return runtimeSrc.getPath();
|
||||
}
|
||||
|
||||
public void testErrors(String[] pairs, boolean printTree) {
|
||||
for (int i = 0; i < pairs.length; i+=2) {
|
||||
String input = pairs[i];
|
||||
String expect = pairs[i+1];
|
||||
|
||||
String[] lines = input.split("\n");
|
||||
String fileName = getFilenameFromFirstLineOfGrammar(lines[0]);
|
||||
ErrorQueue equeue = antlr(fileName, fileName, input, false);
|
||||
|
||||
String actual = equeue.toString(true);
|
||||
actual = actual.replace(tmpdir + File.separator, "");
|
||||
System.err.println(actual);
|
||||
String msg = input;
|
||||
msg = msg.replace("\n","\\n");
|
||||
msg = msg.replace("\r","\\r");
|
||||
msg = msg.replace("\t","\\t");
|
||||
|
||||
assertEquals("error in: "+msg,expect,actual);
|
||||
}
|
||||
}
|
||||
|
||||
public String getFilenameFromFirstLineOfGrammar(String line) {
|
||||
String fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
int grIndex = line.lastIndexOf("grammar");
|
||||
int semi = line.lastIndexOf(';');
|
||||
if ( grIndex>=0 && semi>=0 ) {
|
||||
int space = line.indexOf(' ', grIndex);
|
||||
fileName = line.substring(space+1, semi)+Tool.GRAMMAR_EXTENSION;
|
||||
}
|
||||
if ( fileName.length()==Tool.GRAMMAR_EXTENSION.length() ) fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
return fileName;
|
||||
}
|
||||
|
||||
List<ANTLRMessage> getMessagesOfType(List<ANTLRMessage> msgs, Class<? extends ANTLRMessage> c) {
|
||||
List<ANTLRMessage> filtered = new ArrayList<ANTLRMessage>();
|
||||
for (ANTLRMessage m : msgs) {
|
||||
|
|
|
@ -39,7 +39,6 @@ import org.antlr.v4.test.runtime.ErrorQueue;
|
|||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||
import org.antlr.v4.test.runtime.SpecialRuntimeTestAssert;
|
||||
import org.antlr.v4.tool.ANTLRMessage;
|
||||
import org.antlr.v4.tool.DefaultToolListener;
|
||||
import org.antlr.v4.tool.GrammarSemanticsMessage;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.rules.TestWatcher;
|
||||
|
@ -74,7 +73,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.antlr.v4.test.runtime.java.BaseJavaTest.antlrLock;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -238,65 +237,6 @@ public class BaseCSharpTest implements RuntimeTestSupport, SpecialRuntimeTestAss
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
protected ErrorQueue antlr(String grammarFileName, boolean defaultListener, String... extraOptions) {
|
||||
final List<String> options = new ArrayList<String>();
|
||||
Collections.addAll(options, extraOptions);
|
||||
options.add("-Dlanguage=CSharp");
|
||||
if ( !options.contains("-o") ) {
|
||||
options.add("-o");
|
||||
options.add(tmpdir);
|
||||
}
|
||||
if ( !options.contains("-lib") ) {
|
||||
options.add("-lib");
|
||||
options.add(tmpdir);
|
||||
}
|
||||
if ( !options.contains("-encoding") ) {
|
||||
options.add("-encoding");
|
||||
options.add("UTF-8");
|
||||
}
|
||||
options.add(new File(tmpdir,grammarFileName).toString());
|
||||
|
||||
final String[] optionsA = new String[options.size()];
|
||||
options.toArray(optionsA);
|
||||
Tool antlr = newTool(optionsA);
|
||||
ErrorQueue equeue = new ErrorQueue(antlr);
|
||||
antlr.addListener(equeue);
|
||||
if (defaultListener) {
|
||||
antlr.addListener(new DefaultToolListener(antlr));
|
||||
}
|
||||
synchronized (antlrLock) {
|
||||
antlr.processGrammarsOnCommandLine();
|
||||
}
|
||||
|
||||
if ( !defaultListener && !equeue.errors.isEmpty() ) {
|
||||
for (int i = 0; i < equeue.errors.size(); i++) {
|
||||
ANTLRMessage msg = equeue.errors.get(i);
|
||||
antlrToolErrors.append(msg.toString());
|
||||
}
|
||||
try {
|
||||
antlrToolErrors.append(new String(Utils.readFile(tmpdir+"/"+grammarFileName)));
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
antlrToolErrors.append(ioe.toString());
|
||||
}
|
||||
}
|
||||
if ( !defaultListener && !equeue.warnings.isEmpty() ) {
|
||||
for (int i = 0; i < equeue.warnings.size(); i++) {
|
||||
ANTLRMessage msg = equeue.warnings.get(i);
|
||||
// antlrToolErrors.append(msg); warnings are hushed
|
||||
}
|
||||
}
|
||||
|
||||
return equeue;
|
||||
}
|
||||
|
||||
protected ErrorQueue antlr(String grammarFileName, String grammarStr, boolean defaultListener, String... extraOptions) {
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, grammarFileName, grammarStr);
|
||||
return antlr(grammarFileName, defaultListener, extraOptions);
|
||||
}
|
||||
|
||||
protected String execLexer(String grammarFileName,
|
||||
String grammarStr,
|
||||
String lexerName,
|
||||
|
@ -380,7 +320,7 @@ public class BaseCSharpTest implements RuntimeTestSupport, SpecialRuntimeTestAss
|
|||
boolean defaultListener,
|
||||
String... extraOptions)
|
||||
{
|
||||
ErrorQueue equeue = antlr(grammarFileName, grammarStr, defaultListener, extraOptions);
|
||||
ErrorQueue equeue = antlrOnString(getTmpDir(), "CSharp", grammarFileName, grammarStr, defaultListener, extraOptions);
|
||||
if (!equeue.errors.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -610,40 +550,6 @@ public class BaseCSharpTest implements RuntimeTestSupport, SpecialRuntimeTestAss
|
|||
}
|
||||
}
|
||||
|
||||
public void testErrors(String[] pairs, boolean printTree) {
|
||||
for (int i = 0; i < pairs.length; i+=2) {
|
||||
String input = pairs[i];
|
||||
String expect = pairs[i+1];
|
||||
|
||||
String[] lines = input.split("\n");
|
||||
String fileName = getFilenameFromFirstLineOfGrammar(lines[0]);
|
||||
ErrorQueue equeue = antlr(fileName, input, false);
|
||||
|
||||
String actual = equeue.toString(true);
|
||||
actual = actual.replace(tmpdir + File.separator, "");
|
||||
System.err.println(actual);
|
||||
String msg = input;
|
||||
msg = msg.replace("\n","\\n");
|
||||
msg = msg.replace("\r","\\r");
|
||||
msg = msg.replace("\t","\\t");
|
||||
|
||||
org.junit.Assert.assertEquals("error in: "+msg,expect,actual);
|
||||
}
|
||||
}
|
||||
|
||||
public String getFilenameFromFirstLineOfGrammar(String line) {
|
||||
String fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
int grIndex = line.lastIndexOf("grammar");
|
||||
int semi = line.lastIndexOf(';');
|
||||
if ( grIndex>=0 && semi>=0 ) {
|
||||
int space = line.indexOf(' ', grIndex);
|
||||
fileName = line.substring(space+1, semi)+Tool.GRAMMAR_EXTENSION;
|
||||
}
|
||||
if ( fileName.length()==Tool.GRAMMAR_EXTENSION.length() ) fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
return fileName;
|
||||
}
|
||||
|
||||
|
||||
List<ANTLRMessage> getMessagesOfType(List<ANTLRMessage> msgs, Class<? extends ANTLRMessage> c) {
|
||||
List<ANTLRMessage> filtered = new ArrayList<ANTLRMessage>();
|
||||
for (ANTLRMessage m : msgs) {
|
||||
|
|
|
@ -54,13 +54,11 @@ import org.antlr.v4.runtime.atn.LexerATNSimulator;
|
|||
import org.antlr.v4.runtime.dfa.DFA;
|
||||
import org.antlr.v4.runtime.misc.IntegerList;
|
||||
import org.antlr.v4.runtime.misc.Interval;
|
||||
import org.antlr.v4.runtime.misc.Utils;
|
||||
import org.antlr.v4.semantics.SemanticPipeline;
|
||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||
import org.antlr.v4.tool.ANTLRMessage;
|
||||
import org.antlr.v4.tool.DOTGenerator;
|
||||
import org.antlr.v4.tool.DefaultToolListener;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.GrammarSemanticsMessage;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
|
@ -95,7 +93,7 @@ import static junit.framework.TestCase.assertEquals;
|
|||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.antlr.v4.test.runtime.java.BaseJavaTest.antlrLock;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
public class BaseGoTest implements RuntimeTestSupport {
|
||||
|
@ -324,60 +322,6 @@ public class BaseGoTest implements RuntimeTestSupport {
|
|||
return tokenTypes;
|
||||
}
|
||||
|
||||
/** Return true if all is ok, no errors */
|
||||
protected ErrorQueue antlr(String fileName, String grammarFileName,
|
||||
String grammarStr, boolean defaultListener, String... extraOptions) {
|
||||
if(grammarStr!=null) {
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, fileName, grammarStr);
|
||||
}
|
||||
final List<String> options = new ArrayList<String>();
|
||||
Collections.addAll(options, extraOptions);
|
||||
options.add("-Dlanguage=Go");
|
||||
options.add("-o");
|
||||
options.add(tmpdir.getPath());
|
||||
options.add("-lib");
|
||||
options.add(tmpdir.getPath());
|
||||
if ( !options.contains("-encoding") ) {
|
||||
options.add("-encoding");
|
||||
options.add("UTF-8");
|
||||
}
|
||||
options.add(new File(tmpdir, grammarFileName).getPath());
|
||||
|
||||
final String[] optionsA = new String[options.size()];
|
||||
options.toArray(optionsA);
|
||||
Tool antlr = newTool(optionsA);
|
||||
ErrorQueue equeue = new ErrorQueue(antlr);
|
||||
antlr.addListener(equeue);
|
||||
if (defaultListener) {
|
||||
antlr.addListener(new DefaultToolListener(antlr));
|
||||
}
|
||||
synchronized (antlrLock) {
|
||||
antlr.processGrammarsOnCommandLine();
|
||||
}
|
||||
|
||||
if ( !defaultListener && !equeue.errors.isEmpty() ) {
|
||||
for (int i = 0; i < equeue.errors.size(); i++) {
|
||||
ANTLRMessage msg = equeue.errors.get(i);
|
||||
antlrToolErrors.append(msg.toString());
|
||||
}
|
||||
try {
|
||||
antlrToolErrors.append(new String(Utils.readFile(tmpdir+"/"+grammarFileName)));
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
antlrToolErrors.append(ioe.toString());
|
||||
}
|
||||
}
|
||||
if ( !defaultListener && !equeue.warnings.isEmpty() ) {
|
||||
for (int i = 0; i < equeue.warnings.size(); i++) {
|
||||
ANTLRMessage msg = equeue.warnings.get(i);
|
||||
// antlrToolErrors.append(msg); warnings are hushed
|
||||
}
|
||||
}
|
||||
|
||||
return equeue;
|
||||
}
|
||||
|
||||
protected String execLexer(String grammarFileName, String grammarStr,
|
||||
String lexerName, String input) {
|
||||
return execLexer(grammarFileName, grammarStr, lexerName, input, false);
|
||||
|
@ -436,29 +380,12 @@ public class BaseGoTest implements RuntimeTestSupport {
|
|||
protected boolean rawGenerateAndBuildRecognizer(String grammarFileName,
|
||||
String grammarStr, String parserName, String lexerName,
|
||||
boolean defaultListener, String... extraOptions) {
|
||||
ErrorQueue equeue = antlr(grammarFileName, grammarFileName, grammarStr,
|
||||
defaultListener, extraOptions);
|
||||
|
||||
// List<String> files = new ArrayList<String>();
|
||||
// if (lexerName != null) {
|
||||
// files.add(lexerName + ".go");
|
||||
// }
|
||||
// if (parserName != null) {
|
||||
// files.add(parserName + ".go");
|
||||
// Set<String> optionsSet = new HashSet<String>(
|
||||
// Arrays.asList(extraOptions));
|
||||
// if (!optionsSet.contains("-no-listener")) {
|
||||
// files.add(grammarFileName.substring(0,
|
||||
// grammarFileName.lastIndexOf('.'))
|
||||
// + "Listener.go");
|
||||
// }
|
||||
// if (optionsSet.contains("-visitor")) {
|
||||
// files.add(grammarFileName.substring(0,
|
||||
// grammarFileName.lastIndexOf('.'))
|
||||
// + "Visitor.go");
|
||||
// }
|
||||
// }
|
||||
return true; // allIsWell: no compile
|
||||
ErrorQueue equeue = antlrOnString(getTmpDir(), "Go", grammarFileName, grammarStr,
|
||||
defaultListener, extraOptions);
|
||||
if (!equeue.errors.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void rawBuildRecognizerTestFile(String parserName,
|
||||
|
@ -565,40 +492,6 @@ public class BaseGoTest implements RuntimeTestSupport {
|
|||
return runtimeDir;
|
||||
}
|
||||
|
||||
public void testErrors(String[] pairs, boolean printTree) {
|
||||
for (int i = 0; i < pairs.length; i += 2) {
|
||||
String input = pairs[i];
|
||||
String expect = pairs[i + 1];
|
||||
|
||||
String[] lines = input.split("\n");
|
||||
String fileName = getFilenameFromFirstLineOfGrammar(lines[0]);
|
||||
ErrorQueue equeue = antlr(fileName, fileName, input, false);
|
||||
|
||||
String actual = equeue.toString(true);
|
||||
actual = actual.replace(overall_tmpdir+ File.separator, "");
|
||||
System.err.println(actual);
|
||||
String msg = input;
|
||||
msg = msg.replace("\n", "\\n");
|
||||
msg = msg.replace("\r", "\\r");
|
||||
msg = msg.replace("\t", "\\t");
|
||||
|
||||
assertEquals("error in: " + msg, expect, actual);
|
||||
}
|
||||
}
|
||||
|
||||
public String getFilenameFromFirstLineOfGrammar(String line) {
|
||||
String fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
int grIndex = line.lastIndexOf("grammar");
|
||||
int semi = line.lastIndexOf(';');
|
||||
if (grIndex >= 0 && semi >= 0) {
|
||||
int space = line.indexOf(' ', grIndex);
|
||||
fileName = line.substring(space + 1, semi) + Tool.GRAMMAR_EXTENSION;
|
||||
}
|
||||
if (fileName.length() == Tool.GRAMMAR_EXTENSION.length())
|
||||
fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
return fileName;
|
||||
}
|
||||
|
||||
// void ambig(List<Message> msgs, int[] expectedAmbigAlts, String
|
||||
// expectedAmbigInput)
|
||||
// throws Exception
|
||||
|
|
|
@ -61,10 +61,10 @@ import org.antlr.v4.runtime.misc.Pair;
|
|||
import org.antlr.v4.runtime.misc.Utils;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.antlr.v4.semantics.SemanticPipeline;
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||
import org.antlr.v4.tool.ANTLRMessage;
|
||||
import org.antlr.v4.tool.DefaultToolListener;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.GrammarSemanticsMessage;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
|
@ -475,63 +475,6 @@ public class BaseJavaTest implements RuntimeTestSupport {
|
|||
return ok;
|
||||
}
|
||||
|
||||
protected ErrorQueue antlr(String grammarFileName, boolean defaultListener, String... extraOptions) {
|
||||
final List<String> options = new ArrayList<String>();
|
||||
Collections.addAll(options, extraOptions);
|
||||
if ( !options.contains("-o") ) {
|
||||
options.add("-o");
|
||||
options.add(tmpdir);
|
||||
}
|
||||
if ( !options.contains("-lib") ) {
|
||||
options.add("-lib");
|
||||
options.add(tmpdir);
|
||||
}
|
||||
if ( !options.contains("-encoding") ) {
|
||||
options.add("-encoding");
|
||||
options.add("UTF-8");
|
||||
}
|
||||
options.add(new File(tmpdir, grammarFileName).toString());
|
||||
|
||||
final String[] optionsA = new String[options.size()];
|
||||
options.toArray(optionsA);
|
||||
Tool antlr = newTool(optionsA);
|
||||
ErrorQueue equeue = new ErrorQueue(antlr);
|
||||
antlr.addListener(equeue);
|
||||
if ( defaultListener ) {
|
||||
antlr.addListener(new DefaultToolListener(antlr));
|
||||
}
|
||||
synchronized (antlrLock) {
|
||||
antlr.processGrammarsOnCommandLine();
|
||||
}
|
||||
|
||||
if ( !defaultListener && !equeue.errors.isEmpty() ) {
|
||||
for (int i = 0; i<equeue.errors.size(); i++) {
|
||||
ANTLRMessage msg = equeue.errors.get(i);
|
||||
antlrToolErrors.append(msg.toString());
|
||||
}
|
||||
try {
|
||||
antlrToolErrors.append(new String(Utils.readFile(tmpdir+"/"+grammarFileName)));
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
antlrToolErrors.append(ioe.toString());
|
||||
}
|
||||
}
|
||||
if ( !defaultListener && !equeue.warnings.isEmpty() ) {
|
||||
for (int i = 0; i<equeue.warnings.size(); i++) {
|
||||
ANTLRMessage msg = equeue.warnings.get(i);
|
||||
// antlrToolErrors.append(msg); warnings are hushed
|
||||
}
|
||||
}
|
||||
|
||||
return equeue;
|
||||
}
|
||||
|
||||
protected ErrorQueue antlr(String grammarFileName, String grammarStr, boolean defaultListener, String... extraOptions) {
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, grammarFileName, grammarStr);
|
||||
return antlr(grammarFileName, defaultListener, extraOptions);
|
||||
}
|
||||
|
||||
protected String execLexer(String grammarFileName,
|
||||
String grammarStr,
|
||||
String lexerName,
|
||||
|
@ -679,7 +622,7 @@ public class BaseJavaTest implements RuntimeTestSupport {
|
|||
String... extraOptions)
|
||||
{
|
||||
ErrorQueue equeue =
|
||||
antlr(grammarFileName, grammarStr, defaultListener, extraOptions);
|
||||
BaseRuntimeTest.antlrOnString(getTmpDir(), "Java", grammarFileName, grammarStr, defaultListener, extraOptions);
|
||||
if (!equeue.errors.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -812,39 +755,6 @@ public class BaseJavaTest implements RuntimeTestSupport {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void testErrors(String[] pairs, boolean printTree) {
|
||||
for (int i = 0; i < pairs.length; i+=2) {
|
||||
String input = pairs[i];
|
||||
String expect = pairs[i+1];
|
||||
|
||||
String[] lines = input.split("\n");
|
||||
String fileName = getFilenameFromFirstLineOfGrammar(lines[0]);
|
||||
ErrorQueue equeue = antlr(fileName, input, false);
|
||||
|
||||
String actual = equeue.toString(true);
|
||||
actual = actual.replace(tmpdir + File.separator, "");
|
||||
// System.err.println(actual);
|
||||
String msg = input;
|
||||
msg = msg.replace("\n","\\n");
|
||||
msg = msg.replace("\r","\\r");
|
||||
msg = msg.replace("\t","\\t");
|
||||
|
||||
assertEquals("error in: "+msg,expect,actual);
|
||||
}
|
||||
}
|
||||
|
||||
public String getFilenameFromFirstLineOfGrammar(String line) {
|
||||
String fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
int grIndex = line.lastIndexOf("grammar");
|
||||
int semi = line.lastIndexOf(';');
|
||||
if ( grIndex>=0 && semi>=0 ) {
|
||||
int space = line.indexOf(' ', grIndex);
|
||||
fileName = line.substring(space+1, semi)+Tool.GRAMMAR_EXTENSION;
|
||||
}
|
||||
if ( fileName.length()==Tool.GRAMMAR_EXTENSION.length() ) fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
return fileName;
|
||||
}
|
||||
|
||||
// void ambig(List<Message> msgs, int[] expectedAmbigAlts, String expectedAmbigInput)
|
||||
// throws Exception
|
||||
// {
|
||||
|
@ -1065,11 +975,6 @@ public class BaseJavaTest implements RuntimeTestSupport {
|
|||
}
|
||||
}
|
||||
|
||||
protected void mkdir(String dir) {
|
||||
File f = new File(dir);
|
||||
f.mkdirs();
|
||||
}
|
||||
|
||||
protected void writeTestFile(String parserName,
|
||||
String lexerName,
|
||||
String parserStartRuleName,
|
||||
|
|
|
@ -54,13 +54,11 @@ import org.antlr.v4.runtime.atn.LexerATNSimulator;
|
|||
import org.antlr.v4.runtime.dfa.DFA;
|
||||
import org.antlr.v4.runtime.misc.IntegerList;
|
||||
import org.antlr.v4.runtime.misc.Interval;
|
||||
import org.antlr.v4.runtime.misc.Utils;
|
||||
import org.antlr.v4.semantics.SemanticPipeline;
|
||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||
import org.antlr.v4.tool.ANTLRMessage;
|
||||
import org.antlr.v4.tool.DOTGenerator;
|
||||
import org.antlr.v4.tool.DefaultToolListener;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.GrammarSemanticsMessage;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
|
@ -97,7 +95,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static org.antlr.v4.test.runtime.java.BaseJavaTest.antlrLock;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -272,54 +270,6 @@ public abstract class BaseBrowserTest implements RuntimeTestSupport {
|
|||
return tokenTypes;
|
||||
}
|
||||
|
||||
|
||||
/** Return true if all is ok, no errors */
|
||||
protected ErrorQueue antlr(String fileName, String grammarFileName, String grammarStr, boolean defaultListener, String... extraOptions) {
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, fileName, grammarStr);
|
||||
final List<String> options = new ArrayList<String>();
|
||||
Collections.addAll(options, extraOptions);
|
||||
options.add("-Dlanguage=JavaScript");
|
||||
options.add("-o");
|
||||
options.add(tmpdir);
|
||||
options.add("-lib");
|
||||
options.add(tmpdir);
|
||||
options.add(new File(tmpdir,grammarFileName).toString());
|
||||
|
||||
final String[] optionsA = new String[options.size()];
|
||||
options.toArray(optionsA);
|
||||
Tool antlr = newTool(optionsA);
|
||||
ErrorQueue equeue = new ErrorQueue(antlr);
|
||||
antlr.addListener(equeue);
|
||||
if (defaultListener) {
|
||||
antlr.addListener(new DefaultToolListener(antlr));
|
||||
}
|
||||
synchronized (antlrLock) {
|
||||
antlr.processGrammarsOnCommandLine();
|
||||
}
|
||||
|
||||
if ( !defaultListener && !equeue.errors.isEmpty() ) {
|
||||
for (int i = 0; i < equeue.errors.size(); i++) {
|
||||
ANTLRMessage msg = equeue.errors.get(i);
|
||||
antlrToolErrors.append(msg.toString());
|
||||
}
|
||||
try {
|
||||
antlrToolErrors.append(new String(Utils.readFile(tmpdir+"/"+grammarFileName)));
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
antlrToolErrors.append(ioe.toString());
|
||||
}
|
||||
}
|
||||
if ( !defaultListener && !equeue.warnings.isEmpty() ) {
|
||||
for (int i = 0; i < equeue.warnings.size(); i++) {
|
||||
ANTLRMessage msg = equeue.warnings.get(i);
|
||||
// antlrToolErrors.append(msg); warnings are hushed
|
||||
}
|
||||
}
|
||||
|
||||
return equeue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execLexer(String grammarFileName,
|
||||
String grammarStr,
|
||||
|
@ -399,7 +349,7 @@ public abstract class BaseBrowserTest implements RuntimeTestSupport {
|
|||
String... extraOptions)
|
||||
{
|
||||
ErrorQueue equeue =
|
||||
antlr(grammarFileName, grammarFileName, grammarStr, defaultListener, extraOptions);
|
||||
antlrOnString(getTmpDir(), "JavaScript", grammarFileName, grammarStr, defaultListener, extraOptions);
|
||||
if (!equeue.errors.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -545,39 +495,6 @@ public abstract class BaseBrowserTest implements RuntimeTestSupport {
|
|||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
public void testErrors(String[] pairs, boolean printTree) {
|
||||
for (int i = 0; i < pairs.length; i+=2) {
|
||||
String input = pairs[i];
|
||||
String expect = pairs[i+1];
|
||||
|
||||
String[] lines = input.split("\n");
|
||||
String fileName = getFilenameFromFirstLineOfGrammar(lines[0]);
|
||||
ErrorQueue equeue = antlr(fileName, fileName, input, false);
|
||||
|
||||
String actual = equeue.toString(true);
|
||||
actual = actual.replace(tmpdir + File.separator, "");
|
||||
System.err.println(actual);
|
||||
String msg = input;
|
||||
msg = msg.replace("\n","\\n");
|
||||
msg = msg.replace("\r","\\r");
|
||||
msg = msg.replace("\t","\\t");
|
||||
|
||||
assertEquals("error in: "+msg,expect,actual);
|
||||
}
|
||||
}
|
||||
|
||||
public String getFilenameFromFirstLineOfGrammar(String line) {
|
||||
String fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
int grIndex = line.lastIndexOf("grammar");
|
||||
int semi = line.lastIndexOf(';');
|
||||
if ( grIndex>=0 && semi>=0 ) {
|
||||
int space = line.indexOf(' ', grIndex);
|
||||
fileName = line.substring(space+1, semi)+Tool.GRAMMAR_EXTENSION;
|
||||
}
|
||||
if ( fileName.length()==Tool.GRAMMAR_EXTENSION.length() ) fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
return fileName;
|
||||
}
|
||||
|
||||
List<ANTLRMessage> getMessagesOfType(List<ANTLRMessage> msgs, Class<? extends ANTLRMessage> c) {
|
||||
List<ANTLRMessage> filtered = new ArrayList<ANTLRMessage>();
|
||||
for (ANTLRMessage m : msgs) {
|
||||
|
|
|
@ -54,13 +54,11 @@ import org.antlr.v4.runtime.atn.LexerATNSimulator;
|
|||
import org.antlr.v4.runtime.dfa.DFA;
|
||||
import org.antlr.v4.runtime.misc.IntegerList;
|
||||
import org.antlr.v4.runtime.misc.Interval;
|
||||
import org.antlr.v4.runtime.misc.Utils;
|
||||
import org.antlr.v4.semantics.SemanticPipeline;
|
||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||
import org.antlr.v4.tool.ANTLRMessage;
|
||||
import org.antlr.v4.tool.DOTGenerator;
|
||||
import org.antlr.v4.tool.DefaultToolListener;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.GrammarSemanticsMessage;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
|
@ -89,7 +87,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static org.antlr.v4.test.runtime.java.BaseJavaTest.antlrLock;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -260,60 +258,6 @@ public class BaseNodeTest implements RuntimeTestSupport {
|
|||
return tokenTypes;
|
||||
}
|
||||
|
||||
/** Return true if all is ok, no errors */
|
||||
protected ErrorQueue antlr(String fileName, String grammarFileName,
|
||||
String grammarStr, boolean defaultListener, String... extraOptions) {
|
||||
if(grammarStr!=null) {
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, fileName, grammarStr);
|
||||
}
|
||||
final List<String> options = new ArrayList<String>();
|
||||
Collections.addAll(options, extraOptions);
|
||||
options.add("-Dlanguage=JavaScript");
|
||||
options.add("-o");
|
||||
options.add(tmpdir);
|
||||
options.add("-lib");
|
||||
options.add(tmpdir);
|
||||
if ( !options.contains("-encoding") ) {
|
||||
options.add("-encoding");
|
||||
options.add("UTF-8");
|
||||
}
|
||||
options.add(new File(tmpdir, grammarFileName).toString());
|
||||
|
||||
final String[] optionsA = new String[options.size()];
|
||||
options.toArray(optionsA);
|
||||
Tool antlr = newTool(optionsA);
|
||||
ErrorQueue equeue = new ErrorQueue(antlr);
|
||||
antlr.addListener(equeue);
|
||||
if (defaultListener) {
|
||||
antlr.addListener(new DefaultToolListener(antlr));
|
||||
}
|
||||
synchronized (antlrLock) {
|
||||
antlr.processGrammarsOnCommandLine();
|
||||
}
|
||||
|
||||
if ( !defaultListener && !equeue.errors.isEmpty() ) {
|
||||
for (int i = 0; i < equeue.errors.size(); i++) {
|
||||
ANTLRMessage msg = equeue.errors.get(i);
|
||||
antlrToolErrors.append(msg.toString());
|
||||
}
|
||||
try {
|
||||
antlrToolErrors.append(new String(Utils.readFile(tmpdir+"/"+grammarFileName)));
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
antlrToolErrors.append(ioe.toString());
|
||||
}
|
||||
}
|
||||
if ( !defaultListener && !equeue.warnings.isEmpty() ) {
|
||||
for (int i = 0; i < equeue.warnings.size(); i++) {
|
||||
ANTLRMessage msg = equeue.warnings.get(i);
|
||||
// antlrToolErrors.append(msg); warnings are hushed
|
||||
}
|
||||
}
|
||||
|
||||
return equeue;
|
||||
}
|
||||
|
||||
protected String execLexer(String grammarFileName, String grammarStr,
|
||||
String lexerName, String input) {
|
||||
return execLexer(grammarFileName, grammarStr, lexerName, input, false);
|
||||
|
@ -361,8 +305,8 @@ public class BaseNodeTest implements RuntimeTestSupport {
|
|||
protected boolean rawGenerateAndBuildRecognizer(String grammarFileName,
|
||||
String grammarStr, String parserName, String lexerName,
|
||||
boolean defaultListener, String... extraOptions) {
|
||||
ErrorQueue equeue = antlr(grammarFileName, grammarFileName, grammarStr,
|
||||
defaultListener, extraOptions);
|
||||
ErrorQueue equeue = antlrOnString(getTmpDir(), "JavaScript", grammarFileName, grammarStr,
|
||||
defaultListener, extraOptions);
|
||||
if (!equeue.errors.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -501,40 +445,6 @@ public class BaseNodeTest implements RuntimeTestSupport {
|
|||
return System.getProperty("os.name").toLowerCase().contains("windows");
|
||||
}
|
||||
|
||||
public void testErrors(String[] pairs, boolean printTree) {
|
||||
for (int i = 0; i < pairs.length; i += 2) {
|
||||
String input = pairs[i];
|
||||
String expect = pairs[i + 1];
|
||||
|
||||
String[] lines = input.split("\n");
|
||||
String fileName = getFilenameFromFirstLineOfGrammar(lines[0]);
|
||||
ErrorQueue equeue = antlr(fileName, fileName, input, false);
|
||||
|
||||
String actual = equeue.toString(true);
|
||||
actual = actual.replace(tmpdir + File.separator, "");
|
||||
System.err.println(actual);
|
||||
String msg = input;
|
||||
msg = msg.replace("\n", "\\n");
|
||||
msg = msg.replace("\r", "\\r");
|
||||
msg = msg.replace("\t", "\\t");
|
||||
|
||||
assertEquals("error in: " + msg, expect, actual);
|
||||
}
|
||||
}
|
||||
|
||||
public String getFilenameFromFirstLineOfGrammar(String line) {
|
||||
String fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
int grIndex = line.lastIndexOf("grammar");
|
||||
int semi = line.lastIndexOf(';');
|
||||
if (grIndex >= 0 && semi >= 0) {
|
||||
int space = line.indexOf(' ', grIndex);
|
||||
fileName = line.substring(space + 1, semi) + Tool.GRAMMAR_EXTENSION;
|
||||
}
|
||||
if (fileName.length() == Tool.GRAMMAR_EXTENSION.length())
|
||||
fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
return fileName;
|
||||
}
|
||||
|
||||
// void ambig(List<Message> msgs, int[] expectedAmbigAlts, String
|
||||
// expectedAmbigInput)
|
||||
// throws Exception
|
||||
|
|
|
@ -56,14 +56,12 @@ import org.antlr.v4.runtime.atn.LexerATNSimulator;
|
|||
import org.antlr.v4.runtime.dfa.DFA;
|
||||
import org.antlr.v4.runtime.misc.IntegerList;
|
||||
import org.antlr.v4.runtime.misc.Interval;
|
||||
import org.antlr.v4.runtime.misc.Utils;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.antlr.v4.semantics.SemanticPipeline;
|
||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||
import org.antlr.v4.tool.ANTLRMessage;
|
||||
import org.antlr.v4.tool.DOTGenerator;
|
||||
import org.antlr.v4.tool.DefaultToolListener;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.GrammarSemanticsMessage;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
|
@ -95,7 +93,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static org.antlr.v4.test.runtime.java.BaseJavaTest.antlrLock;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -358,57 +356,6 @@ public abstract class BasePythonTest implements RuntimeTestSupport {
|
|||
|
||||
protected abstract String getLanguage();
|
||||
|
||||
/** Return true if all is ok, no errors */
|
||||
protected ErrorQueue antlr(String fileName, String grammarFileName, String grammarStr, boolean defaultListener, String... extraOptions) {
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, fileName, grammarStr);
|
||||
final List<String> options = new ArrayList<String>();
|
||||
Collections.addAll(options, extraOptions);
|
||||
options.add("-Dlanguage=" + getLanguage());
|
||||
options.add("-o");
|
||||
options.add(tmpdir);
|
||||
options.add("-lib");
|
||||
options.add(tmpdir);
|
||||
if ( !options.contains("-encoding") ) {
|
||||
options.add("-encoding");
|
||||
options.add("UTF-8");
|
||||
}
|
||||
options.add(new File(tmpdir,grammarFileName).toString());
|
||||
|
||||
final String[] optionsA = new String[options.size()];
|
||||
options.toArray(optionsA);
|
||||
Tool antlr = newTool(optionsA);
|
||||
ErrorQueue equeue = new ErrorQueue(antlr);
|
||||
antlr.addListener(equeue);
|
||||
if (defaultListener) {
|
||||
antlr.addListener(new DefaultToolListener(antlr));
|
||||
}
|
||||
synchronized (antlrLock) {
|
||||
antlr.processGrammarsOnCommandLine();
|
||||
}
|
||||
|
||||
if ( !defaultListener && !equeue.errors.isEmpty() ) {
|
||||
for (int i = 0; i < equeue.errors.size(); i++) {
|
||||
ANTLRMessage msg = equeue.errors.get(i);
|
||||
antlrToolErrors.append(msg.toString());
|
||||
}
|
||||
try {
|
||||
antlrToolErrors.append(new String(Utils.readFile(tmpdir+"/"+grammarFileName)));
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
antlrToolErrors.append(ioe.toString());
|
||||
}
|
||||
}
|
||||
if ( !defaultListener && !equeue.warnings.isEmpty() ) {
|
||||
for (int i = 0; i < equeue.warnings.size(); i++) {
|
||||
ANTLRMessage msg = equeue.warnings.get(i);
|
||||
// antlrToolErrors.append(msg); warnings are hushed
|
||||
}
|
||||
}
|
||||
|
||||
return equeue;
|
||||
}
|
||||
|
||||
protected String execLexer(String grammarFileName,
|
||||
String grammarStr,
|
||||
String lexerName,
|
||||
|
@ -514,7 +461,7 @@ public abstract class BasePythonTest implements RuntimeTestSupport {
|
|||
String... extraOptions)
|
||||
{
|
||||
ErrorQueue equeue =
|
||||
antlr(grammarFileName, grammarFileName, grammarStr, defaultListener, extraOptions);
|
||||
antlrOnString(getTmpDir(), getLanguage(), grammarFileName, grammarStr, defaultListener, extraOptions);
|
||||
if (!equeue.errors.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -636,39 +583,6 @@ public abstract class BasePythonTest implements RuntimeTestSupport {
|
|||
return System.getProperty("os.name").toLowerCase().contains("windows");
|
||||
}
|
||||
|
||||
public void testErrors(String[] pairs, boolean printTree) {
|
||||
for (int i = 0; i < pairs.length; i+=2) {
|
||||
String input = pairs[i];
|
||||
String expect = pairs[i+1];
|
||||
|
||||
String[] lines = input.split("\n");
|
||||
String fileName = getFilenameFromFirstLineOfGrammar(lines[0]);
|
||||
ErrorQueue equeue = antlr(fileName, fileName, input, false);
|
||||
|
||||
String actual = equeue.toString(true);
|
||||
actual = actual.replace(tmpdir + File.separator, "");
|
||||
System.err.println(actual);
|
||||
String msg = input;
|
||||
msg = msg.replace("\n","\\n");
|
||||
msg = msg.replace("\r","\\r");
|
||||
msg = msg.replace("\t","\\t");
|
||||
|
||||
assertEquals("error in: "+msg,expect,actual);
|
||||
}
|
||||
}
|
||||
|
||||
public String getFilenameFromFirstLineOfGrammar(String line) {
|
||||
String fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
int grIndex = line.lastIndexOf("grammar");
|
||||
int semi = line.lastIndexOf(';');
|
||||
if ( grIndex>=0 && semi>=0 ) {
|
||||
int space = line.indexOf(' ', grIndex);
|
||||
fileName = line.substring(space+1, semi)+Tool.GRAMMAR_EXTENSION;
|
||||
}
|
||||
if ( fileName.length()==Tool.GRAMMAR_EXTENSION.length() ) fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
return fileName;
|
||||
}
|
||||
|
||||
// void ambig(List<Message> msgs, int[] expectedAmbigAlts, String expectedAmbigInput)
|
||||
// throws Exception
|
||||
// {
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package org.antlr.v4.test.runtime.swift;
|
||||
|
||||
import org.antlr.v4.Tool;
|
||||
import org.antlr.v4.runtime.misc.Utils;
|
||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||
import org.antlr.v4.tool.ANTLRMessage;
|
||||
import org.antlr.v4.tool.DefaultToolListener;
|
||||
import org.stringtemplate.v4.ST;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
@ -23,7 +20,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.antlr.v4.test.runtime.java.BaseJavaTest.antlrLock;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BaseSwiftTest implements RuntimeTestSupport {
|
||||
|
@ -489,7 +486,7 @@ public class BaseSwiftTest implements RuntimeTestSupport {
|
|||
String lexerName,
|
||||
boolean defaultListener,
|
||||
String... extraOptions) {
|
||||
ErrorQueue equeue = antlr(grammarFileName, grammarStr, defaultListener, extraOptions);
|
||||
ErrorQueue equeue = antlrOnString(getTmpDir(), "Swift", grammarFileName, grammarStr, defaultListener, extraOptions);
|
||||
if (!equeue.errors.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -517,63 +514,6 @@ public class BaseSwiftTest implements RuntimeTestSupport {
|
|||
return true;
|
||||
}
|
||||
|
||||
protected ErrorQueue antlr(String grammarFileName, boolean defaultListener, String... extraOptions) {
|
||||
final List<String> options = new ArrayList<String>();
|
||||
Collections.addAll(options, extraOptions);
|
||||
options.add("-Dlanguage=Swift");
|
||||
if ( !options.contains("-o") ) {
|
||||
options.add("-o");
|
||||
options.add(tmpdir);
|
||||
}
|
||||
if ( !options.contains("-lib") ) {
|
||||
options.add("-lib");
|
||||
options.add(tmpdir);
|
||||
}
|
||||
if ( !options.contains("-encoding") ) {
|
||||
options.add("-encoding");
|
||||
options.add("UTF-8");
|
||||
}
|
||||
options.add(new File(tmpdir, grammarFileName).toString());
|
||||
|
||||
final String[] optionsA = new String[options.size()];
|
||||
options.toArray(optionsA);
|
||||
Tool antlr = newTool(optionsA);
|
||||
ErrorQueue equeue = new ErrorQueue(antlr);
|
||||
antlr.addListener(equeue);
|
||||
if ( defaultListener ) {
|
||||
antlr.addListener(new DefaultToolListener(antlr));
|
||||
}
|
||||
synchronized (antlrLock) {
|
||||
antlr.processGrammarsOnCommandLine();
|
||||
}
|
||||
|
||||
if ( !defaultListener && !equeue.errors.isEmpty() ) {
|
||||
for (int i = 0; i<equeue.errors.size(); i++) {
|
||||
ANTLRMessage msg = equeue.errors.get(i);
|
||||
antlrToolErrors.append(msg.toString());
|
||||
}
|
||||
try {
|
||||
antlrToolErrors.append(new String(Utils.readFile(tmpdir+"/"+grammarFileName)));
|
||||
} catch (IOException ioe) {
|
||||
antlrToolErrors.append(ioe.toString());
|
||||
}
|
||||
}
|
||||
if ( !defaultListener && !equeue.warnings.isEmpty() ) {
|
||||
for (int i = 0; i<equeue.warnings.size(); i++) {
|
||||
ANTLRMessage msg = equeue.warnings.get(i);
|
||||
// antlrToolErrors.append(msg); warnings are hushed
|
||||
}
|
||||
}
|
||||
|
||||
return equeue;
|
||||
}
|
||||
|
||||
protected ErrorQueue antlr(String grammarFileName, String grammarStr, boolean defaultListener, String... extraOptions) {
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, grammarFileName, grammarStr);
|
||||
return antlr(grammarFileName, defaultListener, extraOptions);
|
||||
}
|
||||
|
||||
protected static void mkdir(String dir) {
|
||||
File f = new File(dir);
|
||||
f.mkdirs();
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package org.antlr.v4.test.tool;
|
||||
|
||||
import org.antlr.v4.Tool;
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class BaseJavaToolTest extends BaseJavaTest {
|
||||
public void testErrors(String[] pairs, boolean printTree) {
|
||||
for (int i = 0; i < pairs.length; i+=2) {
|
||||
String grammarStr = pairs[i];
|
||||
String expect = pairs[i+1];
|
||||
|
||||
String[] lines = grammarStr.split("\n");
|
||||
String fileName = getFilenameFromFirstLineOfGrammar(lines[0]);
|
||||
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, null, fileName, grammarStr, false); // use default language target in case test overrides
|
||||
|
||||
String actual = equeue.toString(true);
|
||||
actual = actual.replace(tmpdir + File.separator, "");
|
||||
// System.err.println(actual);
|
||||
String msg = grammarStr;
|
||||
msg = msg.replace("\n","\\n");
|
||||
msg = msg.replace("\r","\\r");
|
||||
msg = msg.replace("\t","\\t");
|
||||
|
||||
assertEquals("error in: "+msg,expect,actual);
|
||||
}
|
||||
}
|
||||
|
||||
public String getFilenameFromFirstLineOfGrammar(String line) {
|
||||
String fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
int grIndex = line.lastIndexOf("grammar");
|
||||
int semi = line.lastIndexOf(';');
|
||||
if ( grIndex>=0 && semi>=0 ) {
|
||||
int space = line.indexOf(' ', grIndex);
|
||||
fileName = line.substring(space+1, semi)+Tool.GRAMMAR_EXTENSION;
|
||||
}
|
||||
if ( fileName.length()==Tool.GRAMMAR_EXTENSION.length() ) fileName = "A" + Tool.GRAMMAR_EXTENSION;
|
||||
return fileName;
|
||||
}
|
||||
}
|
|
@ -37,7 +37,6 @@ import org.antlr.v4.parse.ANTLRParser;
|
|||
import org.antlr.v4.runtime.atn.ATN;
|
||||
import org.antlr.v4.runtime.atn.ATNState;
|
||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.ErrorType;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
|
@ -55,7 +54,7 @@ import java.util.Map;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TestATNConstruction extends BaseJavaTest {
|
||||
public class TestATNConstruction extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.antlr.v4.runtime.atn.ATN;
|
|||
import org.antlr.v4.runtime.atn.ATNDeserializer;
|
||||
import org.antlr.v4.runtime.atn.ATNSerializer;
|
||||
import org.antlr.v4.runtime.misc.Utils;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
import org.junit.Before;
|
||||
|
@ -44,7 +43,7 @@ import java.util.Arrays;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestATNDeserialization extends BaseJavaTest {
|
||||
public class TestATNDeserialization extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -39,7 +39,6 @@ import org.antlr.v4.runtime.atn.BlockStartState;
|
|||
import org.antlr.v4.runtime.atn.LexerATNSimulator;
|
||||
import org.antlr.v4.runtime.dfa.DFA;
|
||||
import org.antlr.v4.runtime.misc.IntegerList;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.DOTGenerator;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
|
@ -53,7 +52,7 @@ import static org.junit.Assert.assertEquals;
|
|||
// NOTICE: TOKENS IN LEXER, PARSER MUST BE SAME OR TOKEN TYPE MISMATCH
|
||||
// NOTICE: TOKENS IN LEXER, PARSER MUST BE SAME OR TOKEN TYPE MISMATCH
|
||||
|
||||
public class TestATNInterpreter extends BaseJavaTest {
|
||||
public class TestATNInterpreter extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.antlr.v4.runtime.CharStream;
|
|||
import org.antlr.v4.runtime.atn.ATN;
|
||||
import org.antlr.v4.runtime.atn.ATNState;
|
||||
import org.antlr.v4.runtime.misc.Utils;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.DOTGenerator;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
import org.junit.Before;
|
||||
|
@ -58,7 +57,7 @@ import static org.junit.Assert.assertEquals;
|
|||
* want, but occasionally there are some quirks as you'll see from
|
||||
* the tests below.
|
||||
*/
|
||||
public class TestATNLexerInterpreter extends BaseJavaTest {
|
||||
public class TestATNLexerInterpreter extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -41,7 +41,6 @@ import org.antlr.v4.runtime.atn.LexerATNSimulator;
|
|||
import org.antlr.v4.runtime.atn.PredictionContextCache;
|
||||
import org.antlr.v4.runtime.dfa.DFA;
|
||||
import org.antlr.v4.runtime.misc.IntegerList;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.DOTGenerator;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.LeftRecursiveRule;
|
||||
|
@ -59,7 +58,7 @@ import static org.junit.Assert.assertTrue;
|
|||
// NOTICE: TOKENS IN LEXER, PARSER MUST BE SAME OR TOKEN TYPE MISMATCH
|
||||
// NOTICE: TOKENS IN LEXER, PARSER MUST BE SAME OR TOKEN TYPE MISMATCH
|
||||
|
||||
public class TestATNParserPrediction extends BaseJavaTest {
|
||||
public class TestATNParserPrediction extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -32,7 +32,6 @@ package org.antlr.v4.test.tool;
|
|||
|
||||
import org.antlr.v4.runtime.atn.ATN;
|
||||
import org.antlr.v4.runtime.atn.ATNSerializer;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.DOTGenerator;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
|
@ -43,7 +42,7 @@ import java.util.Arrays;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestATNSerialization extends BaseJavaTest {
|
||||
public class TestATNSerialization extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.antlr.runtime.ANTLRStringStream;
|
|||
import org.antlr.runtime.Token;
|
||||
import org.antlr.v4.parse.ActionSplitter;
|
||||
import org.antlr.v4.semantics.BlankActionSplitterListener;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -43,7 +42,7 @@ import java.util.List;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestActionSplitter extends BaseJavaTest {
|
||||
public class TestActionSplitter extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -30,14 +30,13 @@
|
|||
|
||||
package org.antlr.v4.test.tool;
|
||||
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/** */
|
||||
@SuppressWarnings("unused")
|
||||
public class TestActionTranslation extends BaseJavaTest {
|
||||
public class TestActionTranslation extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
package org.antlr.v4.test.tool;
|
||||
|
||||
import org.antlr.runtime.RecognitionException;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.ErrorType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -40,7 +39,7 @@ import org.stringtemplate.v4.STGroup;
|
|||
import org.stringtemplate.v4.misc.ErrorBuffer;
|
||||
|
||||
/** */
|
||||
public class TestAttributeChecks extends BaseJavaTest {
|
||||
public class TestAttributeChecks extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -30,13 +30,12 @@
|
|||
|
||||
package org.antlr.v4.test.tool;
|
||||
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.ErrorType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.stringtemplate.v4.ST;
|
||||
|
||||
public class TestBasicSemanticErrors extends BaseJavaTest {
|
||||
public class TestBasicSemanticErrors extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -37,14 +37,13 @@ import org.antlr.v4.runtime.LexerInterpreter;
|
|||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.TokenSource;
|
||||
import org.antlr.v4.runtime.TokenStream;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestBufferedTokenStream extends BaseJavaTest {
|
||||
public class TestBufferedTokenStream extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.antlr.v4.automata.ParserATNFactory;
|
|||
import org.antlr.v4.codegen.CodeGenerator;
|
||||
import org.antlr.v4.semantics.SemanticPipeline;
|
||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
import org.junit.Before;
|
||||
|
@ -57,7 +56,7 @@ import java.util.List;
|
|||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
public class TestCodeGeneration extends BaseJavaTest {
|
||||
public class TestCodeGeneration extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
|
||||
package org.antlr.v4.test.tool;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.ANTLRMessage;
|
||||
import org.antlr.v4.tool.ErrorType;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
|
@ -44,7 +44,7 @@ import java.io.File;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class TestCompositeGrammars extends BaseJavaTest {
|
||||
public class TestCompositeGrammars extends BaseJavaToolTest {
|
||||
protected boolean debug = false;
|
||||
|
||||
@Before
|
||||
|
@ -57,9 +57,9 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
String slave =
|
||||
"parser grammar S;\n" +
|
||||
"a : B {System.out.println(\"S.a\");} ;\n";
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
String subdir = tmpdir + "/sub";
|
||||
mkdir(subdir);
|
||||
BaseRuntimeTest.mkdir(subdir);
|
||||
writeFile(subdir, "S.g4", slave);
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
|
@ -68,19 +68,19 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
"B : 'b' ;" + // defines B from inherited token space
|
||||
"WS : (' '|'\\n') -> skip ;\n" ;
|
||||
writeFile(tmpdir, "M.g4", master);
|
||||
ErrorQueue equeue = antlr("M.g4", false, "-lib", subdir);
|
||||
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "M.g4", false, "-lib", subdir);
|
||||
assertEquals(0, equeue.size());
|
||||
}
|
||||
|
||||
// Test for https://github.com/antlr/antlr4/issues/1317
|
||||
@Test public void testImportSelfLoop() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import M;\n" +
|
||||
"s : 'a' ;\n";
|
||||
writeFile(tmpdir, "M.g4", master);
|
||||
ErrorQueue equeue = antlr("M.g4", false, "-lib", tmpdir);
|
||||
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "M.g4", false, "-lib", tmpdir);
|
||||
assertEquals(0, equeue.size());
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
"tokens { C, B, A } // reverse order\n"+
|
||||
"y : A ;\n";
|
||||
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g4", slaveS);
|
||||
writeFile(tmpdir, "T.g4", slaveT);
|
||||
|
||||
|
@ -132,13 +132,13 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
String slave =
|
||||
"parser grammar S;\n" +
|
||||
"a : 'a' | c;\n";
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import S;\n";
|
||||
writeFile(tmpdir, "M.g4", master);
|
||||
ErrorQueue equeue = antlr("M.g4", false, "-lib", tmpdir);
|
||||
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "M.g4", false, "-lib", tmpdir);
|
||||
ANTLRMessage msg = equeue.errors.get(0);
|
||||
assertEquals(ErrorType.UNDEFINED_RULE_REF, msg.getErrorType());
|
||||
assertEquals("c", msg.getArgs()[0]);
|
||||
|
@ -151,9 +151,9 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
String slave =
|
||||
"parser grammar S;\n" +
|
||||
"a : B {System.out.println(\"S.a\");} ;\n";
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
String outdir = tmpdir + "/out";
|
||||
mkdir(outdir);
|
||||
BaseRuntimeTest.mkdir(outdir);
|
||||
writeFile(outdir, "S.g4", slave);
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
|
@ -162,7 +162,7 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
"B : 'b' ;" + // defines B from inherited token space
|
||||
"WS : (' '|'\\n') -> skip ;\n" ;
|
||||
writeFile(tmpdir, "M.g4", master);
|
||||
ErrorQueue equeue = antlr("M.g4", false, "-o", outdir);
|
||||
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "M.g4", false, "-o", outdir);
|
||||
assertEquals(ErrorType.CANNOT_FIND_IMPORTED_GRAMMAR, equeue.errors.get(0).getErrorType());
|
||||
}
|
||||
|
||||
|
@ -170,9 +170,9 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
String slave =
|
||||
"parser grammar S;\n" +
|
||||
"a : B {System.out.println(\"S.a\");} ;\n";
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
String subdir = tmpdir + "/sub";
|
||||
mkdir(subdir);
|
||||
BaseRuntimeTest.mkdir(subdir);
|
||||
writeFile(subdir, "S.g4", slave);
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
|
@ -182,8 +182,8 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
"WS : (' '|'\\n') -> skip ;\n" ;
|
||||
writeFile(tmpdir, "M.g4", master);
|
||||
String outdir = tmpdir + "/out";
|
||||
mkdir(outdir);
|
||||
ErrorQueue equeue = antlr("M.g4", false, "-o", outdir, "-lib", subdir);
|
||||
BaseRuntimeTest.mkdir(outdir);
|
||||
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "M.g4", false, "-o", outdir, "-lib", subdir);
|
||||
assertEquals(0, equeue.size());
|
||||
}
|
||||
|
||||
|
@ -191,9 +191,9 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
String slave =
|
||||
"parser grammar S;\n" +
|
||||
"a : B {System.out.println(\"S.a\");} ;\n";
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
String subdir = tmpdir + "/sub";
|
||||
mkdir(subdir);
|
||||
BaseRuntimeTest.mkdir(subdir);
|
||||
writeFile(subdir, "S.g4", slave);
|
||||
String parser =
|
||||
"parser grammar MParser;\n" +
|
||||
|
@ -207,10 +207,10 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
"WS : (' '|'\\n') -> skip ;\n" ;
|
||||
writeFile(tmpdir, "MLexer.g4", lexer);
|
||||
String outdir = tmpdir + "/out";
|
||||
mkdir(outdir);
|
||||
ErrorQueue equeue = antlr("MLexer.g4", false, "-o", outdir);
|
||||
BaseRuntimeTest.mkdir(outdir);
|
||||
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "MLexer.g4", false, "-o", outdir);
|
||||
assertEquals(0, equeue.size());
|
||||
equeue = antlr("MParser.g4", false, "-o", outdir, "-lib", subdir);
|
||||
equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "MParser.g4", false, "-o", outdir, "-lib", subdir);
|
||||
assertEquals(0, equeue.size());
|
||||
}
|
||||
|
||||
|
@ -221,7 +221,7 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
"options {tokenVocab=whatever;}\n" +
|
||||
"tokens { A }\n" +
|
||||
"x : A {System.out.println(\"S.x\");} ;\n";
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
|
||||
String master =
|
||||
|
@ -247,7 +247,7 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
String slave =
|
||||
"parser grammar S;\n" +
|
||||
"options {toke\n";
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
|
||||
String master =
|
||||
|
@ -267,13 +267,13 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
String slave =
|
||||
"parser grammar T;\n" +
|
||||
"a : T ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "T.g4", slave);
|
||||
String slave2 =
|
||||
"parser grammar S;\n" +
|
||||
"import T;\n" +
|
||||
"a : S ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g4", slave2);
|
||||
|
||||
String master =
|
||||
|
@ -307,34 +307,34 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
"parser grammar T;\n" +
|
||||
"tokens{T}\n" +
|
||||
"x : T ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "T.g4", slave);
|
||||
slave =
|
||||
"parser grammar S;\n" +
|
||||
"import T;\n" +
|
||||
"tokens{S}\n" +
|
||||
"y : S ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
|
||||
slave =
|
||||
"parser grammar C;\n" +
|
||||
"tokens{C}\n" +
|
||||
"i : C ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "C.g4", slave);
|
||||
slave =
|
||||
"parser grammar B;\n" +
|
||||
"tokens{B}\n" +
|
||||
"j : B ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "B.g4", slave);
|
||||
slave =
|
||||
"parser grammar A;\n" +
|
||||
"import B,C;\n" +
|
||||
"tokens{A}\n" +
|
||||
"k : A ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "A.g4", slave);
|
||||
|
||||
String master =
|
||||
|
@ -368,13 +368,13 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
String slave =
|
||||
"parser grammar T;\n" +
|
||||
"x : T ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "T.g4", slave);
|
||||
String slave2 =
|
||||
"parser grammar S;\n" + // A, B, C token type order
|
||||
"import T;\n" +
|
||||
"a : S ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g4", slave2);
|
||||
|
||||
String master =
|
||||
|
@ -406,27 +406,27 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
"T2: '2';\n" +
|
||||
"T3: '3';\n" +
|
||||
"T4: '4';\n" ;
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "L.g4", gstr);
|
||||
gstr =
|
||||
"parser grammar G1;\n" +
|
||||
"s: a | b;\n" +
|
||||
"a: T1;\n" +
|
||||
"b: T2;\n" ;
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "G1.g4", gstr);
|
||||
|
||||
gstr =
|
||||
"parser grammar G2;\n" +
|
||||
"import G1;\n" +
|
||||
"a: T3;\n" ;
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "G2.g4", gstr);
|
||||
String G3str =
|
||||
"grammar G3;\n" +
|
||||
"import G2;\n" +
|
||||
"b: T4;\n" ;
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "G3.g4", G3str);
|
||||
|
||||
Grammar g = new Grammar(tmpdir+"/G3.g4", G3str, equeue);
|
||||
|
@ -453,7 +453,7 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
String slave =
|
||||
"parser grammar S;\n" +
|
||||
"a : B {System.out.print(\"S.a\");} ;\n";
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
|
@ -462,7 +462,7 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
"s : a ;\n" +
|
||||
"B : 'b' ;" + // defines B from inherited token space
|
||||
"WS : (' '|'\\n') -> skip ;\n" ;
|
||||
ErrorQueue equeue = antlr("M.g4", master, false);
|
||||
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "M.g4", master, false);
|
||||
int expecting = 0; // should be ok
|
||||
assertEquals(expecting, equeue.errors.size());
|
||||
}
|
||||
|
@ -481,7 +481,7 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
"grammar NewJava;\n" +
|
||||
"import Java;\n";
|
||||
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "Java.g4", slave);
|
||||
String found = execParser("NewJava.g4", master, "NewJavaParser", "NewJavaLexer",
|
||||
null, null, "compilationUnit", "package Foo;", debug);
|
||||
|
@ -509,7 +509,7 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
"import Java;\n" +
|
||||
"s : e ;\n";
|
||||
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
writeFile(tmpdir, "Java.g4", slave);
|
||||
String found = execParser("T.g4", master, "TParser", "TLexer",
|
||||
null, null, "s", "a=b", debug);
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
package org.antlr.v4.test.tool;
|
||||
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TestDollarParser extends BaseJavaTest {
|
||||
public class TestDollarParser extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -29,13 +29,12 @@
|
|||
*/
|
||||
package org.antlr.v4.test.tool;
|
||||
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.ErrorType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/** Test errors with the set stuff in lexer and parser */
|
||||
public class TestErrorSets extends BaseJavaTest {
|
||||
public class TestErrorSets extends BaseJavaToolTest {
|
||||
protected boolean debug = false;
|
||||
|
||||
@Before
|
||||
|
|
|
@ -33,7 +33,6 @@ package org.antlr.v4.test.tool;
|
|||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.misc.IntervalSet;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -41,7 +40,7 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TestIntervalSet extends BaseJavaTest {
|
||||
public class TestIntervalSet extends BaseJavaToolTest {
|
||||
|
||||
/** Public default constructor used by TestRig */
|
||||
public TestIntervalSet() {
|
||||
|
|
|
@ -30,13 +30,12 @@
|
|||
|
||||
package org.antlr.v4.test.tool;
|
||||
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.ErrorType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/** */
|
||||
public class TestLeftRecursionToolIssues extends BaseJavaTest {
|
||||
public class TestLeftRecursionToolIssues extends BaseJavaToolTest {
|
||||
protected boolean debug = false;
|
||||
|
||||
@Before
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package org.antlr.v4.test.tool;
|
||||
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestLexerActions extends BaseJavaTest {
|
||||
public class TestLexerActions extends BaseJavaToolTest {
|
||||
|
||||
@Before
|
||||
@Override
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.antlr.v4.runtime.tree.ParseTree;
|
|||
import org.antlr.v4.runtime.tree.pattern.ParseTreeMatch;
|
||||
import org.antlr.v4.runtime.tree.pattern.ParseTreePattern;
|
||||
import org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -25,7 +24,7 @@ import static org.junit.Assert.assertNotNull;
|
|||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TestParseTreeMatcher extends BaseJavaTest {
|
||||
public class TestParseTreeMatcher extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
|
||||
package org.antlr.v4.test.tool;
|
||||
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
@ -70,7 +69,7 @@ import static org.junit.Assert.assertTrue;
|
|||
* Nongreedy loops match as much input as possible while still allowing
|
||||
* the remaining input to match.
|
||||
*/
|
||||
public class TestParserExec extends BaseJavaTest {
|
||||
public class TestParserExec extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.antlr.v4.runtime.CommonTokenStream;
|
|||
import org.antlr.v4.runtime.LexerInterpreter;
|
||||
import org.antlr.v4.runtime.ParserInterpreter;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
import org.junit.Before;
|
||||
|
@ -44,7 +43,7 @@ import org.junit.Test;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
public class TestParserInterpreter extends BaseJavaTest {
|
||||
public class TestParserInterpreter extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.antlr.v4.runtime.LexerInterpreter;
|
|||
import org.antlr.v4.runtime.ParserInterpreter;
|
||||
import org.antlr.v4.runtime.ParserRuleContext;
|
||||
import org.antlr.v4.runtime.atn.DecisionInfo;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
import org.antlr.v4.tool.Rule;
|
||||
|
@ -49,7 +48,7 @@ import java.util.Arrays;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class TestParserProfiler extends BaseJavaTest {
|
||||
public class TestParserProfiler extends BaseJavaToolTest {
|
||||
LexerGrammar lg;
|
||||
|
||||
@Before
|
||||
|
|
|
@ -63,8 +63,8 @@ import org.antlr.v4.runtime.tree.ParseTree;
|
|||
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -108,7 +108,7 @@ import static org.junit.Assert.assertThat;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class TestPerformance extends BaseJavaTest {
|
||||
public class TestPerformance extends BaseJavaToolTest {
|
||||
/**
|
||||
* Parse all java files under this package within the JDK_SOURCE_ROOT
|
||||
* (environment variable or property defined on the Java command line).
|
||||
|
@ -1961,7 +1961,7 @@ public class TestPerformance extends BaseJavaTest {
|
|||
"\n" +
|
||||
"rule_%d_%d : EOF;\n";
|
||||
|
||||
mkdir(tmpdir);
|
||||
BaseRuntimeTest.mkdir(tmpdir);
|
||||
|
||||
long startTime = System.nanoTime();
|
||||
|
||||
|
@ -1976,7 +1976,7 @@ public class TestPerformance extends BaseJavaTest {
|
|||
}
|
||||
}
|
||||
|
||||
ErrorQueue equeue = antlr("Level_0_1.g4", false);
|
||||
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(tmpdir, "Java", "Level_0_1.g4", false);
|
||||
Assert.assertTrue(equeue.errors.isEmpty());
|
||||
|
||||
long endTime = System.nanoTime();
|
||||
|
|
|
@ -32,7 +32,6 @@ package org.antlr.v4.test.tool;
|
|||
|
||||
import org.antlr.v4.misc.Utils;
|
||||
import org.antlr.v4.parse.ScopeParser;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.Attribute;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.junit.Before;
|
||||
|
@ -48,7 +47,7 @@ import java.util.List;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestScopeParsing extends BaseJavaTest {
|
||||
public class TestScopeParsing extends BaseJavaToolTest {
|
||||
static String[] argPairs = {
|
||||
"", "",
|
||||
" ", "",
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
|
||||
package org.antlr.v4.test.tool;
|
||||
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.ErrorType;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
import org.junit.Before;
|
||||
|
@ -39,7 +38,7 @@ import org.junit.Test;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/** */
|
||||
public class TestSymbolIssues extends BaseJavaTest {
|
||||
public class TestSymbolIssues extends BaseJavaToolTest {
|
||||
static String[] A = {
|
||||
// INPUT
|
||||
"grammar A;\n" +
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.antlr.runtime.Token;
|
|||
import org.antlr.v4.misc.Utils;
|
||||
import org.antlr.v4.parse.ANTLRParser;
|
||||
import org.antlr.v4.runtime.misc.IntervalSet;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.ast.GrammarAST;
|
||||
import org.junit.Before;
|
||||
|
@ -44,7 +43,7 @@ import java.util.List;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestTokenPositionOptions extends BaseJavaTest {
|
||||
public class TestTokenPositionOptions extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.antlr.v4.runtime.CommonTokenStream;
|
|||
import org.antlr.v4.runtime.LexerInterpreter;
|
||||
import org.antlr.v4.runtime.TokenStreamRewriter;
|
||||
import org.antlr.v4.runtime.misc.Interval;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
|
@ -43,7 +42,7 @@ import org.junit.Test;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class TestTokenStreamRewriter extends BaseJavaTest {
|
||||
public class TestTokenStreamRewriter extends BaseJavaToolTest {
|
||||
|
||||
/** Public default constructor used by TestRig */
|
||||
public TestTokenStreamRewriter() {
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
package org.antlr.v4.test.tool;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
import org.junit.Test;
|
||||
|
@ -45,7 +44,7 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TestTokenTypeAssignment extends BaseJavaTest {
|
||||
public class TestTokenTypeAssignment extends BaseJavaToolTest {
|
||||
|
||||
@Test
|
||||
public void testParserSimpleTokens() throws Exception {
|
||||
|
|
|
@ -31,12 +31,11 @@
|
|||
package org.antlr.v4.test.tool;
|
||||
|
||||
import org.antlr.v4.Tool;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.ErrorType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestToolSyntaxErrors extends BaseJavaTest {
|
||||
public class TestToolSyntaxErrors extends BaseJavaToolTest {
|
||||
static String[] A = {
|
||||
// INPUT
|
||||
"grammar A;\n" +
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
package org.antlr.v4.test.tool;
|
||||
|
||||
import org.antlr.v4.misc.Graph;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -39,7 +38,7 @@ import java.util.List;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/** Test topo sort in GraphNode. */
|
||||
public class TestTopologicalSort extends BaseJavaTest {
|
||||
public class TestTopologicalSort extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -37,7 +37,6 @@ import org.antlr.v4.runtime.IntStream;
|
|||
import org.antlr.v4.runtime.LexerInterpreter;
|
||||
import org.antlr.v4.runtime.UnbufferedCharStream;
|
||||
import org.antlr.v4.runtime.misc.Interval;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -48,7 +47,7 @@ import java.io.StringReader;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class TestUnbufferedCharStream extends BaseJavaTest {
|
||||
public class TestUnbufferedCharStream extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -37,7 +37,6 @@ import org.antlr.v4.runtime.Token;
|
|||
import org.antlr.v4.runtime.TokenSource;
|
||||
import org.antlr.v4.runtime.TokenStream;
|
||||
import org.antlr.v4.runtime.UnbufferedTokenStream;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -50,7 +49,7 @@ import java.util.List;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class TestUnbufferedTokenStream extends BaseJavaTest {
|
||||
public class TestUnbufferedTokenStream extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -32,7 +32,6 @@ package org.antlr.v4.test.tool;
|
|||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.Vocabulary;
|
||||
import org.antlr.v4.runtime.VocabularyImpl;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -41,7 +40,7 @@ import org.junit.Test;
|
|||
*
|
||||
* @author Sam Harwell
|
||||
*/
|
||||
public class TestVocabulary extends BaseJavaTest {
|
||||
public class TestVocabulary extends BaseJavaToolTest {
|
||||
@Before
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.antlr.v4.runtime.misc.Pair;
|
|||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
import org.antlr.v4.runtime.tree.xpath.XPath;
|
||||
import org.antlr.v4.test.runtime.java.BaseJavaTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -18,7 +17,7 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TestXPath extends BaseJavaTest {
|
||||
public class TestXPath extends BaseJavaToolTest {
|
||||
public static final String grammar =
|
||||
"grammar Expr;\n" +
|
||||
"prog: func+ ;\n" +
|
||||
|
|
Loading…
Reference in New Issue