Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[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...
commit 38ab3add4ff6f67700df3f042a61a7a4a7744e1f 1 parent d01cac7
kyle authored
Showing with 84 additions and 0 deletions.
  1. +84 −0 S04-exceptions/pending.t
View
84 S04-exceptions/pending.t
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.