3 # This file tests the results of calling subroutines in the CORE::
4 # namespace with ampersand syntax. In other words, it tests the bodies of
5 # the subroutines themselves, not the ops that they might inline themselves
6 # as when called as barewords.
8 # Other tests for CORE subs are in coresubs.t
18 &is(map(@$_ ? "[@{[map $_//'~~u~~', @$_]}]" : 'nought', @_[0,1]), $_[2]);
22 use overload '%{}' => sub { +{} }
25 use overload '${}' => sub { \my $x }
29 evalbytes=> 'eval "string"',
30 join => 'join or string',
31 pos => 'match position',
32 prototype=> 'subroutine prototype',
33 readline => '<HANDLE>',
34 readpipe => 'quoted execution (``, qx)',
35 reset => 'symbol reset',
36 ref => 'reference-type operator',
37 undef => 'undef operator',
40 return $op_desc{$_[0]} || $_[0];
44 # This tests that the &{} syntax respects the number of arguments implied
45 # by the prototype, plus some extra tests for the (_) prototype.
49 # Create an alias, for the caller’s convenience.
50 *{"my$o"} = \&{"CORE::$o"};
52 my $p = prototype "CORE::$o";
53 $p = '$;$' if $p eq '$_';
58 eval " &CORE::$o(1) ";
59 like $@, qr/^Too many arguments for $o at /, "&$o with too many args";
62 elsif ($p =~ /^_;?\z/) {
65 eval " &CORE::$o(1,2) ";
66 my $desc = quotemeta op_desc($o);
67 like $@, qr/^Too many arguments for $desc at /,
68 "&$o with too many args";
74 my($in,$out) = @_; # for testing implied $_
76 # Since we have $in and $out values, we might as well test basic amper-
79 is &{"CORE::$o"}($in), $out, "&$o";
80 lis [&{"CORE::$o"}($in)], [$out], "&$o in list context";
83 is &{"CORE::$o"}(), $out, "&$o with no args";
85 # Since there is special code to deal with lexical $_, make sure it
90 is &{"CORE::$o"}(), $out, "&$o with no args uses lexical \$_";
92 # Make sure we get the right pad under recursion
97 is &{"CORE::$o"}(), $out,
98 "&$o with no args uses the right lexical \$_ under recursion";
107 is "CORE::$o"->(), $out, "&$o with the right lexical \$_ in an eval"
110 elsif ($p =~ '^;([$*]+)\z') { # ;$ ;* ;$$ etc.
111 my $maxargs = length $1;
113 eval " &CORE::$o((1)x($maxargs+1)) ";
114 my $desc = quotemeta op_desc($o);
115 like $@, qr/^Too many arguments for $desc at /,
116 "&$o with too many args";
118 elsif ($p =~ '^([$*]+);?\z') { # Fixed-length $$$ or ***
119 my $args = length $1;
121 my $desc = quotemeta op_desc($o);
122 eval " &CORE::$o((1)x($args-1)) ";
123 like $@, qr/^Not enough arguments for $desc at /, "&$o w/too few args";
124 eval " &CORE::$o((1)x($args+1)) ";
125 like $@, qr/^Too many arguments for $desc at /, "&$o w/too many args";
127 elsif ($p =~ '^([$*]+);([$*]+)\z') { # Variable-length $$$ or ***
128 my $minargs = length $1;
129 my $maxargs = $minargs + length $2;
131 eval " &CORE::$o((1)x($minargs-1)) ";
132 like $@, qr/^Not enough arguments for $o at /, "&$o with too few args";
133 eval " &CORE::$o((1)x($maxargs+1)) ";
134 like $@, qr/^Too many arguments for $o at /, "&$o with too many args";
136 elsif ($p eq '_;$') {
139 eval " &CORE::$o(1,2,3) ";
140 like $@, qr/^Too many arguments for $o at /, "&$o with too many args";
143 # Do nothing, as we cannot test for too few or too many arguments.
145 elsif ($p =~ '^[$*;]+@\z') {
149 eval " &CORE::$o((1)x($minargs-1)) ";
150 my $desc = quotemeta op_desc($o);
151 like $@, qr/^Not enough arguments for $desc at /,
152 "&$o with too few args";
154 elsif ($p =~ /^\*\\\$\$(;?)\$\z/) { # *\$$$ and *\$$;$
157 eval "&CORE::$o(1,1,1,1,1)";
158 like $@, qr/^Too many arguments for $o at /,
159 "&$o with too many args";
160 eval " &CORE::$o((1)x(\$1?2:3)) ";
161 like $@, qr/^Not enough arguments for $o at /,
162 "&$o with too few args";
163 eval " &CORE::$o(1,[],1,1) ";
164 like $@, qr/^Type of arg 2 to &CORE::$o must be scalar reference at /,
165 "&$o with array ref arg";
166 eval " &CORE::$o(1,1,1,1) ";
167 like $@, qr/^Type of arg 2 to &CORE::$o must be scalar reference at /,
168 "&$o with scalar arg";
169 eval " &CORE::$o(1,bless([], 'sov'),1,1) ";
170 like $@, qr/^Type of arg 2 to &CORE::$o must be scalar reference at /,
171 "&$o with non-scalar arg w/scalar overload (which does not count)";
173 elsif ($p =~ /^\\%\$*\z/) { # \% and \%$$
176 eval "&CORE::$o(" . join(",", (1) x length $p) . ")";
177 like $@, qr/^Too many arguments for $o at /,
178 "&$o with too many args";
179 eval " &CORE::$o(" . join(",", (1) x (length($p)-2)) . ") ";
180 like $@, qr/^Not enough arguments for $o at /,
181 "&$o with too few args";
182 my $moreargs = ",1" x (length($p) - 2);
183 eval " &CORE::$o([]$moreargs) ";
184 like $@, qr/^Type of arg 1 to &CORE::$o must be hash reference at /,
185 "&$o with array ref arg";
186 eval " &CORE::$o(*foo$moreargs) ";
187 like $@, qr/^Type of arg 1 to &CORE::$o must be hash reference at /,
188 "&$o with typeglob arg";
189 eval " &CORE::$o(bless([], 'hov')$moreargs) ";
190 like $@, qr/^Type of arg 1 to &CORE::$o must be hash reference at /,
191 "&$o with non-hash arg with hash overload (which does not count)";
193 elsif ($p =~ /^(;)?\\\[(\$\@%&?\*)](\$\@)?\z/) {
198 eval " &CORE::$o(1,2) ";
199 like $@, qr/^Too many arguments for ${\op_desc($o)} at /,
200 "&$o with too many args";
204 eval { &{"CORE::$o"}($3 ? 1 : ()) };
205 like $@, qr/^Not enough arguments for $o at /,
206 "&$o with too few args";
208 my $more_args = $3 ? ',1' : '';
209 eval " &CORE::$o(2$more_args) ";
210 like $@, qr/^Type of arg 1 to &CORE::$o must be reference to one of(?x:
212 "&$o with non-ref arg";
213 eval " &CORE::$o(*STDOUT{IO}$more_args) ";
214 like $@, qr/^Type of arg 1 to &CORE::$o must be reference to one of(?x:
216 "&$o with ioref arg";
217 my $class = ref *DATA{IO};
218 eval " &CORE::$o(bless(*DATA{IO}, 'hov')$more_args) ";
219 like $@, qr/^Type of arg 1 to &CORE::$o must be reference to one of(?x:
221 "&$o with ioref arg with hash overload (which does not count)";
222 bless *DATA{IO}, $class;
223 if (do {$2 !~ /&/}) {
225 eval " &CORE::$o(\\&scriggle$more_args) ";
226 like $@, qr/^Type of arg 1 to &CORE::$o must be reference to one (?x:
228 "&$o with coderef arg";
231 elsif ($p eq ';\[$*]') {
234 my $desc = quotemeta op_desc($o);
235 eval " &CORE::$o(1,2) ";
236 like $@, qr/^Too many arguments for $desc at /,
237 "&$o with too many args";
238 eval " &CORE::$o([]) ";
239 like $@, qr/^Type of arg 1 to &CORE::$o must be scalar reference at /,
240 "&$o with array ref arg";
241 eval " &CORE::$o(1) ";
242 like $@, qr/^Type of arg 1 to &CORE::$o must be scalar reference at /,
243 "&$o with scalar arg";
244 eval " &CORE::$o(bless([], 'sov')) ";
245 like $@, qr/^Type of arg 1 to &CORE::$o must be scalar reference at /,
246 "&$o with non-scalar arg w/scalar overload (which does not count)";
250 die "Please add tests for the $p prototype";
254 # Test that &CORE::foo calls without parentheses (no new @_) can handle the
255 # total absence of any @_ without crashing.
259 pass('no crash with &CORE::foo when *_{ARRAY} is undef');
261 test_proto '__FILE__';
262 test_proto '__LINE__';
263 test_proto '__PACKAGE__';
264 test_proto '__SUB__';
266 is file(), 'frob' , '__FILE__ does check its caller' ; ++ $tests;
267 is line(), 5 , '__LINE__ does check its caller' ; ++ $tests;
268 is pakg(), 'stribble', '__PACKAGE__ does check its caller'; ++ $tests;
269 sub __SUB__test { &my__SUB__ }
270 is __SUB__test, \&__SUB__test, '&__SUB__'; ++ $tests;
272 test_proto 'abs', -5, 5;
276 is &CORE::accept(qw{foo bar}), undef, "&accept";
277 lis [&{"CORE::accept"}(qw{foo bar})], [undef], "&accept in list context";
279 &myaccept(my $foo, my $bar);
280 is ref $foo, 'GLOB', 'CORE::accept autovivifies its first argument';
281 is $bar, undef, 'CORE::accept does not autovivify its second argument';
284 eval { 'myaccept'->($foo, $bar) };
285 like $@, qr/^Can't use an undefined value as a symbol reference at/,
286 'CORE::accept will not accept undef 2nd arg under strict';
287 is ref $foo, 'GLOB', 'CORE::accept autovivs its first arg under strict';
295 is &CORE::bind('foo', 'bear'), undef, "&bind";
296 lis [&CORE::bind('foo', 'bear')], [undef], "&bind in list context";
297 eval { &mybind(my $foo, "bear") };
298 like $@, qr/^Bad symbol for filehandle at/,
299 'CORE::bind dies with undef first arg';
301 test_proto 'binmode';
303 is &CORE::binmode(qw[foo bar]), undef, "&binmode";
304 lis [&CORE::binmode(qw[foo bar])], [undef], "&binmode in list context";
305 is &mybinmode(foo), undef, '&binmode with one arg';
309 like &CORE::bless([],'parcel'), qr/^parcel=ARRAY/, "&bless";
310 like join(" ", &CORE::bless([],'parcel')),
311 qr/^parcel=ARRAY(?!.* )/, "&bless in list context";
312 like &mybless([]), qr/^main=ARRAY/, '&bless with one arg';
323 is $tmp, undef, '&break';
329 is scalar &CORE::caller, 'hadhad', '&caller';
330 is scalar &CORE::caller(1), 'main', '&caller(1)';
331 lis [&CORE::caller], [caller], '&caller in list context';
332 # The last element of caller in list context is a hint hash, which
333 # may be a different hash for caller vs &CORE::caller, so an eq com-
334 # parison (which lis() uses for convenience) won’t work. So just
335 # pop the last element, since the rest are sufficient to prove that
336 # &CORE::caller works.
337 my @ampcaller = &CORE::caller(1);
338 my @caller = caller(1);
339 pop @ampcaller; pop @caller;
340 lis \@ampcaller, \@caller, '&caller(1) in list context';
349 is &CORE::chmod(), 0, '&chmod with no args';
350 is &CORE::chmod(0666), 0, '&chmod';
351 lis [&CORE::chmod(0666)], [0], '&chmod in list context';
355 is &CORE::chown(), 0, '&chown with no args';
356 is &CORE::chown(1), 0, '&chown with 1 arg';
357 is &CORE::chown(1,2), 0, '&chown';
358 lis [&CORE::chown(1,2)], [0], '&chown in list context';
360 test_proto 'chr', 5, "\5";
368 open my $fh, ">", \my $buffalo;
369 print $fh 'an address in the outskirts of Jersey';
370 ok &CORE::close($fh), '&CORE::close retval';
372 is $buffalo, 'an address in the outskirts of Jersey',
373 'effect of &CORE::close';
374 # This has to be a separate variable from $fh, as re-using the same
375 # variable can cause the tests to pass by accident. That actually hap-
376 # pened during developement, because the second close() was reading
377 # beyond the end of the stack and finding a $fh left over from before.
378 open my $fh2, ">", \($buffalo = '');
379 select+(select($fh2), do {
380 print "Nasusiro Tokasoni";
383 is $buffalo, "Nasusiro Tokasoni", '&CORE::close with no args';
386 lis [&CORE::close('tototootot')], [''], '&close in list context'; ++$tests;
388 test_proto 'closedir';
390 is &CORE::closedir(foo), undef, '&CORE::closedir';
391 lis [&CORE::closedir(foo)], [undef], '&CORE::closedir in list context';
393 test_proto 'connect';
395 is &CORE::connect('foo','bar'), undef, '&connect';
396 lis [&myconnect('foo','bar')], [undef], '&connect in list context';
398 test_proto 'continue';
410 test_proto 'dbmclose';
411 test_proto 'dbmopen';
413 last unless eval { require AnyDBM_File };
415 my $filename = tempfile();
416 &mydbmopen(\my %db, $filename, 0666);
417 $db{1} = 2; $db{3} = 4;
419 is scalar keys %db, 0, '&dbmopen and &dbmclose';
423 eval { dier('quinquangle') };
424 is $@, "quinquangle at frob line 6.\n", '&CORE::die'; $tests ++;
426 test_proto $_ for qw(
427 endgrent endhostent endnetent endprotoent endpwent endservent
430 test_proto 'evalbytes';
433 chop(my $upgraded = "use utf8; '\xc4\x80'" . chr 256);
434 is &myevalbytes($upgraded), chr 256, '&evalbytes';
439 is someone, "someone", "run-time hint bits do not leak into &evalbytes"
442 BEGIN { $^H{coreamp} = 42 }
446 is $^H{coreamp}, 42, "compile-time hh propagates into &evalbytes";
450 like $@, qr/strict/, 'compile-time hint bits propagate into &evalbytes';
455 is runperl(prog => '&CORE::exit; END { print qq-ok\n- }'), "ok\n",
456 '&exit with no args';
460 test_proto 'formline';
462 is &myformline(' @<<< @>>>', 1, 2), 1, '&myformline retval';
463 is $^A, ' 1 2', 'effect of &myformline';
464 lis [&myformline('@')], [1], '&myformline in list context';
471 my $sharp_s = "\xdf";
472 is &myfc($sharp_s), $sharp_s, '&fc, no unicode_strings';
473 use feature 'unicode_strings';
474 is &myfc($sharp_s), "ss", '&fc, unicode_strings';
481 is &CORE::fileno(\*STDIN), fileno STDIN, '&CORE::fileno';
482 lis [&CORE::fileno(\*STDIN)], [fileno STDIN], '&CORE::fileno in list cx';
492 open my $fh, "<", \(my $buf='falo');
493 open STDIN, "<", \(my $buf2 = 'bison');
494 is &mygetc($fh), 'f', '&mygetc';
495 is &mygetc(), 'b', '&mygetc with no args';
496 lis [&mygetc($fh)], ['a'], '&mygetc in list context';
499 test_proto "get$_" for qw '
500 grent grgid grnam hostbyaddr hostbyname hostent login netbyaddr netbyname
504 test_proto 'getpgrp';
506 pass '&getpgrp with no args does not crash'; $tests++;
508 test_proto "get$_" for qw '
509 ppid priority protobyname protobynumber protoent
510 pwent pwnam pwuid servbyname servbyport servent sockname sockopt
513 # Make sure the following tests test what we think they are testing.
514 ok ! $CORE::{glob}, '*CORE::glob not autovivified yet'; $tests ++;
516 # Make sure ck_glob does not respect the override when &CORE::glob is
517 # autovivified (by test_proto).
518 local *CORE::GLOBAL::glob = sub {};
523 is join($", &myglob()), "@_", '&glob without arguments';
524 is join($", &myglob("t/*.t")), "@_", '&glob with an arg';
529 pass '&gmtime without args does not crash'; ++$tests;
531 test_proto 'hex', ff=>255;
535 is &myindex("foffooo","o",2),4,'&index';
536 lis [&myindex("foffooo","o",2)],[4],'&index in list context';
537 is &myindex("foffooo","o"),1,'&index with 2 args';
539 test_proto 'int', 1.5=>1;
544 is &myjoin('a','b','c'), 'bac', '&join';
545 lis [&myjoin('a','b','c')], ['bac'], '&join in list context';
547 test_proto 'kill'; # set up mykill alias
548 if ($^O ne 'riscos') {
550 ok( &mykill(0, $$), '&kill' );
553 test_proto 'lc', 'A', 'a';
554 test_proto 'lcfirst', 'AA', 'aA';
555 test_proto 'length', 'aaa', 3;
559 test_proto 'localtime';
561 pass '&localtime without args does not crash'; ++$tests;
565 is \&mylock(\$foo), \$foo, '&lock retval when passed a scalar ref';
566 lis [\&mylock(\$foo)], [\$foo], '&lock in list context';
567 is &mylock(\@foo), \@foo, '&lock retval when passed an array ref';
568 is &mylock(\%foo), \%foo, '&lock retval when passed a ash ref';
569 is &mylock(\&foo), \&foo, '&lock retval when passed a code ref';
570 is \&mylock(\*foo), \*foo, '&lock retval when passed a glob ref';
575 # mkdir is tested with implicit $_ at the end, to make the test easier
577 test_proto "msg$_" for qw( ctl get rcv snd );
581 is &mynot(1), !1, '¬';
582 lis [&mynot(0)], [!0], '¬ in list context';
584 test_proto 'oct', '666', 438;
589 ok &myopen('file'), '&open with 1 arg' or warn "1-arg open: $!";
590 like <file>, qr|^#|, 'result of &open with 1 arg';
593 ok &myopen(my $fh, "test.pl"), 'two-arg &open';
594 ok $fh, '&open autovivifies';
595 like <$fh>, qr '^#', 'result of &open with 2 args';
598 ok &myopen(my $fh2, "<", \"sharummbles"), 'retval of 3-arg &open';
599 is <$fh2>, 'sharummbles', 'result of three-arg &open';
602 test_proto 'opendir';
603 test_proto 'ord', chr(64), 64;
607 is &mypack("H*", '5065726c'), 'Perl', '&pack';
608 lis [&mypack("H*", '5065726c')], ['Perl'], '&pack in list context';
616 is &mypos, 3, 'reading &pos without args';
618 is pos, 4, 'writing to &pos without args';
622 is &mypos(\$x), 3, 'reading &pos without args';
624 is pos $x, 4, 'writing to &pos without args';
627 test_proto 'prototype';
629 is &myprototype(\&myprototype), prototype("CORE::prototype"), '&prototype';
631 test_proto 'quotemeta', '$', '\$';
635 like &CORE::rand, qr/^0[.\d]*\z/, '&rand';
636 unlike join(" ", &CORE::rand), qr/ /, '&rand in list context';
637 &cmp_ok(&CORE::rand(78), qw '< 78', '&rand with 2 args');
643 open my $fh, "<", \(my $buff = 'morays have their mores');
644 ok &myread($fh, \my $input, 6), '&read with 3 args';
645 is $input, 'morays', 'value read by 3-arg &read';
646 ok &myread($fh, \$input, 6, 6), '&read with 4 args';
647 is $input, 'morays have ', 'value read by 4-arg &read';
648 is +()=&myread($fh, \$input, 6), 1, '&read in list context';
651 test_proto 'readdir';
653 test_proto 'readline';
657 is scalar &myreadline,
658 "I wandered lonely as a cloud\n", '&readline w/no args';
663 open my $fh, "<", \(my $buff = <<END);
664 The Recursive Problem
665 ---------------------
666 I have a problem I cannot solve.
667 The problem is that I cannot solve it.
669 is &myreadline($fh), "The Recursive Problem\n",
670 '&readline with 1 arg';
671 lis [&myreadline($fh)], [
672 "---------------------\n",
673 "I have a problem I cannot solve.\n",
674 "The problem is that I cannot solve it.\n",
675 ], '&readline in list context';
678 test_proto 'readlink';
679 test_proto 'readpipe';
682 use if !is_miniperl, File::Spec::Functions, qw "catfile";
683 use if !is_miniperl, File::Temp, 'tempdir';
689 my $dir = tempdir(uc cleanup => 1);
690 my $tmpfilenam = catfile $dir, 'aaa';
691 open my $fh, ">", $tmpfilenam or die "cannot open $tmpfilenam: $!";
692 close $fh or die "cannot close $tmpfilenam: $!";
693 &myrename("$tmpfilenam", $tmpfilenam = catfile $dir,'bbb');
694 ok open(my $fh, '>', $tmpfilenam), '&rename';
697 test_proto 'ref', [], 'ARRAY';
701 my $oncer = sub { "a" =~ m?a? };
704 ok &$oncer, '&reset with no args';
709 ::lis [$b,$banana],[(undef)x2], '1-arg &reset';
712 test_proto 'reverse';
714 is &myreverse('reward'), 'drawer', '&reverse';
715 lis [&myreverse(qw 'dog bites man')], [qw 'man bites dog'],
716 '&reverse in list context';
718 test_proto 'rewinddir';
722 is &myrindex("foffooo","o",2),1,'&rindex';
723 lis [&myrindex("foffooo","o",2)],[1],'&rindex in list context';
724 is &myrindex("foffooo","o"),6,'&rindex with 2 args';
730 is &myscalar(3), 3, '&scalar';
731 lis [&myscalar(3)], [3], '&scalar in list cx';
737 open my $fh, "<", \"misled" or die $!;
739 is <$fh>, 'sled', '&seek in action';
742 test_proto 'seekdir';
744 # Can’t test_proto, as it has none
746 *myselect = \&CORE::select;
747 is defined prototype &myselect, defined prototype "CORE::select",
748 'prototype of &select (or lack thereof)';
749 is &myselect, select, '&select with no args';
752 is &myselect(my $fh), $prev, '&select($arg) retval';
753 is lc ref $fh, 'glob', '&select autovivifies';
754 is select=~s/\*//rug, (*$fh."")=~s/\*//rug, '&select selects';
757 eval { &myselect(1,2) };
758 like $@, qr/^Not enough arguments for select system call at /,
759 ,'&myselect($two,$args)';
760 eval { &myselect(1,2,3) };
761 like $@, qr/^Not enough arguments for select system call at /,
762 ,'&myselect($with,$three,$args)';
763 eval { &myselect(1,2,3,4,5) };
764 like $@, qr/^Too many arguments for select system call at /,
765 ,'&myselect($a,$total,$of,$five,$args)';
766 &myselect((undef)x3,.25);
767 # Just have to assume that worked. :-) If we get here, at least it didn’t
770 test_proto "sem$_" for qw "ctl get op";
774 test_proto "set$_" for qw '
778 test_proto 'setpgrp';
780 eval { &mysetpgrp( 0) };
781 pass "&setpgrp with one argument";
783 pass "&setpgrp with no arguments";
785 test_proto "set$_" for qw '
786 priority protoent pwent servent sockopt
789 test_proto "shm$_" for qw "ctl get read write";
790 test_proto 'shutdown';
793 test_proto "socket$_" for "", "pair";
795 test_proto 'sprintf';
797 is &mysprintf("%x", 65), '41', '&sprintf';
798 lis [&mysprintf("%x", '65')], ['41'], '&sprintf in list context';
800 test_proto 'sqrt', 4, 2;
805 pass '&srand with no args does not crash';
812 is &mysubstr($_, 1, 1, "d"), 'b', '4-arg &substr';
813 is $_, 'adc', 'what 4-arg &substr does';
814 is &mysubstr("abc", 1, 1), 'b', '3-arg &substr';
815 is &mysubstr("abc", 1), 'bc', '2-arg &substr';
816 &mysubstr($_, 1) = 'long';
817 is $_, 'along', 'lvalue &substr';
819 test_proto 'symlink';
820 test_proto 'syscall';
822 test_proto 'sysopen';
825 &mysysopen(my $fh, 'test.pl', 0);
826 pass '&sysopen does not crash with 3 args';
827 ok $fh, 'sysopen autovivifies';
830 test_proto 'sysread';
831 test_proto 'sysseek';
832 test_proto 'syswrite';
837 open my $fh, "test.pl" or die "Cannot open test.pl";
839 is &mytell(), tell($fh), '&tell with no args';
840 is &mytell($fh), tell($fh), '&tell with an arg';
843 test_proto 'telldir';
851 sub TIESCALAR { bless[] }
852 sub FETCH { ++$fetches }
855 my $obj = &mytie(\$tied, 'tier');
856 is &mytied(\$tied), $obj, '&tie and &tied retvals';
858 is $fetches, 1, '&tie actually ties';
859 &CORE::untie(\$tied);
861 is $fetches, 1, '&untie unties';
866 like &mytime, '^\d+\z', '&time in scalar context';
867 like join('-', &mytime), '^\d+\z', '&time in list context';
871 like &mytimes, '^[\d.]+\z', '× in scalar context';
872 like join('-',&mytimes), '^[\d.]+-[\d.]+-[\d.]+-[\d.]+\z',
873 '× in list context';
875 test_proto 'uc', 'aa', 'AA';
876 test_proto 'ucfirst', 'aa', "Aa";
880 is &myumask, umask, '&umask with no args';
884 is &myundef(), undef, '&undef returns undef';
885 lis [&myundef()], [undef], '&undef returns undef in list cx';
886 lis [&myundef(\$_)], [undef], '&undef(...) returns undef in list cx';
887 is \&myundef(), \undef, '&undef returns the right undef';
888 $_ = 'anserine questions';
890 is $_, undef, '&undef(\$_) undefines $_';
893 is @_, 0, '&undef(\@_) undefines @_';
896 ok !%_, '&undef(\%_) undefines %_';
897 &myundef(\&utf8::valid); # nobody should be using this :-)
898 ok !defined &utf8::valid, '&undef(\&foo) undefines &foo';
901 is *_{ARRAY}, undef, '&undef(\*_) undefines *_';
902 (&myundef(), @_) = 1..10;
903 lis \@_, [2..10], 'list assignment to &undef()';
904 ok !defined undef, 'list assignment to &undef() does not affect undef';
910 is &myunpack("H*"), '61626364', '&unpack with one arg';
911 is &myunpack("H*", "bcde"), '62636465', '&unpack with two arg';
914 test_proto 'untie'; # behaviour already tested along with tie(d)
918 is &myutime(undef,undef), 0, '&utime';
919 lis [&myutime(undef,undef)], [0], '&utime in list context';
923 is &myvec("foo", 0, 4), 6, '&vec';
924 lis [&myvec("foo", 0, 4)], [6], '&vec in list context';
927 is $tmp, "goo", 'lvalue &vec';
930 test_proto 'waitpid';
932 test_proto 'wantarray';
936 $context = qw[void scalar list][&mywantarray + defined mywantarray()]
939 is $context, 'list', '&wantarray with caller in list context';
941 is($context, 'scalar', '&wantarray with caller in scalar context');
943 is($context, 'void', '&wantarray with caller in void context');
944 lis [&mywantarray],[wantarray], '&wantarray itself in list context';
949 local $SIG{__WARN__} = sub { $w = shift };
950 is &mywarn('a'), 1, '&warn retval';
951 is $w, "a at " . __FILE__ . " line " . (__LINE__-1) . ".\n", 'warning';
952 lis [&mywarn()], [1], '&warn retval in list context';
958 like $@, qr'^Undefined format "STDOUT" called',
959 "&write without arguments can handle the null";
961 # This is just a check to make sure we have tested everything. If we
962 # haven’t, then either the sub needs to be tested or the list in
966 require File::Spec::Functions;
968 File::Spec::Functions::catfile(
969 File::Spec::Functions::updir,'regen','keywords.pl'
971 open my $kh, $keywords_file
972 or die "$0 cannot open $keywords_file: $!";
974 if (m?__END__?..${\0} and /^[-+](.*)/) {
977 $word =~ /^(?:s(?:tate|ort|ay|ub)?|d(?:ef
978 ault|ump|o)|p(?:rintf?|ackag
979 e)|e(?:ls(?:if|e)|val|q)|g(?:[et]|iven|oto
980 |rep)|u(?:n(?:less|til)|se)|l(?:(?:as)?t|ocal|e)|re
981 (?:quire|turn|do)|__(?:DATA|END)__|for(?:each|mat)?|(?:
982 AUTOLOA|EN)D|n(?:e(?:xt)?|o)|C(?:HECK|ORE)|wh(?:ile|en)
983 |(?:ou?|t)r|m(?:ap|y)?|UNITCHECK|q[qrwx]?|x(?:or)?|DEST
984 ROY|BEGIN|INIT|and|cmp|if|y)\z/x;
986 ok exists &{"my$word"}
987 || (eval{&{"CORE::$word"}}, $@ =~ /cannot be called directly/),
988 "$word either has been tested or is not ampable";
993 # Add new tests above this line.
995 # This test must come last (before the test count test):
1002 require File::Temp ;
1003 my $dir = File::Temp::tempdir(uc cleanup => 1);
1007 # Make sure that implicit $_ is not applied to mkdir’s second argument.
1010 local $SIG{__WARN__} = sub { ++$warnings };
1013 ok &mymkdir(), '&mkdir';
1014 like <*>, qr/^phoo(.DIR)?\z/i, 'mkdir works with implicit $_';
1016 is $warnings, undef, 'no implicit $_ for second argument to mkdir';
1018 chdir($cwd); # so auto-cleanup can remove $dir
1021 # ------------ END TESTING ----------- #
1023 done_testing $tests;
1027 sub file { &CORE::__FILE__ }
1028 sub line { &CORE::__LINE__ } # 5
1029 sub dier { &CORE::die(@_) } # 6
1031 sub main::pakg { &CORE::__PACKAGE__ }
1033 # Please do not add new tests here.
1036 I wandered lonely as a cloud
1037 That floats on high o’er vales and hills,
1038 And all at once I saw a crowd,
1039 A host of golden daffodils!
1040 Beside the lake, beneath the trees,
1041 Fluttering, dancing, in the breeze.