Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BNF grammar test case generation [closed]

Does anyone have any experience with a tool that generates test strings from a BNF grammar that could then be fed into a unit test?

like image 364
Rob Walker Avatar asked Sep 09 '08 15:09

Rob Walker


2 Answers

I don't have an answer to the tool question, but I will say it is fairly easy in any text processing language (perl/python/etc) to randomly generate sentences from a BNF grammar, and slightly more verbose in a bigger language (Java/C/etc), but it shouldn't be too hard to roll your own.

The problem with this, of course, is that it can only generate strings in the grammar, and unless your grammar is very simple, the test space is infinitely large.

like image 117
hazzen Avatar answered Oct 11 '22 19:10

hazzen


I've done exactly as hazzen commented (using an embedded DSL in a scripting language). It was a mildly interesting exercise, but except for the most basic tests of e.g. parsing, it wasn't terribly useful. Most of my most interesting tests have to do with more sophisticated relationships than one can easily express in BNF (or any other context-free grammar).

like image 44
joel.neely Avatar answered Oct 11 '22 19:10

joel.neely