Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 353 lines (272 sloc) 9.738 kB
58135b3 [t/spec] changed 'use v6-alpha;' to 'use v6;'
moritz authored
1 use v6;
08d48bd [t] Test suite refactoring.
cosimo authored
2 use Test;
ae01205 [t/spec] Tests inspired by IRC: http://irclog.perlgeek.de/perl6/2009-…
kyle authored
3 BEGIN { @*INC.push('t/spec/packages/') };
4 use Test::Util;
08d48bd [t] Test suite refactoring.
cosimo authored
5
f660aa6 [t/spec] Possibly converted all remaining pod markers to pod6
cosimo authored
6 =begin pod
08d48bd [t] Test suite refactoring.
cosimo authored
7
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
8 'Mu' and 'undefine' tests
08d48bd [t] Test suite refactoring.
cosimo authored
9
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
10 This test file contains two sections: a port of the perl5 'undef.t' tests, and
08d48bd [t] Test suite refactoring.
cosimo authored
11 perl6-specific tests.
12
f660aa6 [t/spec] Possibly converted all remaining pod markers to pod6
cosimo authored
13 =end pod
08d48bd [t] Test suite refactoring.
cosimo authored
14
15 # Note: See thread "Undef issues" by Adrian Taylor on p6l
16 # L<http://groups.google.com/groups?threadm=20050601002444.GB32060@wall.org>
17 # On Tue, May 24, 2005 at 10:53:59PM +1000, Stuart Cook wrote:
18 # : I'm not sure whether this behaviour is supposed to be changing.
19 #
20 # It is. I think we decided to make the value undef, and the function
21 # undefine(). (But these days most values of undef really ought to
22 # be constructed and returned (or thrown) using fail().)
23 #
24 # Larry
25
ac7ea9d @moritz correct or remove tests that assume you can compare type objects with…
moritz authored
26 plan 86;
08d48bd [t] Test suite refactoring.
cosimo authored
27
28 our $GLOBAL;
f660aa6 [t/spec] Possibly converted all remaining pod markers to pod6
cosimo authored
29
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
30 # L<S32::Basics/Mu/=item defined>
f660aa6 [t/spec] Possibly converted all remaining pod markers to pod6
cosimo authored
31
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
32 ok(!defined(Mu), "Mu is not defined");
08d48bd [t] Test suite refactoring.
cosimo authored
33
34 {
35 my $a;
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
36 ok(!defined($a), "uninitialized lexicals are undefined");
08d48bd [t] Test suite refactoring.
cosimo authored
37
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
38 ok(!defined($GLOBAL), "uninitialized package vars are undefined");
08d48bd [t] Test suite refactoring.
cosimo authored
39
ae01205 [t/spec] Tests inspired by IRC: http://irclog.perlgeek.de/perl6/2009-…
kyle authored
40 $a += 1;
08d48bd [t] Test suite refactoring.
cosimo authored
41 ok(defined($a), "initialized var is defined");
ae01205 [t/spec] Tests inspired by IRC: http://irclog.perlgeek.de/perl6/2009-…
kyle authored
42 is_run( 'my $a; $a += 1', { err => '', out => '', status => 0 },
43 'increment of undefined variable does not warn' );
08d48bd [t] Test suite refactoring.
cosimo authored
44
45 undefine $a;
46 ok(!defined($a), "undefine($a) does");
47
48 $a = "hi";
49 ok(defined($a), "string");
50
51 my $b;
52 $a = $b;
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
53 ok(!defined($a), "assigning another undefined lexical");
08d48bd [t] Test suite refactoring.
cosimo authored
54
55 $a = $GLOBAL;
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
56 ok(!defined($a), "assigning another undefined global");
08d48bd [t] Test suite refactoring.
cosimo authored
57 }
f660aa6 [t/spec] Possibly converted all remaining pod markers to pod6
cosimo authored
58
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
59 # L<S32::Basics/Mu/"=item undefine">
08d48bd [t] Test suite refactoring.
cosimo authored
60 {
61 my @ary = "arg1";
62 my $a = @ary.pop;
63 ok(defined($a), "pop from array");
64 $a = @ary.pop;
65 ok(!defined($a), "pop from empty array");
66
67 @ary = "arg1";
68 $a = @ary.shift;
69 ok(defined($a), "shift from array");
70 $a = @ary.shift;
71 ok(!defined($a), "shift from empty array");
72
73 my %hash = ( bar => 'baz', quux => 'quuz' );
74 ok(defined(%hash<bar>), "hash subscript");
75 ok(!defined(%hash<bargho>), "non-existent hash subscript");
76
77 undefine %hash<bar>;
78 ok(!defined(%hash<bar>), "undefine hash subscript");
79
80 %hash<bar> = "baz";
81 %hash.delete("bar");
82 ok(!defined(%hash<bar>), "delete hash subscript");
83
84 ok(defined(@ary), "aggregate array defined");
85 ok(defined(%hash), "aggregate hash defined");
86
87 undefine(@ary);
a20c69c [t/spec/*.t] :todo whackage
lwall authored
88 #?pugs todo 'bug'
173bb69 [t/spec] correct undef.t, and fudge for rakudo
moritz authored
89 #?rakudo todo 'definedness of array'
a20c69c [t/spec/*.t] :todo whackage
lwall authored
90 ok(!defined(@ary), "undefine array");
08d48bd [t] Test suite refactoring.
cosimo authored
91
173bb69 [t/spec] correct undef.t, and fudge for rakudo
moritz authored
92 #?rakudo emit #
08d48bd [t] Test suite refactoring.
cosimo authored
93 undefine(%hash);
a20c69c [t/spec/*.t] :todo whackage
lwall authored
94 #?pugs todo 'bug'
173bb69 [t/spec] correct undef.t, and fudge for rakudo
moritz authored
95 #?rakudo todo 'definedness of hash'
a20c69c [t/spec/*.t] :todo whackage
lwall authored
96 ok(!defined(%hash), "undefine hash");
08d48bd [t] Test suite refactoring.
cosimo authored
97
98 @ary = (1);
99 ok(defined(@ary), "define array again");
100 %hash = (1,1);
101 ok(defined(%hash), "define hash again");
102 }
103
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
104 #?rakudo skip 'access to &your_sub'
08d48bd [t] Test suite refactoring.
cosimo authored
105 {
106 sub a_sub { "møøse" }
107
108 ok(defined(&a_sub), "defined sub");
a20c69c [t/spec/*.t] :todo whackage
lwall authored
109 #?pugs todo 'parsefail'
110 ok(eval('defined(%«$?PACKAGE\::»<&a_sub>)'), "defined sub (symbol table)");
08d48bd [t] Test suite refactoring.
cosimo authored
111
a20c69c [t/spec/*.t] :todo whackage
lwall authored
112 #?pugs todo 'feature'
113 ok(eval('!defined(&a_subwoofer)'), "undefined sub");
114 #?pugs todo 'feature'
115 ok(eval('!defined(%«$?PACKAGE\::»<&a_subwoofer>)'), "undefined sub (symbol table)");
ae01205 [t/spec] Tests inspired by IRC: http://irclog.perlgeek.de/perl6/2009-…
kyle authored
116
117 dies_ok { undefine &a_sub }, 'die trying to undefine a sub';
118 ok defined &a_sub, 'sub is still defined after attempt to undefine';
08d48bd [t] Test suite refactoring.
cosimo authored
119 }
120
121 # TODO: find a read-only value to try and assign to, since we don't
122 # have rules right now to play around with (the p5 version used $1)
123 #eval { "constant" = "something else"; };
124 #is($!, "Modification of a read", "readonly write yields exception");
125
126 # skipped tests for tied things
127
128 # skipped test for attempt to undef a bareword -- no barewords here.
129
130 # TODO: p5 "bugid 3096
131 # undefing a hash may free objects with destructors that then try to
132 # modify the hash. To them, the hash should appear empty."
133
134
135 # Test LHS assignment to undef:
297e783 [t] and [t/spec]
moritz authored
136 # XXX shouldn't that be * instead of undef?
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
137 # yes, this chunk should move to a different file --Larry
08d48bd [t] Test suite refactoring.
cosimo authored
138
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
139 {
140 my $interesting;
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
141 (*, *, $interesting) = (1,2,3);
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
142 is($interesting, 3, "Undef on LHS of list assignment");
08d48bd [t] Test suite refactoring.
cosimo authored
143
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
144 (*, $interesting, *) = (1,2,3);
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
145 is($interesting, 2, "Undef on LHS of list assignment");
08d48bd [t] Test suite refactoring.
cosimo authored
146
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
147 ($interesting, *, *) = (1,2,3);
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
148 is($interesting, 1, "Undef on LHS of list assignment");
08d48bd [t] Test suite refactoring.
cosimo authored
149
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
150 sub two_elements() { (1,2) };
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
151 (*,$interesting) = two_elements();
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
152 is($interesting, 2, "Undef on LHS of function assignment");
08d48bd [t] Test suite refactoring.
cosimo authored
153
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
154 ($interesting, *) = two_elements();
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
155 is($interesting, 1, "Undef on LHS of function assignment");
156 }
08d48bd [t] Test suite refactoring.
cosimo authored
157
f660aa6 [t/spec] Possibly converted all remaining pod markers to pod6
cosimo authored
158 =begin pod
08d48bd [t] Test suite refactoring.
cosimo authored
159
160 Perl6-specific tests
161
f660aa6 [t/spec] Possibly converted all remaining pod markers to pod6
cosimo authored
162 =end pod
08d48bd [t] Test suite refactoring.
cosimo authored
163
173bb69 [t/spec] correct undef.t, and fudge for rakudo
moritz authored
164 #?rakudo skip 'fun with undefine'
08d48bd [t] Test suite refactoring.
cosimo authored
165 {
166 # aggregate references
167
168 my @ary = (<a b c d e>);
169 my $ary_r = @ary; # ref
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
170 isa_ok($ary_r, Array);
08d48bd [t] Test suite refactoring.
cosimo authored
171 ok(defined($ary_r), "array reference");
172
173 undefine @ary;
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
174 ok(!+$ary_r, "undefine array referent");
08d48bd [t] Test suite refactoring.
cosimo authored
175
176 is(+$ary_r, 0, "dangling array reference");
177
178 my %hash = (1, 2, 3, 4);
179 my $hash_r = %hash;
180 isa_ok($hash_r, "Hash");
181 ok(defined($hash_r), "hash reference");
182 undefine %hash;
183 ok(defined($hash_r), "undefine hash referent:");
184 is(+$hash_r.keys, 0, "dangling hash reference");
185 }
186
187 {
188 my Array $an_ary;
189 ok(!defined($an_ary), "my Array");
7805860 @coke nom fudge
coke authored
190 #?rakudo todo 'nom regression'
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
191 ok((try { !defined($an_ary[0]) }), "my Array subscript - Mu");
08d48bd [t] Test suite refactoring.
cosimo authored
192 try { $an_ary.push("blergh") };
7805860 @coke nom fudge
coke authored
193 #?rakudo todo 'nom regression'
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
194 ok((try { defined($an_ary.pop) }), "push");
7805860 @coke nom fudge
coke authored
195 #?rakudo todo 'nom regression'
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
196 ok((try { !defined($an_ary.pop) }), "comes to shove");
02df239 Unfudge some passing autoviv tests.
pmichaud authored
197 }
08d48bd [t] Test suite refactoring.
cosimo authored
198
02df239 Unfudge some passing autoviv tests.
pmichaud authored
199 #?rakudo skip 'Autovivify hashes'
200 {
08d48bd [t] Test suite refactoring.
cosimo authored
201 my Hash $a_hash;
202
203 ok(!defined($a_hash), "my Hash");
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
204 ok((try { !defined($a_hash<blergh>) }), "my Hash subscript - Mu");
205 ok((try { !defined($a_hash<blergh>) }), "my Hash subscript - Mu, no autovivification happened");
08d48bd [t] Test suite refactoring.
cosimo authored
206
207 $a_hash<blergh> = 1;
208 ok(defined($a_hash.delete('blergh')), "delete");
209 ok(!defined($a_hash.delete("blergh")), " - once only");
02df239 Unfudge some passing autoviv tests.
pmichaud authored
210 }
211
08d48bd [t] Test suite refactoring.
cosimo authored
212
02df239 Unfudge some passing autoviv tests.
pmichaud authored
213 {
08d48bd [t] Test suite refactoring.
cosimo authored
214 class Dog {};
215 my Dog $spot;
216
217 ok(!defined($spot), "Unelaborated mutt");
218 $spot .= new;
219 ok(defined $spot, " - now real");
220 }
221
222 # rules
223 # TODO. refer to S05
224 # L<S05/Match objects/"they will all be undefined" closure
225 # "let keyword">
226
ea2ee24 [STD] various bugs
lwall authored
227 # - unmatched alternative should bind to undef
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
228 #?rakudo skip 'null PMC access in type()'
ece272c [t/spec] fudged undef.t for rakudo
moritz authored
229 #?DOES 10
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
230 {
4ad9719 [undef.t] there is no my() function...declarators require space
lwall authored
231 my ($num, $alpha);
8dc7d4b [t/spec] mark various tests that intentionally declare things that ar…
lwall authored
232 my ($rx1, $rx2); #OK not used
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
233 eval '
234 $rx1 = rx
235 / [ (\d+) { let $<num> := $0 }
236 | (<alpha>+) { let $<alpha> := $1 }
237 ]
238 /;
239 $rx2 = rx
240 / [ $<num> := (\d+)
241 | $<alpha>:= (<alpha>+)
242 ]
243 /;
244 ';
245 for (<rx1 rx2>) {
246 # I want symbolic lookups because I need the rx names for test results.
247
248 eval '"1" ~~ %MY::{$_}';
249 #?pugs todo 'unimpl'
250 ok(defined($num), '{$_}: successful hypothetical');
251 ok(!defined($alpha), '{$_}: failed hypothetical');
252
253 eval '"A" ~~ %MY::{$_}';
254 ok(!defined($num), '{$_}: failed hypothetical (2nd go)');
255 #?pugs todo 'unimpl'
256 ok(defined($alpha), '{$_}: successful hypothetical (2nd go)');
257 }
08d48bd [t] Test suite refactoring.
cosimo authored
258
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
259 # - binding to hash keys only would leave values undefined
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
260 eval '"a=b\nc=d\n" ~~ / $<matches> := [ (\w) = \N+ ]* /';
261 #?pugs todo 'unimpl'
262 ok(eval('$<matches> ~~ all(<a b>)'), "match keys exist");
08d48bd [t] Test suite refactoring.
cosimo authored
263
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
264 #ok(!defined($<matches><a>) && !defined($<matches><b>), "match values don't");
265 #?pugs todo 'unimpl'
266 ok(0 , "match values don't");
267 }
3604100 more buglets
lwall authored
268
ece272c [t/spec] fudged undef.t for rakudo
moritz authored
269 #?DOES 1
08d48bd [t] Test suite refactoring.
cosimo authored
270 {
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
271 # - $0, $1 etc. should all be undefined after a failed match
08d48bd [t] Test suite refactoring.
cosimo authored
272 # (except for special circumstances)
972b6e4 [t/spec] simplify a few tests to use /../ instead of rx/../
moritz authored
273 "abcde" ~~ /(.)(.)(.)/;
274 "abcde" ~~ /(\d)/;
08d48bd [t] Test suite refactoring.
cosimo authored
275 ok((!try { grep { defined($_) }, ($0, $1, $2, $3, $4, $5) }),
276 "all submatches undefined after failed match") or
277 diag("match state: " ~ eval '$/');
278
279 # XXX write me: "special circumstances"
280 }
281
282
283 # subroutines
284 {
285 sub bar ($bar, $baz?, :$quux) {
286 is($bar, "BAR", "defined param"); # sanity
287
60d29c6 fix some legacy smartlink syntax
szabgab authored
288 # L<S06/Optional parameters/Missing optional arguments>
08d48bd [t] Test suite refactoring.
cosimo authored
289 ok(!defined($baz), "unspecified optional param");
290
60d29c6 fix some legacy smartlink syntax
szabgab authored
291 # L<S06/Named parameters/Named parameters are optional>
08d48bd [t] Test suite refactoring.
cosimo authored
292 ok(!defined($quux), "unspecified optional param");
293 }
294
295 bar("BAR");
296
297 }
298
299 # autoloading
300 # L<S10/Autoloading>
301
302 # Currently waiting on
303 # - packages
304 # - symtable hash
305 # - autoloading itself
306
307 # Extra tests added due to apparent bugs
173bb69 [t/spec] correct undef.t, and fudge for rakudo
moritz authored
308 is((Any) + 1, 1, 'Any + 1');
309 is(1 + (Any), 1, '1 + Any');
310 is((Any) * 2, 0, 'Any * 2');
311 is(2 * (Any), 0, '2 * Any');
312 is((Any) xx 2, [Any, Any], 'Any xx 2');
313 is((Any) * (Any), 0, 'Any * Any');
08d48bd [t] Test suite refactoring.
cosimo authored
314
315 # L<http://colabti.de/irclogger/irclogger_log/perl6?date=2006-09-12,Tue&sel=145#l186>
316 # See log above. From IRC, TimToady says that both of these
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
317 # should be false. (At time of writing, @(Mu,) is true.)
a20c69c [t/spec/*.t] :todo whackage
lwall authored
318 #?pugs todo 'feature', :depends<@() imposing context and not [] constructor>;
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
319 #?rakudo 2 skip 'todo: lists, defined, truthness'
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
320 is ?(@(Mu,)), Bool::False, '?(@(Mu,)) is false';
321 is ?(list(Mu,)), Bool::False, '?(@(Mu,)) is false';
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
322
e702d26 [t/spec] really test for #61868 this time
moritz authored
323 lives_ok { uc(eval("")) }, 'can use eval("") in further expressions';
ae01205 [t/spec] Tests inspired by IRC: http://irclog.perlgeek.de/perl6/2009-…
kyle authored
324
325 {
326 sub lie { Bool::False }
327 ok lie() ~~ Bool, 'sub returns a bool';
328 dies_ok { undefine lie }, 'attempt to undefine returned Bool type dies';
329 ok lie() ~~ Bool, 'sub still returns a bool';
330 }
331
332 {
f341480 [t/spec] more warning suppressions; remaining STD warnings are mostly…
lwall authored
333 sub def { my $x = [] } #OK not used
ae01205 [t/spec] Tests inspired by IRC: http://irclog.perlgeek.de/perl6/2009-…
kyle authored
334 ok def() ~~ Array, 'sub returns array';
7805860 @coke nom fudge
coke authored
335 #?rakudo todo 'nom regression'
ae01205 [t/spec] Tests inspired by IRC: http://irclog.perlgeek.de/perl6/2009-…
kyle authored
336 lives_ok { undefine def }, 'attempt to undefine returned array lives';
337 ok def() ~~ Array, 'sub still returns array';
338
339 dies_ok { undefine &def }, 'attempt to undefine sub dies';
340 ok defined &def, 'attempt to undefine sub fails';
f000672 [t/spec] Test suggested by moritz++
kyle authored
341 ok def() ~~ Array, 'can still call sub after attempt to undefine it';
ae01205 [t/spec] Tests inspired by IRC: http://irclog.perlgeek.de/perl6/2009-…
kyle authored
342 }
343
29deb7f [t/spec] test that you can undefine a lexical variable twice; RT #69238
moritz authored
344 # RT #69238
345 {
346 sub foo { my $a = "baz"; undefine $a; undefine $a; $a; }
347 ok !defined(foo()), 'can undefine $a twice without any troubles';
348 }
349
e76dd4c @moritz s/done_testing/done/ as per recent S24 changes
moritz authored
350 done;
ae01205 [t/spec] Tests inspired by IRC: http://irclog.perlgeek.de/perl6/2009-…
kyle authored
351
5f0915d [t/spec] partially fudge undef.t for rakudo. Pending fudge bugs.
moritz authored
352 # vim: ft=perl6
Something went wrong with that request. Please try again.