Merge branch 'test-reporting' of git://github.com/sharwell/antlr4

This commit is contained in:
Terence Parr 2012-04-04 13:08:07 -07:00
commit 8658be69ba
3 changed files with 33 additions and 9 deletions

View File

@ -54,6 +54,7 @@ import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.Nullable; import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.semantics.SemanticPipeline; import org.antlr.v4.semantics.SemanticPipeline;
import org.antlr.v4.tool.ANTLRMessage; import org.antlr.v4.tool.ANTLRMessage;
import org.antlr.v4.tool.DefaultToolListener;
import org.antlr.v4.tool.DOTGenerator; import org.antlr.v4.tool.DOTGenerator;
import org.antlr.v4.tool.Grammar; import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.GrammarSemanticsMessage; import org.antlr.v4.tool.GrammarSemanticsMessage;
@ -383,7 +384,7 @@ public abstract class BaseTest {
/** Return true if all is ok, no errors */ /** Return true if all is ok, no errors */
protected boolean antlr(String fileName, String grammarFileName, String grammarStr, String... extraOptions) { protected boolean antlr(String fileName, String grammarFileName, String grammarStr, boolean defaultListener, String... extraOptions) {
boolean allIsWell = true; boolean allIsWell = true;
System.out.println("dir "+tmpdir); System.out.println("dir "+tmpdir);
mkdir(tmpdir); mkdir(tmpdir);
@ -401,9 +402,12 @@ public abstract class BaseTest {
ErrorQueue equeue = new ErrorQueue(); ErrorQueue equeue = new ErrorQueue();
Tool antlr = newTool(optionsA); Tool antlr = newTool(optionsA);
antlr.addListener(equeue); antlr.addListener(equeue);
if (defaultListener) {
antlr.addListener(new DefaultToolListener(antlr));
}
antlr.processGrammarsOnCommandLine(); antlr.processGrammarsOnCommandLine();
if ( equeue.errors.size()>0 ) { allIsWell = equeue.errors.isEmpty();
allIsWell = false; if ( !defaultListener && !equeue.errors.isEmpty() ) {
System.err.println("antlr reports errors from "+options); System.err.println("antlr reports errors from "+options);
for (int i = 0; i < equeue.errors.size(); i++) { for (int i = 0; i < equeue.errors.size(); i++) {
ANTLRMessage msg = equeue.errors.get(i); ANTLRMessage msg = equeue.errors.get(i);
@ -413,6 +417,13 @@ public abstract class BaseTest {
System.out.println(grammarStr); System.out.println(grammarStr);
System.out.println("###"); System.out.println("###");
} }
if ( !defaultListener && !equeue.warnings.isEmpty() ) {
System.err.println("antlr reports warnings from "+options);
for (int i = 0; i < equeue.warnings.size(); i++) {
ANTLRMessage msg = equeue.warnings.get(i);
System.err.println(msg);
}
}
} }
catch (Exception e) { catch (Exception e) {
allIsWell = false; allIsWell = false;
@ -478,10 +489,24 @@ public abstract class BaseTest {
@Nullable String parserName, @Nullable String parserName,
String lexerName, String lexerName,
String... extraOptions) String... extraOptions)
{
return rawGenerateAndBuildRecognizer(grammarFileName, grammarStr, parserName, lexerName, false, extraOptions);
}
/** Return true if all is well */
protected boolean rawGenerateAndBuildRecognizer(String grammarFileName,
String grammarStr,
@Nullable String parserName,
String lexerName,
boolean defaultListener,
String... extraOptions)
{ {
boolean allIsWell = boolean allIsWell =
antlr(grammarFileName, grammarFileName, grammarStr, extraOptions); antlr(grammarFileName, grammarFileName, grammarStr, defaultListener, extraOptions);
boolean ok; if (!allIsWell) {
return false;
}
List<String> files = new ArrayList<String>(); List<String> files = new ArrayList<String>();
if ( lexerName!=null ) { if ( lexerName!=null ) {
files.add(lexerName+".java"); files.add(lexerName+".java");
@ -499,8 +524,7 @@ public abstract class BaseTest {
files.add(grammarFileName.substring(0, grammarFileName.lastIndexOf('.'))+"BaseParseListener.java"); files.add(grammarFileName.substring(0, grammarFileName.lastIndexOf('.'))+"BaseParseListener.java");
} }
} }
ok = compile(files.toArray(new String[files.size()])); allIsWell = compile(files.toArray(new String[files.size()]));
if ( !ok ) { allIsWell = false; }
return allIsWell; return allIsWell;
} }

View File

@ -653,7 +653,7 @@ public class TestCompositeGrammars extends BaseTest {
"s : a ;\n" + "s : a ;\n" +
"B : 'b' ;" + // defines B from inherited token space "B : 'b' ;" + // defines B from inherited token space
"WS : (' '|'\\n') {skip();} ;\n" ; "WS : (' '|'\\n') {skip();} ;\n" ;
boolean ok = antlr("M.g4", "M.g4", master); boolean ok = antlr("M.g4", "M.g4", master, false);
boolean expecting = true; // should be ok boolean expecting = true; // should be ok
assertEquals(expecting, ok); assertEquals(expecting, ok);
} }

View File

@ -433,7 +433,7 @@ public class TestPerformance extends BaseTest {
extraOptions.add("-atn"); extraOptions.add("-atn");
} }
String[] extraOptionsArray = extraOptions.toArray(new String[extraOptions.size()]); String[] extraOptionsArray = extraOptions.toArray(new String[extraOptions.size()]);
boolean success = rawGenerateAndBuildRecognizer(grammarFileName, body, "JavaParser", "JavaLexer", extraOptionsArray); boolean success = rawGenerateAndBuildRecognizer(grammarFileName, body, "JavaParser", "JavaLexer", true, extraOptionsArray);
assertTrue(success); assertTrue(success);
} }