Version 5

    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

     

    1. Edit the testuite file

    2. Create or change the actual list of tests (see gUnit grammar references)

    3. 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" 

       

    4. The above statement generated a JUnit file. Now, open the generated file and localize the following line:

      DRLParser parser = new DRLParser(tokens);

       

    5. Just after the above line add the following line:

      parser.setTreeAdaptor(new DroolsTreeAdaptor());

       

    6. Now localize the following block:

                     if ( stderrVacuum.toString().length()>0 ) {
                          this.stderr = stderrVacuum.toString();
                          return this.stderr;
                     }
      

       

    7. Just after the above block add the following block:

                     if ( parser.hasErrors() ) {
                          this.stderr = parser.getErrors().toString();
                          return this.stderr;
                     }
      

       

    8. Save the JUnit file

     

    Finish! Now you are ready to run the tests.