Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Interesting testing idea ...

by dragonchild (Archbishop)
on Jan 21, 2009 at 14:20 UTC ( [id://737829]=perlmeditation: print w/replies, xml ) Need Help??

The idea comes from It's a neat idea, probably best suited for functional programming where one-liners are the norm and not the exception. BUT ... I think we could do it in Perl. Something like:
use Test::With; sub foo : WithTests( 2 ) { my ($x, $y) = @_; return $x + y; } with_test { cmp_ok( foo( 4, 3 ), '==', 7 ); cmp_ok( foo( -6, 2 ), '==', -4 ); };
I'm not even sure if that syntax will work, but it looks appealing. :-)

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re: Interesting testing idea ...
by Corion (Patriarch) on Jan 21, 2009 at 14:23 UTC

    This is close-yet-different to the idea of Test::Inline, which lets you write your tests in POD directly after the code. I think I prefer Test::Inline's way of allowing a more elaborate test setup, for example setting up a database etc.. The advantage of your idea is that no other tools are required to extract the tests from the POD, but this means that everybody wanting to use your module needs Test::With installed, while the inline tests can be extracted before creating the distribution file.

Re: Interesting testing idea ...
by autarch (Hermit) on Jan 21, 2009 at 21:52 UTC

    I think to do this you'd either need a source filter (gah!) or Devel::Declare.

    As for whether it's a good idea. I don't know. I'm not a big fan of subroutine attributes, and your attribute seems redundant anyway. I think I'd prefer something more like this:

    sub foo { ... } is tested(2) { ... }

    That looks fairly 6-ish.

Re: Interesting testing idea ...
by artist (Parson) on Jan 31, 2009 at 19:13 UTC
    I like the idea. It's like test with the code itself. It eliminates the need of writing 'separate' tests. It also serve purpose of the intended code.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://737829]
Approved by Corion
Front-paged by Arunbear
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-16 20:40 GMT
Find Nodes?
    Voting Booth?

    No recent polls found