Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Interesting testing idea ...

by dragonchild (Archbishop)
on Jan 21, 2009 at 14:20 UTC ( #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 (Pope) 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
Node Status?
node history
Node Type: perlmeditation [id://737829]
Approved by Corion
Front-paged by Arunbear
[marto]: "Eugenie Scott, executive director of the National Center for Science Education, dubbed this approach the Gish gallop, describing it as "where the creationist is allowed to run on for 45 minutes or an hour, spewing forth torrents of error that the
[marto]: evolutionist hasn't a prayer of refuting in the format of a debate." She also criticized Gish for failing to answer objections raised by his opponents"
[erix]: one would hope evolutionists haven't any prayers anyway
[marto]: obviously someone could be religious, but not creationist
[erix]: "Nothing in Intelligent Design makes sense except in the light of Creationism" <-- I made that one up myself (free after Dobzhansky )
[erix]: yes. Deplorable marto, deplorable.
[marto]: the situation seemed similar to this one, majority of the contributrions are nonsense, doesn't address any questions ...
[marto]: meh, I've been called worse :P

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2017-07-28 15:45 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (431 votes). Check out past polls.