Pull error reporting outside of try/finally to ensure errors are not hidden

This commit is contained in:
Sam Harwell 2012-03-16 08:07:46 -05:00
parent ea7037dd2d
commit ea434982fb
1 changed files with 21 additions and 19 deletions

View File

@ -358,7 +358,7 @@ public abstract class BaseTest {
System.out.println("dir "+tmpdir); System.out.println("dir "+tmpdir);
mkdir(tmpdir); mkdir(tmpdir);
writeFile(tmpdir, fileName, grammarStr); writeFile(tmpdir, fileName, grammarStr);
try { ErrorQueue equeue = new ErrorQueue();
final List<String> options = new ArrayList<String>(); final List<String> options = new ArrayList<String>();
Collections.addAll(options, extraOptions); Collections.addAll(options, extraOptions);
options.add("-o"); options.add("-o");
@ -366,12 +366,19 @@ public abstract class BaseTest {
options.add("-lib"); options.add("-lib");
options.add(tmpdir); options.add(tmpdir);
options.add(new File(tmpdir,grammarFileName).toString()); options.add(new File(tmpdir,grammarFileName).toString());
try {
final String[] optionsA = new String[options.size()]; final String[] optionsA = new String[options.size()];
options.toArray(optionsA); options.toArray(optionsA);
ErrorQueue equeue = new ErrorQueue();
Tool antlr = newTool(optionsA); Tool antlr = newTool(optionsA);
antlr.addListener(equeue); antlr.addListener(equeue);
antlr.processGrammarsOnCommandLine(); antlr.processGrammarsOnCommandLine();
}
catch (Exception e) {
allIsWell = false;
System.err.println("problems building grammar: "+e);
e.printStackTrace(System.err);
}
if ( equeue.errors.size()>0 ) { if ( equeue.errors.size()>0 ) {
allIsWell = false; allIsWell = false;
System.err.println("antlr reports errors from "+options); System.err.println("antlr reports errors from "+options);
@ -383,12 +390,7 @@ public abstract class BaseTest {
System.out.println(grammarStr); System.out.println(grammarStr);
System.out.println("###"); System.out.println("###");
} }
}
catch (Exception e) {
allIsWell = false;
System.err.println("problems building grammar: "+e);
e.printStackTrace(System.err);
}
return allIsWell; return allIsWell;
} }