Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 85 lines (63 sloc) 2.198 kb
38ab3ad [t/spec] Some S04 .pending and .handled tests
kyle authored
1 use v6;
2 use Test;
3 plan *;
4
5 # XXX I'm not very confident in my reading of S04, so give a suspicious eye
6 # to these tests before using them.
7
8 # L<S04/Exceptions/"internal list of unhandled exceptions">
9
10 {
11 try { die 'OMG' }
12 ok $! ~~ Exception, '$! has an exception';
13 #?rakudo 2 skip '$!.pending'
14 ok $!.pending ~~ List, '$!.pending returns a List';
15 is $!.pending, (), '$! there are no exceptions pending';
16
17 undefine $!;
18 ok ! $!, '$! has been cleared';
19 }
20
21 sub fail_it { fail $^a }
22
832f178 [t/spec] fix more smartlinks; down to 33 broken links
moritz authored
23 # L<S04/Exceptions/"test a Failure for .defined or .Bool">
38ab3ad [t/spec] Some S04 .pending and .handled tests
kyle authored
24
25 {
26 my @fails = ( fail_it(1), fail_it(2), fail_it(3), fail_it(4) );
27
28 ok all(@fails) ~~ Failure, '@fails is full of fail';
29 ok $! !~~ Exception, 'fails do not enter $!';
30 #?rakudo 11 skip '$!.pending'
31 is +($!.pending.grep( ! *.handled )), 4,
32 '$!.pending has three unhandled exceptions';
33
34 ok ! @fails[0].handled, 'fail 0 is not handled';
a238d44 [t/spec] rename true to so
lwall authored
35 ok @fails[0].not, 'fail 0 is not true';
38ab3ad [t/spec] Some S04 .pending and .handled tests
kyle authored
36 ok @fails[0].handled, 'fail 0 is now handled';
37
38 ok ! @fails[1].handled, 'fail 1 is not handled';
39 ok ! @fails[1].defined, 'fail 1 is not defined';
40 ok @fails[1].handled, 'fail 1 is now handled';
41
42 # L<S04/Exceptions/"The .handled method is rw">
43
44 ok ! @fails[2].handled, 'fail 2 is not handled';
45 lives_ok { @fails[2].handled = 1 }, 'assign to .handled';
46 ok @fails[2].handled, 'fail 2 is now handled';
47
48 is +($!.pending.grep( ! *.handled )), 1,
49 '$!.pending has one unhandled exception';
50
51 undefine $!;
52 ok ! $!, '$! has been cleared';
53 }
54
55 # L<S04/Exceptions/"At scope exit,">
56
57 {
58 my $fails_thrown = 0;
59 {
60 my @throwable = ( fail_it(1), fail_it(2), fail_it(3) );
61 @throwable[1].handled = 1;
62 CATCH {
63 default {
64 $fails_thrown += +($!.pending);
65 }
66 }
67 }
68 is $fails_thrown, 2, 'unhandled Failures in $! at block exit are thrown';
69
70 undefine $!;
71 ok ! $!, '$! has been cleared';
72 }
73
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
74 # L<S04/Exceptions/"a Mu method, not a Failure method">
38ab3ad [t/spec] Some S04 .pending and .handled tests
kyle authored
75
76 {
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
77 my $win = Mu.new;
38ab3ad [t/spec] Some S04 .pending and .handled tests
kyle authored
78 #?rakudo skip '$object.handled'
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
79 ok $win.handled, '.handled method is true for all Mus';
38ab3ad [t/spec] Some S04 .pending and .handled tests
kyle authored
80 }
81
82 done_testing;
83
84 # vim: ft=perl6
Something went wrong with that request. Please try again.