Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[t/spec] Some S04 .pending and .handled tests
git-svn-id: http://svn.pugscode.org/pugs@28699 c213334d-75ef-0310-aa23-eaa082d1ae64
- Loading branch information
kyle
committed
Oct 9, 2009
1 parent
d01cac7
commit 38ab3ad
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use v6; | ||
use Test; | ||
plan *; | ||
|
||
# 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 .true"> | ||
|
||
{ | ||
my @fails = ( fail_it(1), fail_it(2), fail_it(3), fail_it(4) ); | ||
|
||
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].true, '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,"> | ||
|
||
{ | ||
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/"an Object method, not a Failure method"> | ||
|
||
{ | ||
my $win = Object.new; | ||
#?rakudo skip '$object.handled' | ||
ok $win.handled, '.handled method is true for all Objects'; | ||
} | ||
|
||
done_testing; | ||
|
||
# vim: ft=perl6 |