LanX has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I'm trying to get an overview about the possibilities to integrate the tests for a sub/method right away after defining them, much like POD embeds documentation right away in the code.

Till now I found Test::Pod::Snippets and Pod::Tests which use POD-parsers.

I slightly remember a discussion about a more functional than POD approach to do it.

UPDATE: Or code filter approach, like Smart::Comments

Anything more to be considered?

Any idea is appreciated...

Cheers Rolf

Replies are listed 'Best First'.
Re: Embedding tests?
by Corion (Patriarch) on Nov 20, 2009 at 16:54 UTC

    There is Test::Inline, which I used for some time in its 1.0 incarnation, but found it and its Makefile.PL hackery too fragile. The 2.0 version by Adam Kennedy seems more robust, but I haven't really ported my tests over.

      Thx!

      There is Test::Inline, which I used for some time in its 1.0 incarnation,

      Do you mean Pod::Tests with "1.0 incarnation"?

      Cheers Rolf

        At least its documentation seems to concur with that interpretation :)

Re: Embedding tests?
by Bloodnok (Vicar) on Nov 20, 2009 at 20:47 UTC
    You could always adopt the Java approach and use Test::Unit ... which I was forced [sic] to do in my recently pre-emptorarily terminated client engagement - writing perl to look and (if at all possible) behave like java - a singularly bizarre experience (witness some of my posts of the time:-).

    Having said that, methinx the use of Test::Unit is not without benefit - in as much as it facilitates a much cleaner approach to unit testing ... by separating the white box (Test::Unit) and black box (Test::More et al) testing.

    A user level that continues to overstate my experience :-))
Re: Embedding tests?
by JavaFan (Canon) on Nov 20, 2009 at 16:31 UTC
    If it's for a module that normally would not run stand alone, you could do:
    sub foo { ... } unless (caller) { ... your tests go here ... }
    I think it's a common Python technique, but I may be mistaken.