vendredi 27 mars 2015

unit testing a bison generated parser

I have eclipse with cdt and a project which contains files generated by flex and bison, the project runs perfectly(perfectly means no compiler or linker errors, test for wrong output is the goal of this question)but I couldn't run it as a unit test, here the things I tried:


CUTE


As the answer on this question says, I couldn't find a way to test a project that already exists, so this didn't work.


CppUnit is old as the answer said(didn't try it though but I don't want an old thing).


CDT unit testing


As this question states, unit testing is now a part of cdt, I installed it and installed googletest and followed the instructions but when I run it, it says : Unknown error during parsing Google Test module output : Unexpected test module output.


This is another question getting the same message but it doesn't have an answer(except in comments which is the same answer I followed when setting up cdt unit testing).


and after I ran this test, I got compiler errors in yacc.cpp and lex.yy.cc which I didn't get when running the project in normal.


Goal


I'm a university student doing a project with four collegues, we're building a compiler to a language specified by the professors, the language is basically python with these changes:


1-'x' is a char literal and "something" is a string literal, no multiline string, escape characters are still allowed.


2-adding access modifier keywords(public,private,protected).


3-declaring variables by def keyword and putting the access modifier(or not putting it in which it'll default to private). like this for example:


protected def x=10;


4-pure OOP(no functions outside classes).


5-no local classes or methods(in python you can declare a function inside of a function,here you can't).


6-removed the dictionary support(with the del keyword), only lists.


7-removed assert,exec,lamda and yield.


8-overloading methods produces a compiler error(instead of taking the last definition).


9-a method can only override a parent method when they have the same signature, otherwise a compiler error should be produced.


10-added static and final keywords(they mean the same as java), adding static menas static methods cannot have the self parameter(Compiler error). static variables need the static keyword after the def keyword.


11-we end statements by ';' not newline.


12-we don't use indentation to mark the body of anything, instead a block begin with ':' and end with "end" keyword.


other than these, it's identical to python2(not 3).


I have seen a question on "bison flex unit testing", this is it : Unit test of flex bison scanner parse, how to drive the test case


but the poster of the question is using C, we're restricted to use C++ in both scanner and parser, so the question can't really help me.


PS


because running the project without unit testing worked well, I thought the error isn't with my yacc.y or lex.l, that's why I didn't post them, if they are needed I'll edit my question


Aucun commentaire:

Enregistrer un commentaire