On Fri, Jan 05, 2007 at 04:14:27AM +0100, gabriele renzi wrote:
> supposing that I want to keep code and tests in one single file, is
> there a common idiom to do that?
Nice idea!
> At the moment I'm going with something like:
>
> if $?FILE == $*PROGRAM_NAME {
> use Test;
> plan 1;
> ok foo();
> }
>
> but this seem unnecessarily verbose.
It's also wrong; == is numeric equality, you need ~~ or eq. Also, note
that 'use Test' means Test is loaded even when you aren't testing. We
don't currently have a way of calling import in pugs though. Then again
the cost of loading Test isn't too bad because it's precompiled.
> Is there some standard idiom or function in Test.pm that allows this
> kind of thing with a nicer interface?
>
> I think it should be possible and nice to use a macro (possibly a
> standard subroutine, I'm not sure) like
>
> testing {
> ok foo;
> }
>
> would it make sense or I'm just crazy?
I like the approach.
--
Gaal Yahas <[EMAIL PROTECTED]>
http://gaal.livejournal.com/