[antlr-interest] Re: Bug in C# codegen: initializeASTFactory
slightlynew <gackle at shaw.ca>
gackle at shaw.ca
Tue Jan 14 12:53:01 PST 2003
> <scratches-head>Now, just exactly how does one write a simple NUnit
> test for this report?. Ideas pls people...</scratches-head>
>
> Micheal
With a code-generation program, you can either write tests to verify
that the expected code is generated, or tests to verify that the
generated code behaves as expected. The second kind of test is
fairly easy. In the case of this particular bug, your test would
initialize a new AST factory, then make sure that factory behaved as
expected. The key point is that at first, the test would fail
(because of the bug), and then pass when the bug is fixed.
Of course, you'd have to write a test grammar to go with this test.
My approach in a similar situation has been to write a small test
grammar that is just enough to demonstrate whatever feature I'm
trying to test, then write the tests to verify that feature. I keep
the small test grammars as orthogonal as possible, trying to test one
thing at a time. Then there is a higher-level set of acceptance
tests that involve complex grammars, to make sure that all the
individual features work together.
As a matter of fact it was tests of this sort that caught the bug.
My existing tests stopped working when I tried to replace the default
AST factory with a different one. By looking at which tests failed,
it was easy to see that the new factory didn't know about its own
node types. The whole process, from breaking the tests to tracking
down the bug to figuring out a workaround, took about 15 minutes.
Ciao,
Daniel
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list