Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 86 lines (64 sloc) 2.252 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
use v6;
use Test;

# XXX I'm not very confident in my reading of S04, so give a suspicious eye
# to these tests before using them.

# L<S04/Exceptions/"internal list of unhandled exceptions">

{
    try { die 'OMG' }
    ok $! ~~ Exception, '$! has an exception';
    #?rakudo 2 skip '$!.pending'
    ok $!.pending ~~ List, '$!.pending returns a List';
    is $!.pending, (), '$! there are no exceptions pending';

    undefine $!;
    ok ! $!, '$! has been cleared';
}

sub fail_it { fail $^a }

# L<S04/Exceptions/"test a Failure for .defined or .Bool">

{
    my @fails = ( fail_it(1), fail_it(2), fail_it(3), fail_it(4) );

    #?rakudo todo 'not full of fail?'
    ok all(@fails) ~~ Failure, '@fails is full of fail';
    ok $! !~~ Exception, 'fails do not enter $!';
    #?rakudo 11 skip '$!.pending'
    is +($!.pending.grep( ! *.handled )), 4,
       '$!.pending has three unhandled exceptions';

    ok ! @fails[0].handled, 'fail 0 is not handled';
    ok @fails[0].not, 'fail 0 is not true';
    ok @fails[0].handled, 'fail 0 is now handled';

    ok ! @fails[1].handled, 'fail 1 is not handled';
    ok ! @fails[1].defined, 'fail 1 is not defined';
    ok @fails[1].handled, 'fail 1 is now handled';

# L<S04/Exceptions/"The .handled method is rw">

    ok ! @fails[2].handled, 'fail 2 is not handled';
    lives_ok { @fails[2].handled = 1 }, 'assign to .handled';
    ok @fails[2].handled, 'fail 2 is now handled';

    is +($!.pending.grep( ! *.handled )), 1,
       '$!.pending has one unhandled exception';

    undefine $!;
    ok ! $!, '$! has been cleared';
}

# L<S04/Exceptions/"At scope exit,">

#?rakudo skip '$object.handled'
{
    my $fails_thrown = 0;
    {
        my @throwable = ( fail_it(1), fail_it(2), fail_it(3) );
        @throwable[1].handled = 1;
        CATCH {
            default {
                $fails_thrown += +($!.pending);
            }
        }
    }
    is $fails_thrown, 2, 'unhandled Failures in $! at block exit are thrown';

    undefine $!;
    ok ! $!, '$! has been cleared';
}

# L<S04/Exceptions/"a Mu method, not a Failure method">

{
    my $win = Mu.new;
    #?rakudo skip '$object.handled'
    ok $win.handled, '.handled method is true for all Mus';
}

done;

# vim: ft=perl6
Something went wrong with that request. Please try again.