[antlr-interest] ANTLR and Unit Testing

sohail at taggedtype.net sohail at taggedtype.net
Sat Apr 1 12:32:58 PST 2006


> Do many ANTLR users here
> use unit testing?  If so, what is your general strategy on approaching
> writing your test cases?  And finally, if any does have some specific C
> ++ examples that I could look at, I would greatly appreciate it.

Yes! Lots of unit testing. Although people's opinions on unit testing
differ quite a bit. Personally, I break my tests down into two types:
parser and code generation tests.

The parser tests have atleast one test for every language feature. For
example if your language allows statements of the form:

int i = j = 1;

I'd make sure that your parser can parse that. I would not advise using a
parse tree and making sure that the parse tree never changes because you
will always change the parse tree (ime).

Then you'd generally take the same test and translate it to C++, compile
and run the results:

int i = j = 1;
assert(j==1);
assert(i==j);

Of course, this test itself assumes that you have asserts and equality
comparisons already working. Thats a tough one. I generally manually made
sure the fundamental components work before I wrote tests like the above.
If you can at a very minimum verify that asserts and equality comparisons
work, you can test loops and stuff in your source language.

I look forward to hearing others responses.

HTH!

Sohail


More information about the antlr-interest mailing list