You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by mr...@apache.org on 2009/01/21 02:31:54 UTC
svn commit: r736190 - in /ode/sandbox/simpel/src:
main/antlr/org/apache/ode/simpel/antlr/ main/java/org/apache/ode/simpel/
main/java/org/apache/ode/simpel/omodel/
main/java/org/apache/ode/simpel/util/ test/java/org/apache/ode/simpel/
test/resources/
Author: mriou
Date: Tue Jan 20 17:31:53 2009
New Revision: 736190
URL: http://svn.apache.org/viewvc?rev=736190&view=rev
Log:
Small framework to test compilation errors together with a couple of test cases. A few resulting bug fixes.
Added:
ode/sandbox/simpel/src/test/resources/compile-tests-ko.simpel
Modified:
ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/SimPELCompiler.java
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/DefaultErrorListener.java
ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/ErrorMessageBuilder.java
ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java
Modified: ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g?rev=736190&r1=736189&r2=736190&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g (original)
+++ ode/sandbox/simpel/src/main/antlr/org/apache/ode/simpel/antlr/SimPELWalker.g Tue Jan 20 17:31:53 2009
@@ -20,18 +20,16 @@
import org.apache.ode.simpel.omodel.OBuilder;
import org.apache.ode.simpel.omodel.SimPELExpr;
import org.apache.ode.bpel.rtrep.v2.*;
+import org.apache.log4j.Logger;
}
@members {
// Grammar level members
-
- private ErrorListener el;
-
- public void setErrorListener(ErrorListener el) {
- this.el = el;
- }
+
+ private static final Logger __log = Logger.getLogger(SimPELWalker.class);
+
public void displayRecognitionError(String[] tokenNames, RecognitionException e) {
- el.reportRecognitionError(e.line, e.charPositionInLine, getErrorMessage(e, tokenNames), e);
+ __log.debug("Tree grammar error " + e.line + ":" + e.charPositionInLine + " " + getErrorMessage(e, tokenNames));
}
public String getErrorMessage(RecognitionException e, String[] tokenNames) {
Modified: ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/SimPELCompiler.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/SimPELCompiler.java?rev=736190&r1=736189&r2=736190&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/SimPELCompiler.java (original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/SimPELCompiler.java Tue Jan 20 17:31:53 2009
@@ -116,7 +116,6 @@
SimPELWalker walker = new SimPELWalker(nodes);
OBuilder obuilder = new OBuilder(desc, errListener);
walker.setBuilder(obuilder);
- walker.setErrorListener(errListener);
HashMap<Integer, Integer> tokenMapping = buildTokenMap(E4XParser.tokenNames, E4XLexer.class, SimPELWalker.class);
rewriteTokens(tokenMapping, E4XParser.tokenNames, t, walker, false);
Modified: ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java?rev=736190&r1=736189&r2=736190&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java (original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java Tue Jan 20 17:31:53 2009
@@ -72,19 +72,23 @@
StructuredActivity result = (StructuredActivity) buildMethod.invoke(this, buildParams);
if (result != null) parent.run((OActivity) result.getOActivity());
return result;
- } catch (BuilderException e) {
- // Report an error and try to recover from it to get further down in the tree
- errors.reportRecognitionError(t != null ? t.getLine() : -1, t != null ? t.getCharPositionInLine() : -1, e.getMessage(), e);
- return new SimpleActivity<OEmpty>(new OEmpty(_oprocess, (OActivity) parent.getOActivity()));
} catch (Exception e) {
- // Unrecoverable error, trying to report as much as possible
- errors.reportRecognitionError(t != null ? t.getLine() : -1, t != null ? t.getCharPositionInLine() : -1,
- "Unrecoverable error, couldn't build activity of type " + oclass +
- (t != null ? (" near " + t.getText()) : ""), e);
-
- CompilationException ce = new CompilationException(e);
- ce.errors = errors.getErrors();
- throw ce;
+ if (e.getCause() instanceof BuilderException) {
+ // Report an error and try to recover from it to get further down in the tree
+ errors.reportRecognitionError(t != null ? t.getLine() : -1, t != null ? t.getCharPositionInLine() : -1,
+ e.getCause().getMessage(), (Exception) e.getCause());
+ return new SimpleActivity<OInvoke>(new OInvoke(_oprocess, (OActivity) parent.getOActivity()));
+ } else {
+ __log.debug(e);
+ // Unrecoverable error, trying to report as much as possible
+ errors.reportRecognitionError(t != null ? t.getLine() : -1, t != null ? t.getCharPositionInLine() : -1,
+ "Unrecoverable error, couldn't build activity of type " + oclass +
+ (t != null ? (" near " + t.getText()) : ""), e);
+
+ CompilationException ce = new CompilationException(e);
+ ce.errors = errors.getErrors();
+ throw ce;
+ }
}
}
Modified: ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/DefaultErrorListener.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/DefaultErrorListener.java?rev=736190&r1=736189&r2=736190&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/DefaultErrorListener.java (original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/DefaultErrorListener.java Tue Jan 20 17:31:53 2009
@@ -1,17 +1,16 @@
package org.apache.ode.simpel.util;
-import org.antlr.runtime.RecognitionException;
import org.apache.ode.simpel.ErrorListener;
import org.apache.ode.simpel.CompilationException;
+import org.apache.log4j.Logger;
import java.util.LinkedList;
import java.util.List;
-/**
- * @author Matthieu Riou <mr...@apache.org>
- */
public class DefaultErrorListener implements ErrorListener {
+ private static final Logger __log = Logger.getLogger(DefaultErrorListener.class);
+
private LinkedList<CompilationException.Error> _errors = new LinkedList<CompilationException.Error>();
public List<CompilationException.Error> getErrors() {
@@ -20,7 +19,7 @@
public void reportRecognitionError(int line, int column, String message, Exception e) {
_errors.add(new CompilationException.Error(line, column, message, e));
- System.err.println(line + ":" + column + " " + message);
+ __log.debug(line + ":" + column + " " + message);
}
}
Modified: ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/ErrorMessageBuilder.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/ErrorMessageBuilder.java?rev=736190&r1=736189&r2=736190&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/ErrorMessageBuilder.java (original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/ErrorMessageBuilder.java Tue Jan 20 17:31:53 2009
@@ -14,7 +14,8 @@
public static String msg(RecognitionException e, String[] tokenNames, String paraphrase) {
String msg = null;
if (e instanceof NoViableAltException) {
- msg = "Syntax error, unexpected token " + tokenNames[e.token.getType()];
+ if (tokenNames == null) msg = "Invalid character";
+ else msg = "Syntax error, unexpected token " + tokenNames[e.token.getType()];
} else if (e instanceof MismatchedTokenException) {
MismatchedTokenException mte = (MismatchedTokenException) e;
msg = "Syntax error, unexpected token " + tokenNames[e.token.getType()] + ", expecting " + tokenNames[mte.expecting];
Modified: ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java?rev=736190&r1=736189&r2=736190&view=diff
==============================================================================
--- ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java (original)
+++ ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java Tue Jan 20 17:31:53 2009
@@ -4,10 +4,12 @@
import org.antlr.runtime.RecognitionException;
import org.apache.ode.bpel.rtrep.v2.OProcess;
import org.apache.ode.Descriptor;
+import org.apache.ode.simpel.util.DefaultErrorListener;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.List;
+import java.util.concurrent.Callable;
/**
* @author Matthieu Riou <mr...@apache.org>
@@ -22,23 +24,29 @@
desc.setRestful(false);
}
+ public void testAllOk() throws Exception {
+ compileAllInFile("compile-tests-ok.simpel", true);
+ }
+
+ public void testAllKo() throws Exception {
+ compileAllInFile("compile-tests-ko.simpel", false);
+ }
+
/**
* If this was Ruby, I'd just dynamically create methods for each tested process
* and we'd have one clean method for each test case. But this is Java so there's
* only one reported test for all the processes.
* @throws Exception
*/
- public void testAllOk() throws Exception {
+ private void compileAllInFile(String file, boolean forSuccess) throws Exception {
BufferedReader reader = new BufferedReader(new FileReader(
- getClass().getClassLoader().getResource("compile-tests-ok.simpel").getFile()));
+ getClass().getClassLoader().getResource(file).getFile()));
int testCount = 0;
String line;
StringBuffer processBody = new StringBuffer();
- TestErrorListener l = new TestErrorListener();
SimPELCompiler comp = new SimPELCompiler();
- comp.setErrorListener(l);
- StringBuffer allErrors = new StringBuffer();
+ boolean failed = false;
String testCaseName = "";
// Priming the pump
@@ -48,14 +56,15 @@
while ((line = reader.readLine()) != null) {
if (line.trim().startsWith("#=")) {
- // Found next test case divider, process is complete so we can parse
- OProcess oprocess = comp.compileProcess(processBody.toString(), desc);
- if (l.messages.toString().length() > 0) {
- // Shit happened
- allErrors.append("Test case ").append(testCaseName).append(" failed!!\n");
- allErrors.append(l.messages.toString()).append("\n");
- } else {
- System.out.println(oprocess);
+ // Found next test case divider, process is complete so we can compile
+ try {
+ comp.compileProcess(processBody.toString(), desc);
+ System.out.println("Test case " + testCaseName + " compiled properly.");
+ if (!forSuccess) failed = true;
+ } catch (CompilationException e) {
+ System.out.println("There were errors while compiling test case " + testCaseName);
+ System.out.println(e);
+ if (forSuccess) failed = true;
}
testCount++;
@@ -63,7 +72,7 @@
testCaseName = reader.readLine().trim().substring(2);
reader.readLine();reader.readLine();
processBody = new StringBuffer();
- l.messages = new StringBuffer();
+ comp.setErrorListener(new DefaultErrorListener());
} else {
processBody.append(line).append("\n");
}
@@ -72,23 +81,17 @@
// And the last one
try {
comp.compileProcess(processBody.toString(), desc);
- } catch (Exception e) {
- System.out.println("Error compiling " + testCaseName);
- e.printStackTrace();
+ } catch (CompilationException e) {
+ System.err.println("There were errors while compiling test case " + testCaseName);
+ System.err.println(e);
+ if (forSuccess) failed = true;
}
testCount++;
- if (l.messages.toString().length() > 0) {
- // Shit happened
- allErrors.append("Test case ").append(testCaseName).append(" failed!!");
- allErrors.append(l.messages.toString()).append("\n");
- }
- if (allErrors.toString().length() > 0) {
- System.out.println("Some test processes failed to compile:\n");
- System.out.println(allErrors.toString());
+ if (failed) {
fail("There were failures.");
} else {
- System.out.println("\nCompiled " + testCount + " processes successfully.");
+ System.out.println("\nTested " + testCount + " processes successfully.");
}
}
Added: ode/sandbox/simpel/src/test/resources/compile-tests-ko.simpel
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/test/resources/compile-tests-ko.simpel?rev=736190&view=auto
==============================================================================
--- ode/sandbox/simpel/src/test/resources/compile-tests-ko.simpel (added)
+++ ode/sandbox/simpel/src/test/resources/compile-tests-ko.simpel Tue Jan 20 17:31:53 2009
@@ -0,0 +1,25 @@
+# NOTE: The "==" line serves as a separator between test cases.
+# Each of the following test process should raise an error for the tests to pass.
+
+#=============================================================
+# Empty process
+#
+
+process EmptyProcess {
+}
+
+#=============================================================
+# Wrong request method
+#
+
+process WrongRequestMeth {
+ request("/foo", "foo");
+}
+
+#=============================================================
+# Lexer error
+#
+
+process LexerError {
+ reque@st("/foo", "get");
+}
\ No newline at end of file