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
17 no warnings 'experimental::smartmatch';
20 &is(map(@$_ ? "[@{[map $_//'~~u~~', @$_]}]" : 'nought', @_[0,1]), $_[2]);
24 use overload '%{}' => sub { +{} }
27 use overload '${}' => sub { \my $x }
31 evalbytes=> 'eval "string"',
32 join => 'join or string',
33 pos => 'match position',
34 prototype=> 'subroutine prototype',
35 readline => '<HANDLE>',
36 readpipe => 'quoted execution (``, qx)',
37 reset => 'symbol reset',
38 ref => 'reference-type operator',
39 undef => 'undef operator',
42 return $op_desc{$_[0]} || $_[0];
46 # This tests that the &{} syntax respects the number of arguments implied
47 # by the prototype, plus some extra tests for the (_) prototype.
51 # Create an alias, for the caller’s convenience.
52 *{"my$o"} = \&{"CORE::$o"};
54 my $p = prototype "CORE::$o";
55 $p = '$;$' if $p eq '$_';
60 eval " &CORE::$o(1) ";
61 like $@, qr/^Too many arguments for $o at /, "&$o with too many args";
64 elsif ($p =~ /^_;?\z/) {
67 eval " &CORE::$o(1,2) ";
68 my $desc = quotemeta op_desc($o);
69 like $@, qr/^Too many arguments for $desc at /,
70 "&$o with too many args";
76 my($in,$out) = @_; # for testing implied $_
78 # Since we have $in and $out values, we might as well test basic amper-
81 is &{"CORE::$o"}($in), $out, "&$o";
82 lis [&{"CORE::$o"}($in)], [$out], "&$o in list context";
85 is &{"CORE::$o"}(), $out, "&$o with no args";
87 # Since there is special code to deal with lexical $_, make sure it
91 no warnings 'experimental::lexical_topic';
93 is &{"CORE::$o"}(), $out, "&$o with no args uses lexical \$_";
95 # Make sure we get the right pad under recursion
99 no warnings 'experimental::lexical_topic';
101 is &{"CORE::$o"}(), $out,
102 "&$o with no args uses the right lexical \$_ under recursion";
109 no warnings 'experimental::lexical_topic';
112 is "CORE::$o"->(), $out, "&$o with the right lexical \$_ in an eval"
115 elsif ($p =~ '^;([$*]+)\z') { # ;$ ;* ;$$ etc.
116 my $maxargs = length $1;
118 eval " &CORE::$o((1)x($maxargs+1)) ";
119 my $desc = quotemeta op_desc($o);
120 like $@, qr/^Too many arguments for $desc at /,
121 "&$o with too many args";
123 elsif ($p =~ '^([$*]+);?\z') { # Fixed-length $$$ or ***
124 my $args = length $1;
126 my $desc = quotemeta op_desc($o);
127 eval " &CORE::$o((1)x($args-1)) ";
128 like $@, qr/^Not enough arguments for $desc at /, "&$o w/too few args";
129 eval " &CORE::$o((1)x($args+1)) ";
130 like $@, qr/^Too many arguments for $desc at /, "&$o w/too many args";
132 elsif ($p =~ '^([$*]+);([$*]+)\z') { # Variable-length $$$ or ***
133 my $minargs = length $1;
134 my $maxargs = $minargs + length $2;
136 eval " &CORE::$o((1)x($minargs-1)) ";
137 like $@, qr/^Not enough arguments for $o at /, "&$o with too few args";
138 eval " &CORE::$o((1)x($maxargs+1)) ";
139 like $@, qr/^Too many arguments for $o at /, "&$o with too many args";
141 elsif ($p eq '_;$') {
144 eval " &CORE::$o(1,2,3) ";
145 like $@, qr/^Too many arguments for $o at /, "&$o with too many args";
148 # Do nothing, as we cannot test for too few or too many arguments.
150 elsif ($p =~ '^[$*;]+@\z') {
154 eval " &CORE::$o((1)x($minargs-1)) ";
155 my $desc = quotemeta op_desc($o);
156 like $@, qr/^Not enough arguments for $desc at /,
157 "&$o with too few args";
159 elsif ($p =~ /^\*\\\$\$(;?)\$\z/) { # *\$$$ and *\$$;$
162 eval "&CORE::$o(1,1,1,1,1)";
163 like $@, qr/^Too many arguments for $o at /,
164 "&$o with too many args";
165 eval " &CORE::$o((1)x(\$1?2:3)) ";
166 like $@, qr/^Not enough arguments for $o at /,
167 "&$o with too few args";
168 eval " &CORE::$o(1,[],1,1) ";
169 like $@, qr/^Type of arg 2 to &CORE::$o must be scalar reference at /,
170 "&$o with array ref arg";
171 eval " &CORE::$o(1,1,1,1) ";
172 like $@, qr/^Type of arg 2 to &CORE::$o must be scalar reference at /,
173 "&$o with scalar arg";
174 eval " &CORE::$o(1,bless([], 'sov'),1,1) ";
175 like $@, qr/^Type of arg 2 to &CORE::$o must be scalar reference at /,
176 "&$o with non-scalar arg w/scalar overload (which does not count)";
178 elsif ($p =~ /^\\%\$*\z/) { # \% and \%$$
181 eval "&CORE::$o(" . join(",", (1) x length $p) . ")";
182 like $@, qr/^Too many arguments for $o at /,
183 "&$o with too many args";
184 eval " &CORE::$o(" . join(",", (1) x (length($p)-2)) . ") ";
185 like $@, qr/^Not enough arguments for $o at /,
186 "&$o with too few args";
187 my $moreargs = ",1" x (length($p) - 2);
188 eval " &CORE::$o([]$moreargs) ";
189 like $@, qr/^Type of arg 1 to &CORE::$o must be hash reference at /,
190 "&$o with array ref arg";
191 eval " &CORE::$o(*foo$moreargs) ";
192 like $@, qr/^Type of arg 1 to &CORE::$o must be hash reference at /,
193 "&$o with typeglob arg";
194 eval " &CORE::$o(bless([], 'hov')$moreargs) ";
195 like $@, qr/^Type of arg 1 to &CORE::$o must be hash reference at /,
196 "&$o with non-hash arg with hash overload (which does not count)";
198 elsif ($p =~ /^(;)?\\\[(\$\@%&?\*)](\$\@)?\z/) {
203 eval " &CORE::$o(1,2) ";
204 like $@, qr/^Too many arguments for ${\op_desc($o)} at /,
205 "&$o with too many args";
209 eval { &{"CORE::$o"}($3 ? 1 : ()) };
210 like $@, qr/^Not enough arguments for $o at /,
211 "&$o with too few args";
213 my $more_args = $3 ? ',1' : '';
214 eval " &CORE::$o(2$more_args) ";
215 like $@, qr/^Type of arg 1 to &CORE::$o must be reference to one of(?x:
217 "&$o with non-ref arg";
218 eval " &CORE::$o(*STDOUT{IO}$more_args) ";
219 like $@, qr/^Type of arg 1 to &CORE::$o must be reference to one of(?x:
221 "&$o with ioref arg";
222 my $class = ref *DATA{IO};
223 eval " &CORE::$o(bless(*DATA{IO}, 'hov')$more_args) ";
224 like $@, qr/^Type of arg 1 to &CORE::$o must be reference to one of(?x:
226 "&$o with ioref arg with hash overload (which does not count)";
227 bless *DATA{IO}, $class;
228 if (do {$2 !~ /&/}) {
230 eval " &CORE::$o(\\&scriggle$more_args) ";
231 like $@, qr/^Type of arg 1 to &CORE::$o must be reference to one (?x:
233 "&$o with coderef arg";
236 elsif ($p eq ';\[$*]') {
239 my $desc = quotemeta op_desc($o);
240 eval " &CORE::$o(1,2) ";
241 like $@, qr/^Too many arguments for $desc at /,
242 "&$o with too many args";
243 eval " &CORE::$o([]) ";
244 like $@, qr/^Type of arg 1 to &CORE::$o must be scalar reference at /,
245 "&$o with array ref arg";
246 eval " &CORE::$o(1) ";
247 like $@, qr/^Type of arg 1 to &CORE::$o must be scalar reference at /,
248 "&$o with scalar arg";
249 eval " &CORE::$o(bless([], 'sov')) ";
250 like $@, qr/^Type of arg 1 to &CORE::$o must be scalar reference at /,
251 "&$o with non-scalar arg w/scalar overload (which does not count)";
255 die "Please add tests for the $p prototype";
259 # Test that &CORE::foo calls without parentheses (no new @_) can handle the
260 # total absence of any @_ without crashing.
264 pass('no crash with &CORE::foo when *_{ARRAY} is undef');
266 test_proto '__FILE__';
267 test_proto '__LINE__';
268 test_proto '__PACKAGE__';
269 test_proto '__SUB__';
271 is file(), 'frob' , '__FILE__ does check its caller' ; ++ $tests;
272 is line(), 5 , '__LINE__ does check its caller' ; ++ $tests;
273 is pakg(), 'stribble', '__PACKAGE__ does check its caller'; ++ $tests;
274 sub __SUB__test { &my__SUB__ }
275 is __SUB__test, \&__SUB__test, '&__SUB__'; ++ $tests;
277 test_proto 'abs', -5, 5;
281 is &CORE::accept(qw{foo bar}), undef, "&accept";
282 lis [&{"CORE::accept"}(qw{foo bar})], [undef], "&accept in list context";
284 &myaccept(my $foo, my $bar);
285 is ref $foo, 'GLOB', 'CORE::accept autovivifies its first argument';
286 is $bar, undef, 'CORE::accept does not autovivify its second argument';
289 eval { 'myaccept'->($foo, $bar) };
290 like $@, qr/^Can't use an undefined value as a symbol reference at/,
291 'CORE::accept will not accept undef 2nd arg under strict';
292 is ref $foo, 'GLOB', 'CORE::accept autovivs its first arg under strict';
300 is &CORE::bind('foo', 'bear'), undef, "&bind";
301 lis [&CORE::bind('foo', 'bear')], [undef], "&bind in list context";
302 eval { &mybind(my $foo, "bear") };
303 like $@, qr/^Bad symbol for filehandle at/,
304 'CORE::bind dies with undef first arg';
306 test_proto 'binmode';
308 is &CORE::binmode(qw[foo bar]), undef, "&binmode";
309 lis [&CORE::binmode(qw[foo bar])], [undef], "&binmode in list context";
310 is &mybinmode(foo), undef, '&binmode with one arg';
314 like &CORE::bless([],'parcel'), qr/^parcel=ARRAY/, "&bless";
315 like join(" ", &CORE::bless([],'parcel')),
316 qr/^parcel=ARRAY(?!.* )/, "&bless in list context";
317 like &mybless([]), qr/^main=ARRAY/, '&bless with one arg';
328 is $tmp, undef, '&break';
334 is scalar &CORE::caller, 'hadhad', '&caller';
335 is scalar &CORE::caller(1), 'main', '&caller(1)';
336 lis [&CORE::caller], [caller], '&caller in list context';
337 # The last element of caller in list context is a hint hash, which
338 # may be a different hash for caller vs &CORE::caller, so an eq com-
339 # parison (which lis() uses for convenience) won’t work. So just
340 # pop the last element, since the rest are sufficient to prove that
341 # &CORE::caller works.
342 my @ampcaller = &CORE::caller(1);
343 my @caller = caller(1);
344 pop @ampcaller; pop @caller;
345 lis \@ampcaller, \@caller, '&caller(1) in list context';
354 is &CORE::chmod(), 0, '&chmod with no args';
355 is &CORE::chmod(0666), 0, '&chmod';
356 lis [&CORE::chmod(0666)], [0], '&chmod in list context';
360 is &CORE::chown(), 0, '&chown with no args';
361 is &CORE::chown(1), 0, '&chown with 1 arg';
362 is &CORE::chown(1,2), 0, '&chown';
363 lis [&CORE::chown(1,2)], [0], '&chown in list context';
365 test_proto 'chr', 5, "\5";
373 open my $fh, ">", \my $buffalo;
374 print $fh 'an address in the outskirts of Jersey';
375 ok &CORE::close($fh), '&CORE::close retval';
377 is $buffalo, 'an address in the outskirts of Jersey',
378 'effect of &CORE::close';
379 # This has to be a separate variable from $fh, as re-using the same
380 # variable can cause the tests to pass by accident. That actually hap-
381 # pened during developement, because the second close() was reading
382 # beyond the end of the stack and finding a $fh left over from before.
383 open my $fh2, ">", \($buffalo = '');
384 select+(select($fh2), do {
385 print "Nasusiro Tokasoni";
388 is $buffalo, "Nasusiro Tokasoni", '&CORE::close with no args';
391 lis [&CORE::close('tototootot')], [''], '&close in list context'; ++$tests;
393 test_proto 'closedir';
395 is &CORE::closedir(foo), undef, '&CORE::closedir';
396 lis [&CORE::closedir(foo)], [undef], '&CORE::closedir in list context';
398 test_proto 'connect';
400 is &CORE::connect('foo','bar'), undef, '&connect';
401 lis [&myconnect('foo','bar')], [undef], '&connect in list context';
403 test_proto 'continue';
415 test_proto 'dbmclose';
416 test_proto 'dbmopen';
418 last unless eval { require AnyDBM_File };
420 my $filename = tempfile();
421 &mydbmopen(\my %db, $filename, 0666);
422 $db{1} = 2; $db{3} = 4;
424 is scalar keys %db, 0, '&dbmopen and &dbmclose';
425 my $Dfile = "$filename.pag";
427 ($Dfile) = <$filename*>;
430 unlink "$filename.sdbm_dir", $Dfile;
432 unlink "$filename.dir", $Dfile;
437 eval { dier('quinquangle') };
438 is $@, "quinquangle at frob line 6.\n", '&CORE::die'; $tests ++;
440 test_proto $_ for qw(
441 endgrent endhostent endnetent endprotoent endpwent endservent
444 test_proto 'evalbytes';
447 chop(my $upgraded = "use utf8; '\xc4\x80'" . chr 256);
448 is &myevalbytes($upgraded), chr 256, '&evalbytes';
453 is someone, "someone", "run-time hint bits do not leak into &evalbytes"
456 BEGIN { $^H{coreamp} = 42 }
460 is $^H{coreamp}, 42, "compile-time hh propagates into &evalbytes";
464 like $@, qr/strict/, 'compile-time hint bits propagate into &evalbytes';
469 is runperl(prog => '&CORE::exit; END { print qq-ok\n- }'), "ok\n",
470 '&exit with no args';
474 test_proto 'formline';
476 is &myformline(' @<<< @>>>', 1, 2), 1, '&myformline retval';
477 is $^A, ' 1 2', 'effect of &myformline';
478 lis [&myformline('@')], [1], '&myformline in list context';
485 my $sharp_s = "\xdf";
486 is &myfc($sharp_s), $sharp_s, '&fc, no unicode_strings';
487 use feature 'unicode_strings';
488 is &myfc($sharp_s), "ss", '&fc, unicode_strings';
495 is &CORE::fileno(\*STDIN), fileno STDIN, '&CORE::fileno';
496 lis [&CORE::fileno(\*STDIN)], [fileno STDIN], '&CORE::fileno in list cx';
506 open my $fh, "<", \(my $buf='falo');
507 open STDIN, "<", \(my $buf2 = 'bison');
508 is &mygetc($fh), 'f', '&mygetc';
509 is &mygetc(), 'b', '&mygetc with no args';
510 lis [&mygetc($fh)], ['a'], '&mygetc in list context';
513 test_proto "get$_" for qw '
514 grent grgid grnam hostbyaddr hostbyname hostent login netbyaddr netbyname
518 test_proto 'getpgrp';
520 pass '&getpgrp with no args does not crash'; $tests++;
522 test_proto "get$_" for qw '
523 ppid priority protobyname protobynumber protoent
524 pwent pwnam pwuid servbyname servbyport servent sockname sockopt
527 # Make sure the following tests test what we think they are testing.
528 ok ! $CORE::{glob}, '*CORE::glob not autovivified yet'; $tests ++;
530 # Make sure ck_glob does not respect the override when &CORE::glob is
531 # autovivified (by test_proto).
532 local *CORE::GLOBAL::glob = sub {};
537 is join($", &myglob()), "@_", '&glob without arguments';
538 is join($", &myglob("t/*.t")), "@_", '&glob with an arg';
543 pass '&gmtime without args does not crash'; ++$tests;
545 test_proto 'hex', ff=>255;
549 is &myindex("foffooo","o",2),4,'&index';
550 lis [&myindex("foffooo","o",2)],[4],'&index in list context';
551 is &myindex("foffooo","o"),1,'&index with 2 args';
553 test_proto 'int', 1.5=>1;
558 is &myjoin('a','b','c'), 'bac', '&join';
559 lis [&myjoin('a','b','c')], ['bac'], '&join in list context';
561 test_proto 'kill'; # set up mykill alias
562 if ($^O ne 'riscos') {
564 ok( &mykill(0, $$), '&kill' );
567 test_proto 'lc', 'A', 'a';
568 test_proto 'lcfirst', 'AA', 'aA';
569 test_proto 'length', 'aaa', 3;
573 test_proto 'localtime';
575 pass '&localtime without args does not crash'; ++$tests;
579 is \&mylock(\$foo), \$foo, '&lock retval when passed a scalar ref';
580 lis [\&mylock(\$foo)], [\$foo], '&lock in list context';
581 is &mylock(\@foo), \@foo, '&lock retval when passed an array ref';
582 is &mylock(\%foo), \%foo, '&lock retval when passed a ash ref';
583 is &mylock(\&foo), \&foo, '&lock retval when passed a code ref';
584 is \&mylock(\*foo), \*foo, '&lock retval when passed a glob ref';
589 # mkdir is tested with implicit $_ at the end, to make the test easier
591 test_proto "msg$_" for qw( ctl get rcv snd );
595 is &mynot(1), !1, '¬';
596 lis [&mynot(0)], [!0], '¬ in list context';
598 test_proto 'oct', '666', 438;
603 ok &myopen('file'), '&open with 1 arg' or warn "1-arg open: $!";
604 like <file>, qr|^#|, 'result of &open with 1 arg';
607 ok &myopen(my $fh, "test.pl"), 'two-arg &open';
608 ok $fh, '&open autovivifies';
609 like <$fh>, qr '^#', 'result of &open with 2 args';
612 ok &myopen(my $fh2, "<", \"sharummbles"), 'retval of 3-arg &open';
613 is <$fh2>, 'sharummbles', 'result of three-arg &open';
616 test_proto 'opendir';
617 test_proto 'ord', chr(64), 64;
621 is &mypack("H*", '5065726c'), 'Perl', '&pack';
622 lis [&mypack("H*", '5065726c')], ['Perl'], '&pack in list context';
630 is &mypos, 3, 'reading &pos without args';
632 is pos, 4, 'writing to &pos without args';
636 is &mypos(\$x), 3, 'reading &pos without args';
638 is pos $x, 4, 'writing to &pos without args';
641 test_proto 'prototype';
643 is &myprototype(\&myprototype), prototype("CORE::prototype"), '&prototype';
645 test_proto 'quotemeta', '$', '\$';
651 use warnings FATAL => qw{numeric uninitialized};
653 }, '&rand returns a valid number';
654 unlike join(" ", &CORE::rand), qr/ /, '&rand in list context';
655 &cmp_ok(&CORE::rand(78), qw '< 78', '&rand with 1 arg');
661 open my $fh, "<", \(my $buff = 'morays have their mores');
662 ok &myread($fh, \my $input, 6), '&read with 3 args';
663 is $input, 'morays', 'value read by 3-arg &read';
664 ok &myread($fh, \$input, 6, 6), '&read with 4 args';
665 is $input, 'morays have ', 'value read by 4-arg &read';
666 is +()=&myread($fh, \$input, 6), 1, '&read in list context';
669 test_proto 'readdir';
671 test_proto 'readline';
675 is scalar &myreadline,
676 "I wandered lonely as a cloud\n", '&readline w/no args';
681 open my $fh, "<", \(my $buff = <<END);
682 The Recursive Problem
683 ---------------------
684 I have a problem I cannot solve.
685 The problem is that I cannot solve it.
687 is &myreadline($fh), "The Recursive Problem\n",
688 '&readline with 1 arg';
689 lis [&myreadline($fh)], [
690 "---------------------\n",
691 "I have a problem I cannot solve.\n",
692 "The problem is that I cannot solve it.\n",
693 ], '&readline in list context';
696 test_proto 'readlink';
697 test_proto 'readpipe';
700 use if !is_miniperl, File::Spec::Functions, qw "catfile";
701 use if !is_miniperl, File::Temp, 'tempdir';
707 my $dir = tempdir(uc cleanup => 1);
708 my $tmpfilenam = catfile $dir, 'aaa';
709 open my $fh, ">", $tmpfilenam or die "cannot open $tmpfilenam: $!";
710 close $fh or die "cannot close $tmpfilenam: $!";
711 &myrename("$tmpfilenam", $tmpfilenam = catfile $dir,'bbb');
712 ok open(my $fh, '>', $tmpfilenam), '&rename';
715 test_proto 'ref', [], 'ARRAY';
719 my $oncer = sub { "a" =~ m?a? };
722 ok &$oncer, '&reset with no args';
727 ::lis [$b,$banana],[(undef)x2], '1-arg &reset';
730 test_proto 'reverse';
732 is &myreverse('reward'), 'drawer', '&reverse';
733 lis [&myreverse(qw 'dog bites man')], [qw 'man bites dog'],
734 '&reverse in list context';
736 test_proto 'rewinddir';
740 is &myrindex("foffooo","o",2),1,'&rindex';
741 lis [&myrindex("foffooo","o",2)],[1],'&rindex in list context';
742 is &myrindex("foffooo","o"),6,'&rindex with 2 args';
748 is &myscalar(3), 3, '&scalar';
749 lis [&myscalar(3)], [3], '&scalar in list cx';
755 open my $fh, "<", \"misled" or die $!;
757 is <$fh>, 'sled', '&seek in action';
760 test_proto 'seekdir';
762 # Can’t test_proto, as it has none
764 *myselect = \&CORE::select;
765 is defined prototype &myselect, defined prototype "CORE::select",
766 'prototype of &select (or lack thereof)';
767 is &myselect, select, '&select with no args';
770 is &myselect(my $fh), $prev, '&select($arg) retval';
771 is lc ref $fh, 'glob', '&select autovivifies';
772 is select=~s/\*//rug, (*$fh."")=~s/\*//rug, '&select selects';
775 eval { &myselect(1,2) };
776 like $@, qr/^Not enough arguments for select system call at /,
777 ,'&myselect($two,$args)';
778 eval { &myselect(1,2,3) };
779 like $@, qr/^Not enough arguments for select system call at /,
780 ,'&myselect($with,$three,$args)';
781 eval { &myselect(1,2,3,4,5) };
782 like $@, qr/^Too many arguments for select system call at /,
783 ,'&myselect($a,$total,$of,$five,$args)';
784 &myselect((undef)x3,.25);
785 # Just have to assume that worked. :-) If we get here, at least it didn’t
788 test_proto "sem$_" for qw "ctl get op";
792 test_proto "set$_" for qw '
796 test_proto 'setpgrp';
798 eval { &mysetpgrp( 0) };
799 pass "&setpgrp with one argument";
801 pass "&setpgrp with no arguments";
803 test_proto "set$_" for qw '
804 priority protoent pwent servent sockopt
807 test_proto "shm$_" for qw "ctl get read write";
808 test_proto 'shutdown';
811 test_proto "socket$_" for "", "pair";
813 test_proto 'sprintf';
815 is &mysprintf("%x", 65), '41', '&sprintf';
816 lis [&mysprintf("%x", '65')], ['41'], '&sprintf in list context';
818 test_proto 'sqrt', 4, 2;
824 pass '&srand with no args does not crash';
831 is &mysubstr($_, 1, 1, "d"), 'b', '4-arg &substr';
832 is $_, 'adc', 'what 4-arg &substr does';
833 is &mysubstr("abc", 1, 1), 'b', '3-arg &substr';
834 is &mysubstr("abc", 1), 'bc', '2-arg &substr';
835 &mysubstr($_, 1) = 'long';
836 is $_, 'along', 'lvalue &substr';
838 test_proto 'symlink';
839 test_proto 'syscall';
841 test_proto 'sysopen';
844 &mysysopen(my $fh, 'test.pl', 0);
845 pass '&sysopen does not crash with 3 args';
846 ok $fh, 'sysopen autovivifies';
849 test_proto 'sysread';
850 test_proto 'sysseek';
851 test_proto 'syswrite';
856 open my $fh, "test.pl" or die "Cannot open test.pl";
858 is &mytell(), tell($fh), '&tell with no args';
859 is &mytell($fh), tell($fh), '&tell with an arg';
862 test_proto 'telldir';
870 sub TIESCALAR { bless[] }
871 sub FETCH { ++$fetches }
874 my $obj = &mytie(\$tied, 'tier');
875 is &mytied(\$tied), $obj, '&tie and &tied retvals';
877 is $fetches, 1, '&tie actually ties';
878 &CORE::untie(\$tied);
880 is $fetches, 1, '&untie unties';
885 like &mytime, qr/^\d+\z/, '&time in scalar context';
886 like join('-', &mytime), qr/^\d+\z/, '&time in list context';
890 like &mytimes, qr/^[\d.]+\z/, '× in scalar context';
891 like join('-',&mytimes), qr/^[\d.]+-[\d.]+-[\d.]+-[\d.]+\z/,
892 '× in list context';
894 test_proto 'uc', 'aa', 'AA';
895 test_proto 'ucfirst', 'aa', "Aa";
899 is &myumask, umask, '&umask with no args';
903 is &myundef(), undef, '&undef returns undef';
904 lis [&myundef()], [undef], '&undef returns undef in list cx';
905 lis [&myundef(\$_)], [undef], '&undef(...) returns undef in list cx';
906 is \&myundef(), \undef, '&undef returns the right undef';
907 $_ = 'anserine questions';
909 is $_, undef, '&undef(\$_) undefines $_';
912 is @_, 0, '&undef(\@_) undefines @_';
915 ok !%_, '&undef(\%_) undefines %_';
916 &myundef(\&utf8::valid); # nobody should be using this :-)
917 ok !defined &utf8::valid, '&undef(\&foo) undefines &foo';
920 is *_{ARRAY}, undef, '@_=\*_, &undef undefines *_';
923 is *_{ARRAY}, undef, '&undef(\*_) undefines *_';
924 (&myundef(), @_) = 1..10;
925 lis \@_, [2..10], 'list assignment to &undef()';
926 ok !defined undef, 'list assignment to &undef() does not affect undef';
932 is &myunpack("H*"), '61626364', '&unpack with one arg';
933 is &myunpack("H*", "bcde"), '62636465', '&unpack with two arg';
936 test_proto 'untie'; # behaviour already tested along with tie(d)
940 is &myutime(undef,undef), 0, '&utime';
941 lis [&myutime(undef,undef)], [0], '&utime in list context';
945 is &myvec("foo", 0, 4), 6, '&vec';
946 lis [&myvec("foo", 0, 4)], [6], '&vec in list context';
949 is $tmp, "goo", 'lvalue &vec';
952 test_proto 'waitpid';
954 test_proto 'wantarray';
958 $context = qw[void scalar list][&mywantarray + defined mywantarray()]
961 is $context, 'list', '&wantarray with caller in list context';
963 is($context, 'scalar', '&wantarray with caller in scalar context');
965 is($context, 'void', '&wantarray with caller in void context');
966 lis [&mywantarray],[wantarray], '&wantarray itself in list context';
971 local $SIG{__WARN__} = sub { $w = shift };
972 is &mywarn('a'), 1, '&warn retval';
973 is $w, "a at " . __FILE__ . " line " . (__LINE__-1) . ".\n", 'warning';
974 lis [&mywarn()], [1], '&warn retval in list context';
980 like $@, qr'^Undefined format "STDOUT" called',
981 "&write without arguments can handle the null";
983 # This is just a check to make sure we have tested everything. If we
984 # haven’t, then either the sub needs to be tested or the list in
988 require File::Spec::Functions;
990 File::Spec::Functions::catfile(
991 File::Spec::Functions::updir,'regen','keywords.pl'
993 open my $kh, $keywords_file
994 or die "$0 cannot open $keywords_file: $!";
996 if (m?__END__?..${\0} and /^[-+](.*)/) {
999 $word =~ /^(?:s(?:tate|ort|ay|ub)?|d(?:ef
1000 ault|ump|o)|p(?:rintf?|ackag
1001 e)|e(?:ls(?:if|e)|val|q)|g(?:[et]|iven|oto
1002 |rep)|u(?:n(?:less|til)|se)|l(?:(?:as)?t|ocal|e)|re
1003 (?:quire|turn|do)|__(?:DATA|END)__|for(?:each|mat)?|(?:
1004 AUTOLOA|EN)D|n(?:e(?:xt)?|o)|C(?:HECK|ORE)|wh(?:ile|en)
1005 |(?:ou?|t)r|m(?:ap|y)?|UNITCHECK|q[qrwx]?|x(?:or)?|DEST
1006 ROY|BEGIN|INIT|and|cmp|if|y)\z/x;
1008 ok exists &{"my$word"}
1009 || (eval{&{"CORE::$word"}}, $@ =~ /cannot be called directly/),
1010 "$word either has been tested or is not ampable";
1015 # Add new tests above this line.
1017 # This test must come last (before the test count test):
1020 last if is_miniperl;
1024 require File::Temp ;
1025 my $dir = File::Temp::tempdir(uc cleanup => 1);
1029 # Make sure that implicit $_ is not applied to mkdir’s second argument.
1032 local $SIG{__WARN__} = sub { ++$warnings };
1034 no warnings 'experimental::lexical_topic';
1036 ok &mymkdir(), '&mkdir';
1037 like <*>, qr/^phoo(.DIR)?\z/i, 'mkdir works with implicit $_';
1039 is $warnings, undef, 'no implicit $_ for second argument to mkdir';
1041 chdir($cwd); # so auto-cleanup can remove $dir
1044 # ------------ END TESTING ----------- #
1046 done_testing $tests;
1050 sub file { &CORE::__FILE__ }
1051 sub line { &CORE::__LINE__ } # 5
1052 sub dier { &CORE::die(@_) } # 6
1054 sub main::pakg { &CORE::__PACKAGE__ }
1056 # Please do not add new tests here.
1059 I wandered lonely as a cloud
1060 That floats on high o’er vales and hills,
1061 And all at once I saw a crowd,
1062 A host of golden daffodils!
1063 Beside the lake, beneath the trees,
1064 Fluttering, dancing, in the breeze.