On Mon, 24 Sep 2001, Michael G Schwern wrote:

> On Mon, Sep 24, 2001 at 06:42:55PM -0500, Dave Rolsky wrote:
> > +sub eval_ok (&$) {
> > +    my ($code, $name) = @_;
> > +
> > +    eval { $code->() };
> > +    if ($@) {
> > +   ok( 0, "$name - $@" );
> > +    } else {
> > +   ok( 1, $name );
> > +    }
> > +}
>
> The unfortunate problem is this has adverse effects on any code in the
> block that uses caller().  I don't want tests to introduce
> side-effects.  Unfortunately, Sub::Uplevel doesn't work on anything
> before 5.6.0.
>
> However, you're not the first person that's wanted this.
>
> Maybe we can get rid of this problem with documentation.  I tend to
> use this idiom.
>
>     eval { ...code... };
>     is( $@, '' );

Yeah, except that doesn't print out $@ in case of failure.  If I'm
checking that no exception occurs I want to know what the exception is
when it happens.

I don't know that the caller() issue is a big deal.  Document it and then
for code where that's an issue (a small fraction at best, I'd think)
people will know not to use it.  Just cause it doesn't work for all
possible uses doesn't make it useless.


-dave

/*==================
www.urth.org
We await the New Sun
==================*/

Reply via email to