Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 182 lines (158 sloc) 3.575 kb
72237dd4 » moritz
2008-09-09 [t] one more closure_traits move, a bit more TODO (also added to TASKS)
1 use v6;
2
3 use Test;
4 # Test of PRE and POST traits
5 #
4e5f6047 » moritz
2009-11-06 [t/spec] fix some smartlinks
6 # L<S04/Phasers/"assert precondition at every block ">
832f178c » moritz
2010-03-18 [t/spec] fix more smartlinks; down to 33 broken links
7 # L<S06/Subroutine traits/PRE/POST>
72237dd4 » moritz
2008-09-09 [t] one more closure_traits move, a bit more TODO (also added to TASKS)
8
2023f068 » moritz
2012-03-20 test blockless PRE and POST
9 plan 22;
72237dd4 » moritz
2008-09-09 [t] one more closure_traits move, a bit more TODO (also added to TASKS)
10
7d8245f1 » sorear
2011-08-04 [S04-phasers] Fudge pre-post, enter-leave, and keep-undo for niecza
11 sub foo(Int $i) {
72237dd4 » moritz
2008-09-09 [t] one more closure_traits move, a bit more TODO (also added to TASKS)
12 PRE {
13 $i < 5
14 }
15 return 1;
16 }
17
e7ca07b1 » moritz
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
18 sub bar(Int $i) {
72237dd4 » moritz
2008-09-09 [t] one more closure_traits move, a bit more TODO (also added to TASKS)
19 return 1;
20 POST {
21 $i < 5;
22 }
23 }
24
e7ca07b1 » moritz
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
25 lives_ok { foo(2) }, 'sub with PRE compiles and runs';
26 lives_ok { bar(3) }, 'sub with POST compiles and runs';
72237dd4 » moritz
2008-09-09 [t] one more closure_traits move, a bit more TODO (also added to TASKS)
27
77ec25fe » coke
2012-02-18 pugs fudge
28 #?pugs todo
e7ca07b1 » moritz
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
29 dies_ok { foo(10) }, 'Violated PRE throws (catchable) exception';
30 dies_ok { bar(10) }, 'Violated POST throws (catchable) exception';
72237dd4 » moritz
2008-09-09 [t] one more closure_traits move, a bit more TODO (also added to TASKS)
31
32 # multiple PREs und POSTs
33
7d8245f1 » sorear
2011-08-04 [S04-phasers] Fudge pre-post, enter-leave, and keep-undo for niecza
34 sub baz (Int $i) {
72237dd4 » moritz
2008-09-09 [t] one more closure_traits move, a bit more TODO (also added to TASKS)
35 PRE {
36 $i > 0
37 }
38 PRE {
39 $i < 23
40 }
41 return 1;
42 }
e7ca07b1 » moritz
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
43 lives_ok { baz(2) }, 'sub with two PREs compiles and runs';
72237dd4 » moritz
2008-09-09 [t] one more closure_traits move, a bit more TODO (also added to TASKS)
44
77ec25fe » coke
2012-02-18 pugs fudge
45 #?pugs todo
e7ca07b1 » moritz
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
46 dies_ok { baz(-1)}, 'sub with two PREs fails when first is violated';
77ec25fe » coke
2012-02-18 pugs fudge
47 #?pugs todo
dca6a92c » moritz
2008-10-06 [t/spec] fixed syntax error in pre-post.t, caught by STD.pm++
48 dies_ok { baz(42)}, 'sub with two PREs fails when second is violated';
72237dd4 » moritz
2008-09-09 [t] one more closure_traits move, a bit more TODO (also added to TASKS)
49
50
7d8245f1 » sorear
2011-08-04 [S04-phasers] Fudge pre-post, enter-leave, and keep-undo for niecza
51 sub qox (Int $i) {
72237dd4 » moritz
2008-09-09 [t] one more closure_traits move, a bit more TODO (also added to TASKS)
52 return 1;
53 POST {
54 $i > 0
55 }
56 POST {
57 $i < 42
58 }
59 }
60
e7ca07b1 » moritz
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
61 lives_ok({ qox(23) }, "sub with two POSTs compiles and runs");
77ec25fe » coke
2012-02-18 pugs fudge
62 #?pugs todo
e7ca07b1 » moritz
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
63 dies_ok( { qox(-1) }, "sub with two POSTs fails if first POST is violated");
64 dies_ok( { qox(123)}, "sub with two POSTs fails if second POST is violated");
72237dd4 » moritz
2008-09-09 [t] one more closure_traits move, a bit more TODO (also added to TASKS)
65
66
e7ca07b1 » moritz
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
67 class Another {
7d8245f1 » sorear
2011-08-04 [S04-phasers] Fudge pre-post, enter-leave, and keep-undo for niecza
68 method test(Int $x) {
e7ca07b1 » moritz
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
69 return 3 * $x;
70 POST {
71 $_ > 4
72 }
73 }
72237dd4 » moritz
2008-09-09 [t] one more closure_traits move, a bit more TODO (also added to TASKS)
74 }
75
e7ca07b1 » moritz
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
76 my $pt = Another.new;
77ec25fe » coke
2012-02-18 pugs fudge
77 #?pugs todo
e7ca07b1 » moritz
2008-10-05 [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
78 lives_ok { $pt.test(2) }, 'POST receives return value as $_ (succeess)';
79 dies_ok { $pt.test(1) }, 'POST receives return value as $_ (failure)';
7f29bc53 » kyle
2009-08-08 [t/spec] Add vim: lines everywhere.
80
59ffe4c2 » benmorrow
2009-08-16 [t/spec] Tests for r28005 (closure traits and exceptions).
81 {
82 my $str;
83 {
84 PRE { $str ~= '('; 1 }
85 POST { $str ~= ')'; 1 }
86 $str ~= 'x';
87 }
77ec25fe » coke
2012-02-18 pugs fudge
88 #?pugs todo
59ffe4c2 » benmorrow
2009-08-16 [t/spec] Tests for r28005 (closure traits and exceptions).
89 is $str, '(x)', 'PRE and POST run on ordinary blocks';
90 }
91
92 {
93 my $str;
94 {
95 POST { $str ~= ')'; 1 }
96 LEAVE { $str ~= ']' }
97 ENTER { $str ~= '[' }
98 PRE { $str ~= '('; 1 }
99 $str ~= 'x';
100 }
77ec25fe » coke
2012-02-18 pugs fudge
101 #?pugs todo
59ffe4c2 » benmorrow
2009-08-16 [t/spec] Tests for r28005 (closure traits and exceptions).
102 is $str, '([x])', 'PRE/POST run outside ENTER/LEAVE';
103 }
104
105 {
106 my $str;
107 try {
108 {
109 PRE { $str ~= '('; 0 }
110 PRE { $str ~= '*'; 1 }
111 ENTER { $str ~= '[' }
112 $str ~= 'x';
113 LEAVE { $str ~= ']' }
114 POST { $str ~= ')'; 1 }
115 }
116 }
77ec25fe » coke
2012-02-18 pugs fudge
117 #?pugs todo
59ffe4c2 » benmorrow
2009-08-16 [t/spec] Tests for r28005 (closure traits and exceptions).
118 is $str, '(', 'failing PRE runs nothing else';
119 }
120
121 {
122 my $str;
123 try {
124 {
eb002d65 » jnthn
2012-03-19 Correct and unfudge a test; POST runs LIFO.
125 POST { $str ~= 'z'; 1 }
59ffe4c2 » benmorrow
2009-08-16 [t/spec] Tests for r28005 (closure traits and exceptions).
126 POST { $str ~= 'x'; 0 }
127 LEAVE { $str ~= 'y' }
128 }
129 }
77ec25fe » coke
2012-02-18 pugs fudge
130 #?pugs todo
59ffe4c2 » benmorrow
2009-08-16 [t/spec] Tests for r28005 (closure traits and exceptions).
131 is $str, 'yx', 'failing POST runs LEAVE but not more POSTs';
132 }
133
7d8245f1 » sorear
2011-08-04 [S04-phasers] Fudge pre-post, enter-leave, and keep-undo for niecza
134 #?niecza skip 'unspecced'
59ffe4c2 » benmorrow
2009-08-16 [t/spec] Tests for r28005 (closure traits and exceptions).
135 {
136 my $str;
137 try {
138 POST { $str ~= $! // '<undef>'; 1 }
139 die 'foo';
140 }
77ec25fe » coke
2012-02-18 pugs fudge
141 #?pugs todo
8f9a1198 » lwall
2009-11-25 [t/] unify compartmentalized undef and Object concepts into Mu
142 ok $str ~~ /foo/, 'POST runs on exception, with correct $!';
59ffe4c2 » benmorrow
2009-08-16 [t/spec] Tests for r28005 (closure traits and exceptions).
143 }
144
7d8245f1 » sorear
2011-08-04 [S04-phasers] Fudge pre-post, enter-leave, and keep-undo for niecza
145 #?niecza skip 'unspecced'
5e1cfcfa » moritz
2012-07-27 rakudo unfudges
146 #?rakudo 2 todo 'POST and exceptions'
59ffe4c2 » benmorrow
2009-08-16 [t/spec] Tests for r28005 (closure traits and exceptions).
147 {
148 my $str;
149 try {
fd2754ce » lwall
2009-08-17 [t/spec/S04] change ?: to ??!!
150 POST { $str ~= (defined $! ?? 'yes' !! 'no'); 1 }
59ffe4c2 » benmorrow
2009-08-16 [t/spec] Tests for r28005 (closure traits and exceptions).
151 try { die 'foo' }
fd2754ce » lwall
2009-08-17 [t/spec/S04] change ?: to ??!!
152 $str ~= (defined $! ?? 'aye' !! 'nay');
59ffe4c2 » benmorrow
2009-08-16 [t/spec] Tests for r28005 (closure traits and exceptions).
153 }
77ec25fe » coke
2012-02-18 pugs fudge
154 #?pugs todo
8f9a1198 » lwall
2009-11-25 [t/] unify compartmentalized undef and Object concepts into Mu
155 is $str, 'ayeno', 'POST has undefined $! on no exception';
59ffe4c2 » benmorrow
2009-08-16 [t/spec] Tests for r28005 (closure traits and exceptions).
156 }
157
7d8245f1 » sorear
2011-08-04 [S04-phasers] Fudge pre-post, enter-leave, and keep-undo for niecza
158 #?niecza skip 'unspecced'
59ffe4c2 » benmorrow
2009-08-16 [t/spec] Tests for r28005 (closure traits and exceptions).
159 {
160 try {
161 POST { 0 }
162 die 'foo';
163 }
77ec25fe » coke
2012-02-18 pugs fudge
164 #?pugs todo
8f9a1198 » lwall
2009-11-25 [t/] unify compartmentalized undef and Object concepts into Mu
165 ok $! ~~ /foo/, 'failing POST on exception doesn\'t replace $!';
59ffe4c2 » benmorrow
2009-08-16 [t/spec] Tests for r28005 (closure traits and exceptions).
166 # XXX
167 # is $!.pending.[-1], 'a POST exception', 'does push onto $!.pending';
168 }
169
2023f068 » moritz
2012-03-20 test blockless PRE and POST
170 {
171 my sub blockless($x) {
172 PRE $x >= 0;
173 POST $_ == 4;
174 return $x;
175 }
abc657ac » coke
2012-04-02 pugs fudge
176 #?pugs todo
2023f068 » moritz
2012-03-20 test blockless PRE and POST
177 lives_ok { blockless(4) }, 'blockless PRE/POST (+)';
178 dies_ok { blockless -4 }, 'blockless PRE/POST (-, 1)';
179 dies_ok { blockless 14 }, 'blockless PRE/POST (-, 2)';
180 }
181
7f29bc53 » kyle
2009-08-08 [t/spec] Add vim: lines everywhere.
182 # vim: ft=perl6
Something went wrong with that request. Please try again.