davidchambers/doctest — pull request #6 by danse (2013-02-02 15:41:44+00:00)
Title: Doctest doctest with doctests!

Hi, I propose you a new feature for doctest, even if the code is not so elegant, maybe you will find your way to tidy it.

Basical feature: ignore block comments. This, together with the use of __doctest in rewritten file, allows doctest to test itself!

This required to have a stateful rewriter. It would also be possible to do without it, but I think the code would become messy.

I needed to test the rewriter and it is an internal object in the module, so I tested it with doctests! Two notes about that: first, I was not successful in having a global variable mantained in the subsequent doctests, so I saved it outside of comments (`r = {}` in normal code). Second, I don't like the class I made. I would have implemented the rewriter as an iterator if this was python, in order to be able to test it line by line, but I'm not sure about the best way to implement it in java/coffee. The ugliness of its doctests shows the ugliness of the class itself, this is why I like doctests, but in this case I'm not able to find a better solution in short time, so I'm asking for a pull so that at least the new functionalities will be available.

Last note: having a stateful rewriter to ignore blocks is the first step in order to parse them, to have also doctests in blocks. This would increase strongly the readability of doctests I think. Probably the rewriter will deserve in that case its own file, and the problem will raise about dependencies if you want to keep doctests in the code.

And I hope you will want! I hope you will take advantage (and experiment) from your inventions in your own project! (Indeed, I think doctests affect strongly the code structure, otherwise I had not take the hassle to care about them on javascript where they do not exists apart from you project).

Cheers