Skip to content

Commit

Permalink
Corrections and re-fudging of S04-exception-handlers/catch.t.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Oct 24, 2011
1 parent 2881bb5 commit e420571
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions S04-exception-handlers/catch.t
Expand Up @@ -14,12 +14,9 @@ Tests C<CATCH> blocks.

# L<S04/"Exception handlers"/If you define a CATCH block within the try, it replaces the default CATCH>

#?rakudo 2 todo 'empty CATCH block'
dies_ok { die 'blah'; CATCH {} }, 'Empty CATCH rethrows exception';
dies_ok { try {die 'blah'; CATCH {}} }, 'CATCH in try overrides default exception handling';



# L<S04/"Exception handlers"/any block can function as a try block if you put a CATCH block within it>

lives_ok { die 'blah'; CATCH {default {}} }, 'Closure with CATCH {default {}} ignores exceptions';
Expand Down Expand Up @@ -69,7 +66,6 @@ lives_ok { do {die 'blah'; CATCH {default {}}}; }, 'do block with CATCH {default

ok(!$not_died, "did not live after death");
#?pugs 1 todo
#?rakudo todo 'smart matching against exception'
ok($caught, "caught exception of class Naughty");
};

Expand All @@ -80,7 +76,7 @@ lives_ok { do {die 'blah'; CATCH {default {}}}; }, 'do block with CATCH {default

my ($other, $naughty);
{
die Naughty::Specific("error");
die Naughty::Specific.new();

CATCH {
when Naughty::Other {
Expand All @@ -103,6 +99,7 @@ lives_ok { do {die 'blah'; CATCH {default {}}}; }, 'do block with CATCH {default
class Dandy is Exception {};

my ($naughty, $lived);
try {
{
die Dandy.new();

Expand All @@ -113,26 +110,26 @@ lives_ok { do {die 'blah'; CATCH {default {}}}; }, 'do block with CATCH {default
}
};
$lived = 1;

#?rakudo todo 'smart matching in CATCH'
}

ok(!$lived, "did not live past uncaught throw");
ok(!$naughty, "did not get caught by wrong handler");
ok(WHAT($!).gist, '$! is an object');
#?pugs skip 'bug'
#?rakudo todo 'Exception types'
is(WHAT($!).gist, Dandy.gist, ".. of the right class");
};

#?rakudo skip 'loops'
{
my $s = '';
die 3;
CATCH {
when 1 {$s ~= 'a';}
when 2 {$s ~= 'b';}
when 3 {$s ~= 'c';}
when 4 {$s ~= 'd';}
default {$s ~= 'z';}
{
die 3;
CATCH {
when 1 {$s ~= 'a';}
when 2 {$s ~= 'b';}
when 3 {$s ~= 'c';}
when 4 {$s ~= 'd';}
default {$s ~= 'z';}
}
}

is $s, 'c', 'Caught number';
Expand Down Expand Up @@ -165,7 +162,6 @@ lives_ok { do {die 'blah'; CATCH {default {}}}; }, 'do block with CATCH {default
};
}

#?rakudo 2 todo 'CATCH block catching its own exceptions (RT #64262)'
is $catches, 1, "CATCH doesn't catch exceptions thrown in its own lexical scope";

$catches = 0;
Expand Down

0 comments on commit e420571

Please sign in to comment.