Unit Tests for Generators

Hi,

is there a way to write unit tests for generators?

For example I would like to do something like this:
  1. Define a test model
  2. Use it as input for the generator test case
  3. Make assertions on the generated output

Cheers
Yann
0
5 comments
Hi!

Now you can:
- create test model
  • from ANT task execute code generation upon this model & assert generated code is equals to currently existing files for this model

By using it you can:
  • generate code for the test model and check it once
  • put everything into VCS repository
  • on build server checkout test and run it (steps described above)

By doing that you can ensure same code (checked on first step) will be generated for this model by using current state of the generator.
0
Avatar
Permanently deleted user
Thanks for your reply.

I suppose you mean I should create a build script solution for my language (using MPS 2.0) and execute the steps mentioned by you (generate from model and execute tests) there, right?

What I have done is:
  • Create a build script solution
  • Add jetbrains.mps.build.generictasks as a used language to the model. Without this, I can't use any ant calls. (You definitely should add this hint to the wiki documentation!!!)
  • Write some build script (jetbrains.mps.buildlanguage.project):
project TEST [ default = default      ]         
basedir = <no basedir>           
   
  <property declarations>        
   
  <property imports>             
   
  <task calls>    
   
  <import projects>              
   
  target default  
    <property declarations>      
    echo  [ <attributes> ]       
      "Message for testing if anything works..."
      <nested tasks>             
    junit  [ <attributes> ]      
      <nested tasks>


So now I have two Problems:
  1. I can't find any target for generating projects MPS modules (corresponding to the ant target <mps.generate>).
  2. When I try to execute the script above, I get the following error message
BUILD FAILED
/Users/yamass/MPSProjects/Test/solutions/Test.build/source_gen/Test/build/TestBuildScript.xml:4: Problem: failed to create task or type junit
Cause: the class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask was not found.
        This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
        -/Applications/MPS 2.app/lib/ant/lib
        -/Users/yamass/.ant/lib
        -a directory added on the command line with the -lib argument

Do not panic, this is a common problem.
The commonest cause is a missing JAR.

This is not a bug; it is a configuration problem

However, the corresponding jar file (ant-junit.jar) is in the "/Applications/MPS 2.app/lib/ant/lib" directory...

How to proceed?
0
Hello, Yann,

Thare are no counterparts of mps.generate task in MPS currently, so you have to use text build files to use it.

As for the second problem, this is a probably bug, since, as you mentioned, the required jar exists. The bugreport is here MPS-13524 Could you include the command line ant was started from MPS console?

--
Regards,
Julia
0
I could not reproduce the error you are getting, but I found some problems in running ant which would be fixed in MPS RC3. Maybe you problem would be gone with them. So if in RC3 it still be present, please reopen the issue MPS-13524 or white a comment here. Some additional information also would be helpful.
0
Avatar
Permanently deleted user
Add jetbrains.mps.build.generictasks as a used language to the model. Without this, I can't use any ant calls. (You definitely should add this hint to the wiki documentation!!!)


I can confirm, that you really should document how to set up the model for a build script. It's a waste of time if every one has to figure it out by itself just to follow the user guide's example.
0

Please sign in to leave a comment.