Ronald Schmidt wrote:
> Moritz Lenz wrote:
>> Oops, forgot to attach patch. Now it's really there.
>>
>>   
> Your implementations of eval_lives_ok and eval_dies_ok seem 
> inconsistent.  eval_lives_ok uses try and eval_dies_ok does not.  The 
> two implementations may catch different types of exceptions.  I am 
> proposing the patch below:

Good catch. Actually I already encountered I problem with these two
subs, but haven't got around to fix it so far.

Are there any exceptions that are not caught by eval?
Currently rakudo seems to catch every run time exception, but parse
failures still throw an exception. I'm pretty sure that's wrong, because
it's contrary to Perl 6's exception philosophy.

So eval() needs more work, but in the mean time your patch works just
fine (and it will continue to work when eval is fixed), so I vote +1 here.

Cheers,
Moritz

> $ svn diff Test.pm
> Index: Test.pm
> ===================================================================
> --- Test.pm     (revision 28117)
> +++ Test.pm     (working copy)
> @@ -122,17 +122,20 @@
>      lives_ok($closure, '');
>  }
> 
> +sub eval_exception ($code) {
> +    my $eval_exception;
> +    try { eval ( $code ); $eval_exception = $! }
> +    $eval_exception // $!;
> +}
>  multi sub eval_dies_ok($code, $reason) {
> -    eval ( $code );
> -    proclaim((defined $!), $reason);
> +    proclaim((defined eval_exception($code)), $reason);
>  }
>  multi sub eval_dies_ok($code) {
>      eval_dies_ok($code, '');
>  }
> 
>  multi sub eval_lives_ok($code, $reason) {
> -    try { eval ($code) }
> -    proclaim((not defined $!), $reason);
> +    proclaim((not defined eval_exception($code)), $reason);
>  }
>  multi sub eval_lives_ok($code) {
>      eval_lives_ok($code, '');
> 
> 


-- 
Moritz Lenz
http://moritz.faui2k3.org/ |  http://perl-6.de/

Reply via email to