doctest for java

Janto Dreijer janto_d at hotmail.com
Sat Jun 29 15:18:37 EDT 2002


"Janto Dreijer" <janto_d at hotmail.com> wrote in message
news:afisev$1f6e$1 at news.adamastor.ac.za...
> Tim Peters <tim.one at comcast.net> wrote in message
> news:<mailman.1025281419.16432.python-list at python.org>...
> > [Janto Dreijer]
> > > Are there any attempts to port the "doctest" module to Java? (All
> > > I can find using google is some testing class for the JavaDoc program
> > > calling itself "DocTest".)
> > >
> > > At a glance it looks like a worthwhile effort...extracting Jython
> > > "examples"
> > > from /**...*/ comments also seems simple to implement.
> >
> > Last I heard, Python's std doctest.py worked fine under Jython.  If
> anything
> > else simple is needed, you're elected <wink>.
>
> I in no way meant your code is trivial. Although I'm starting to think you
> did that "import __future__" trick with the sole reason to confuse :-)
>
> I'm actually thinking of running doctests on *.java files and not on *.py
> files, so the current doctest.py wouldn't be 100% usable.
>
> class Obj {
>     /**
>         "Three" is the number it should print. And the number of the
> printing should be "three":
>         This is a usage example written in Jython...maybe.
>
>         >>> Obj.f()
>         3
>
>     */
>     public static void f() {
>         System.out.println(3);
>     }
> }
>
> That's it. It can't be helped. I'm spending my weekend on this :-)
>

sigh. ok, I give up.

I wanted to use Tim's implementation since most of the code would be the
same, so:
After extracting all the comments from a Java source file with a simple
regular expression I simply instantiated the Tester class included with
doctest.py and passed the comments to the runstring() method. That means
about 10 lines from Jython.

The problem, however, is that this can only work for public and friendly
Java functions. There's no way I can access a class' properties that are by
definition private. So that rules out solutions involving outside classes.
Unfortunately Java objects also have limited introspection in that it can't
grab a listing of it's own methods (ala __dict__) and thus also rules out a
hack that involves initiating doctests from within the object itself.

A possible way is to go deeper into the JVM by using either a custom made VM
(...yeah, right) or using the Java debugger tool (jdb.exe) which I assume
has access to private attributes. This seems the way to go if someone has
enough enthusiasm.

Bottom line: I'm not _that_ a big a fan of Java. I might work on it a bit
more during the next few weeks, but don't get your hopes up.

ps. I'll mail my code if anyone asks, but I'm not associating myself with
this half-working code by posting it on Usenet. :-)






More information about the Python-list mailing list