How to develop and maintain grammar tests
Drools now uses gUnit for grammar test and here is a mini-howto setup the gUnit tests.
How to change an existent test
Edit the testuite file
Create or change the actual list of tests (see gUnit grammar references)
Save the testuite file and execute the following statement on command line (check your environment variables):
java -cp "$HOME/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar:$HOME/.m2/repository/org/antlr/stringtemplate/3.0/stringtemplate-3.0.jar:$HOME/.m2/repository/org/antlr/antlr/3.0/antlr-3.0.1.jar:$HOME/.m2/repository/org/antlr/gunit/1.0.1/gunit-1.0.1.jar:$DROOLS_PROJECTS/drools-compiler/target/classes" org.antlr.gunit.Interp -o "filename.testsuite"
The above statement generated a JUnit file. Now, open the generated file and localize the following line:
DRLParser parser = new DRLParser(tokens);
Just after the above line add the following line:
parser.setTreeAdaptor(new DroolsTreeAdaptor());
Now localize the following block:
if ( stderrVacuum.toString().length()>0 ) { this.stderr = stderrVacuum.toString(); return this.stderr; }
Just after the above block add the following block:
if ( parser.hasErrors() ) { this.stderr = parser.getErrors().toString(); return this.stderr; }
Save the JUnit file
Finish! Now you are ready to run the tests.
Comments