3 # Contributed by Graham Barr <Graham.Barr@tiuk.ti.com>
5 # So far there are tests for the following prototypes.
6 # none, () ($) ($@) ($%) ($;$) (&) (&\@) (&@) (%) (\%) (\@)
8 # It is impossible to test every prototype that can be specified, but
9 # we should test as many as we can.
17 # We need this, as in places we're testing the interaction of prototypes with
26 my $p = prototype(shift);
28 my $what = defined $c ? '(' . $p . ')' : 'no prototype';
30 print '# Testing ',$what,"\n";
33 if((defined($p) && defined($c) && $p ne $c)
34 || (defined($p) != defined($c)));
35 printf "ok %d\n",$i++;
46 testing \&no_proto, undef;
49 print "# \@_ = (",join(",",@_),")\n";
53 print "not " unless 0 == no_proto();
54 printf "ok %d\n",$i++;
56 print "not " unless 1 == no_proto(5);
57 printf "ok %d\n",$i++;
59 print "not " unless 4 == &no_proto;
60 printf "ok %d\n",$i++;
62 print "not " unless 1 == no_proto +6;
63 printf "ok %d\n",$i++;
65 print "not " unless 4 == no_proto(@_);
66 printf "ok %d\n",$i++;
73 testing \&no_args, '';
76 print "# \@_ = (",join(",",@_),")\n";
80 print "not " unless 0 == no_args();
81 printf "ok %d\n",$i++;
83 print "not " unless 0 == no_args;
84 printf "ok %d\n",$i++;
86 print "not " unless 5 == no_args +5;
87 printf "ok %d\n",$i++;
89 print "not " unless 4 == &no_args;
90 printf "ok %d\n",$i++;
92 print "not " unless 2 == &no_args(1,2);
93 printf "ok %d\n",$i++;
96 print "not " unless $@;
97 printf "ok %d\n",$i++;
103 testing \&one_args, '$';
106 print "# \@_ = (",join(",",@_),")\n";
110 print "not " unless 1 == one_args(1);
111 printf "ok %d\n",$i++;
113 print "not " unless 1 == one_args +5;
114 printf "ok %d\n",$i++;
116 print "not " unless 4 == &one_args;
117 printf "ok %d\n",$i++;
119 print "not " unless 2 == &one_args(1,2);
120 printf "ok %d\n",$i++;
122 eval "one_args(1,2)";
123 print "not " unless $@;
124 printf "ok %d\n",$i++;
127 print "not " unless $@;
128 printf "ok %d\n",$i++;
131 print "# \@_ = (",join(",",@_),")\n";
132 print "not " unless @_ == 1 && $_[0] == 4;
133 printf "ok %d\n",$i++;
142 testing \&over_one_args, '$@';
144 sub over_one_args ($@) {
145 print "# \@_ = (",join(",",@_),")\n";
149 print "not " unless 1 == over_one_args(1);
150 printf "ok %d\n",$i++;
152 print "not " unless 2 == over_one_args(1,2);
153 printf "ok %d\n",$i++;
155 print "not " unless 1 == over_one_args +5;
156 printf "ok %d\n",$i++;
158 print "not " unless 4 == &over_one_args;
159 printf "ok %d\n",$i++;
161 print "not " unless 2 == &over_one_args(1,2);
162 printf "ok %d\n",$i++;
164 print "not " unless 5 == &over_one_args(1,@_);
165 printf "ok %d\n",$i++;
167 eval "over_one_args()";
168 print "not " unless $@;
169 printf "ok %d\n",$i++;
171 sub over_one_a_args ($@) {
172 print "# \@_ = (",join(",",@_),")\n";
173 print "not " unless @_ >= 1 && $_[0] == 4;
174 printf "ok %d\n",$i++;
178 over_one_a_args(@_,1);
179 over_one_a_args(@_,1,2);
180 over_one_a_args(@_,@_);
186 testing \&scalar_and_hash, '$%';
188 sub scalar_and_hash ($%) {
189 print "# \@_ = (",join(",",@_),")\n";
193 print "not " unless 1 == scalar_and_hash(1);
194 printf "ok %d\n",$i++;
196 print "not " unless 3 == scalar_and_hash(1,2,3);
197 printf "ok %d\n",$i++;
199 print "not " unless 1 == scalar_and_hash +5;
200 printf "ok %d\n",$i++;
202 print "not " unless 4 == &scalar_and_hash;
203 printf "ok %d\n",$i++;
205 print "not " unless 2 == &scalar_and_hash(1,2);
206 printf "ok %d\n",$i++;
208 print "not " unless 5 == &scalar_and_hash(1,@_);
209 printf "ok %d\n",$i++;
211 eval "scalar_and_hash()";
212 print "not " unless $@;
213 printf "ok %d\n",$i++;
215 sub scalar_and_hash_a ($@) {
216 print "# \@_ = (",join(",",@_),")\n";
217 print "not " unless @_ >= 1 && $_[0] == 4;
218 printf "ok %d\n",$i++;
221 scalar_and_hash_a(@_);
222 scalar_and_hash_a(@_,1);
223 scalar_and_hash_a(@_,1,2);
224 scalar_and_hash_a(@_,@_);
230 testing \&one_or_two, '$;$';
232 sub one_or_two ($;$) {
233 print "# \@_ = (",join(",",@_),")\n";
237 print "not " unless 1 == one_or_two(1);
238 printf "ok %d\n",$i++;
240 print "not " unless 2 == one_or_two(1,3);
241 printf "ok %d\n",$i++;
243 print "not " unless 1 == one_or_two +5;
244 printf "ok %d\n",$i++;
246 print "not " unless 4 == &one_or_two;
247 printf "ok %d\n",$i++;
249 print "not " unless 3 == &one_or_two(1,2,3);
250 printf "ok %d\n",$i++;
252 print "not " unless 5 == &one_or_two(1,@_);
253 printf "ok %d\n",$i++;
256 print "not " unless $@;
257 printf "ok %d\n",$i++;
259 eval "one_or_two(1,2,3)";
260 print "not " unless $@;
261 printf "ok %d\n",$i++;
263 sub one_or_two_a ($;$) {
264 print "# \@_ = (",join(",",@_),")\n";
265 print "not " unless @_ >= 1 && $_[0] == 4;
266 printf "ok %d\n",$i++;
277 testing \&a_sub, '&';
280 print "# \@_ = (",join(",",@_),")\n";
281 return unless defined $_[0];
285 sub tmp_sub_1 { printf "ok %d\n",$i++ }
287 a_sub { printf "ok %d\n",$i++ };
291 @array = ( \&tmp_sub_1 );
293 print "not " unless $@;
294 printf "ok %d\n",$i++;
295 eval 'a_sub \@array';
296 print "not " unless $@ =~ /Type of arg/;
297 printf "ok %d\n",$i++;
299 print "not " unless $@ =~ /Type of arg/;
300 printf "ok %d\n",$i++;
301 eval 'a_sub \$scalar';
302 print "not " unless $@ =~ /Type of arg/;
303 printf "ok %d\n",$i++;
304 eval 'a_sub \($list, %of, @refs)';
305 print "not " unless $@ =~ /Type of arg/;
306 printf "ok %d\n",$i++;
309 printf "ok %d\n",$i++;
315 testing \&a_subx, '\&';
318 print "# \@_ = (",join(",",@_),")\n";
322 sub tmp_sub_2 { printf "ok %d\n",$i++ }
325 @array = ( \&tmp_sub_2 );
326 eval 'a_subx @array';
327 print "not " unless $@;
328 printf "ok %d\n",$i++;
330 qr/Type of arg 1 to .* must be subroutine \(not subroutine entry\)/;
331 eval 'a_subx &tmp_sub_2()';
332 print "not " unless $@ =~ $bad;
333 printf "ok %d - \\& prohibits &foo()\n",$i++;
334 eval 'a_subx tmp_sub_2()';
335 print "not " unless $@ =~ $bad;
336 printf "ok %d - \\& prohibits foo()\n",$i++;
337 eval 'a_subx tmp_sub_2';
338 print "not " unless $@ =~ $bad;
339 printf "ok %d - \\& prohibits foo where foo is an existing sub\n",$i++;
345 testing \&sub_aref, '&\@';
348 print "# \@_ = (",join(",",@_),")\n";
349 my($sub,$array) = @_;
350 print "not " unless @_ == 2 && @{$array} == 4;
351 print map { &{$sub}($_) } @{$array}
354 @array = (qw(O K)," ", $i++);
355 sub_aref { lc shift } @array;
362 testing \&sub_array, '&@';
365 print "# \@_ = (",join(",",@_),")\n";
366 print "not " unless @_ == 5;
368 print map { &{$sub}($_) } @_
371 @array = (qw(O K)," ", $i++);
372 sub_array { lc shift } @array;
373 sub_array { lc shift } ('O', 'K', ' ', $i++);
380 testing \&a_hash, '%';
383 print "# \@_ = (",join(",",@_),")\n";
387 print "not " unless 1 == a_hash 'a';
388 printf "ok %d\n",$i++;
390 print "not " unless 2 == a_hash 'a','b';
391 printf "ok %d\n",$i++;
397 testing \&a_hash_ref, '\%';
399 sub a_hash_ref (\%) {
400 print "# \@_ = (",join(",",@_),")\n";
401 print "not " unless ref($_[0]) && $_[0]->{'a'};
402 printf "ok %d\n",$i++;
408 print "not " unless $hash{'b'} == 2;
409 printf "ok %d\n",$i++;
413 print "not " unless $hash{'b'} == 2;
414 printf "ok %d\n",$i++;
420 testing \&array_ref_plus, '\@@';
422 sub array_ref_plus (\@@) {
423 print "# \@_ = (",join(",",@_),")\n";
424 print "not " unless @_ == 2 && ref($_[0]) && 1 == @{$_[0]} && $_[1] eq 'x';
425 printf "ok %d\n",$i++;
426 @{$_[0]} = (qw(ok)," ",$i++,"\n");
431 array_ref_plus @array, @more; }
432 print "not " unless @array == 4;
437 array_ref_plus +(@array), @more; }
438 print "not " unless @array == 4;
446 print "not " if defined prototype('CORE::print');
447 print "ok ", $i++, "\n";
449 print "not " if defined prototype('CORE::system');
450 print "ok ", $i++, "\n";
452 print "# CORE::open => ($p)\nnot " if ($p = prototype('CORE::open')) ne '*;$@';
453 print "ok ", $i++, "\n";
455 print "# CORE::Foo => ($p), \$@ => '$@'\nnot "
456 if defined ($p = eval { prototype('CORE::Foo') or 1 }) or $@ !~ /^Can't find an opnumber/;
457 print "ok ", $i++, "\n";
459 eval { prototype("CORE::a\0b") };
460 print "# CORE::a\\0b: \$@ => '$@'\nnot "
461 if $@ !~ /^Can't find an opnumber for "a\0b"/;
462 print "ok ", $i++, "\n";
464 eval { prototype("CORE::\x{100}") };
465 print "# CORE::\\x{100}: => ($p), \$@ => '$@'\nnot "
466 if $@ !~ /^Can't find an opnumber for "\x{100}"/;
467 print "ok ", $i++, "\n";
469 "CORE::Foo" =~ /(.*)/;
470 print "# \$1 containing CORE::Foo => ($p), \$@ => '$@'\nnot "
471 if defined ($p = eval { prototype($1) or 1 })
472 or $@ !~ /^Can't find an opnumber/;
473 print "ok ", $i++, " - \$1 containing CORE::Foo\n";
475 # correctly note too-short parameter lists that don't end with '$',
476 # a possible regression.
480 print "not " unless $@ =~ /^Not enough/;
481 print "ok ", $i++, "\n";
485 print "not " unless $@ =~ /^Not enough/;
486 print "ok ", $i++, "\n";
489 *X::foo3 = sub {'ok'};
490 print "# $@not " unless eval {X->foo3} eq 'ok';
491 print "ok ", $i++, "\n";
494 *X::foo4 = sub ($) {'ok'};
495 print "not " unless X->foo4 eq 'ok';
496 print "ok ", $i++, "\n";
498 # test if the (*) prototype allows barewords, constants, scalar expressions,
499 # globs and globrefs (just as CORE::open() does), all under stricture
500 sub star (*&) { &{$_[1]} }
501 sub star2 (**&) { &{$_[2]} }
503 sub Bar::BAZ { "quuz" }
506 print "not " unless $_[0] eq 'FOO';
507 print "ok $i - star FOO\n";
510 print "not " unless $_[0] eq 'FOO';
511 print "ok $i - star(FOO)\n";
514 print "not " unless $_[0] eq 'FOO';
515 print qq/ok $i - star "FOO"\n/;
518 print "not " unless $_[0] eq 'FOO';
519 print qq/ok $i - star("FOO")\n/;
522 print "not " unless $_[0] eq 'FOO';
523 print "ok $i - star \$star\n";
526 print "not " unless $_[0] eq 'FOO';
527 print "ok $i - star(\$star)\n";
530 print "not " unless $_[0] eq \*FOO;
531 print "ok $i - star *FOO\n";
534 print "not " unless $_[0] eq \*FOO;
535 print "ok $i - star(*FOO)\n";
538 print "not " unless $_[0] eq \*FOO;
539 print "ok $i - star \\*FOO\n";
542 print "not " unless $_[0] eq \*FOO;
543 print "ok $i - star(\\*FOO)\n";
545 star2 FOO, BAR, sub {
546 print "not " unless $_[0] eq 'FOO' and $_[1] eq 'quux';
547 print "ok $i - star2 FOO, BAR\n";
549 star2(Bar::BAZ, FOO, sub {
550 print "not " unless $_[0] eq 'quuz' and $_[1] eq 'FOO';
551 print "ok $i - star2(Bar::BAZ, FOO)\n"
553 star2 BAR(), FOO, sub {
554 print "not " unless $_[0] eq 'quux' and $_[1] eq 'FOO';
555 print "ok $i - star2 BAR(), FOO\n"
557 star2(FOO, BAR(), sub {
558 print "not " unless $_[0] eq 'FOO' and $_[1] eq 'quux';
559 print "ok $i - star2(FOO, BAR())\n";
561 star2 "FOO", "BAR", sub {
562 print "not " unless $_[0] eq 'FOO' and $_[1] eq 'BAR';
563 print qq/ok $i - star2 "FOO", "BAR"\n/;
565 star2("FOO", "BAR", sub {
566 print "not " unless $_[0] eq 'FOO' and $_[1] eq 'BAR';
567 print qq/ok $i - star2("FOO", "BAR")\n/;
569 star2 $star, $star, sub {
570 print "not " unless $_[0] eq 'FOO' and $_[1] eq 'FOO';
571 print "ok $i - star2 \$star, \$star\n";
573 star2($star, $star, sub {
574 print "not " unless $_[0] eq 'FOO' and $_[1] eq 'FOO';
575 print "ok $i - star2(\$star, \$star)\n";
577 star2 *FOO, *BAR, sub {
578 print "not " unless $_[0] eq \*FOO and $_[1] eq \*BAR;
579 print "ok $i - star2 *FOO, *BAR\n";
581 star2(*FOO, *BAR, sub {
582 print "not " unless $_[0] eq \*FOO and $_[1] eq \*BAR;
583 print "ok $i - star2(*FOO, *BAR)\n";
585 star2 \*FOO, \*BAR, sub {
587 print "not " unless $_[0] eq \*{'FOO'} and $_[1] eq \*{'BAR'};
588 print "ok $i - star2 \*FOO, \*BAR\n";
590 star2(\*FOO, \*BAR, sub {
592 print "not " unless $_[0] eq \*{'FOO'} and $_[1] eq \*{'BAR'};
593 print "ok $i - star2(\*FOO, \*BAR)\n";
597 # Test that multiple semicolons are treated as one with *
599 sub star4( ; ; ; ; *){}
600 print "not " unless eval 'star3 STDERR; 1';
601 print "ok ", $i++, " star3 STDERR\n";
602 print "not " unless eval 'star4 STDERR; 1';
603 print "ok ", $i++, " star4 STDERR\n";
606 # Test that prototype binding is late
607 print "not " unless eval 'sub l564($){ l564(); } 1';
608 print "ok ", $i++, " prototype checking not done within initial definition\n";
609 print "not " if eval 'sub l566($); sub l566($){ l566(); } 1';
610 print "ok ", $i++, " prototype checking done if sub pre-declared\n";
612 # test scalarref prototype
614 print "not " unless ref $_[0];
615 print "ok $_[1] - sreftest\n";
619 sreftest my $sref, $i++;
620 sreftest($helem{$i}, $i++);
621 sreftest $aelem[0], $i++;
622 sreftest sub { [0] }->()[0], $i++;
623 sreftest my $a = 'quidgley', $i++;
624 print "not " if eval 'return 1; sreftest(3+4)';
625 print "ok ", $i++, ' - \$ with invalid argument', "\n";
630 print "not " unless @_ == 3 && ref $_[0] eq $_[1];
631 print "ok $_[2] - non container test\n";
633 sub quietlazy (+) { return shift(@_) }
635 sub list_or_scalar { wantarray ? (1..10) : [] }
637 my @multiarray = ("a".."z");
638 my %bighash = @multiarray;
639 lazy(\@multiarray, 'ARRAY', $i++);
640 lazy(\%bighash, 'HASH', $i++);
641 lazy({}, 'HASH', $i++);
642 lazy(give_aref, 'ARRAY', $i++);
643 lazy(3, '', $i++); # allowed by prototype, even if runtime error
644 lazy(list_or_scalar, 'ARRAY', $i++); # propagate scalar context
647 # test prototypes when they are evaled and there is a syntax error
648 # Byacc generates the string "syntax error". Bison gives the
649 # string "parse error".
651 for my $p ( "", qw{ () ($) ($@) ($%) ($;$) (&) (&\@) (&@) (%) (\%) (\@) } ) {
653 local $SIG{__WARN__} = sub {
654 my $thiswarn = join("",@_);
655 return if $thiswarn =~ /^Prototype mismatch: sub main::evaled_subroutine/;
658 my $eval = "sub evaled_subroutine $p { &void *; }";
660 print "# eval[$eval]\nnot " unless $@ && $@ =~ /(parse|syntax) error/i;
661 print "ok ", $i++, "\n";
663 print "ok ", $i++, "\n";
665 print "not ok ", $i++, "# $warn \n";
673 sub mysub { print "not calling mysub I hope\n" }
676 sub myref (\[$@%&*]) { print "# $_[0]\n"; return "$_[0]" }
678 print "not " unless myref($myvar) =~ /^SCALAR\(/;
679 print "ok ", $i++, "\n";
680 print "not " unless myref($myvar=7) =~ /^SCALAR\(/;
681 print "ok ", $i++, "\n";
682 print "not " unless myref(@myarray) =~ /^ARRAY\(/;
683 print "ok ", $i++, "\n";
684 print "not " unless myref(%myhash) =~ /^HASH\(/;
685 print "ok ", $i++, "\n";
686 print "not " unless myref(&mysub) =~ /^CODE\(/;
687 print "ok ", $i++, "\n";
688 print "not " unless myref(*myglob) =~ /^GLOB\(/;
689 print "ok ", $i++, "\n";
691 eval q/sub multi1 (\[%@]) { 1 } multi1 $myvar;/;
693 unless $@ =~ /Type of arg 1 to main::multi1 must be one of \[%\@\] /;
694 print "ok ", $i++, "\n";
695 eval q/sub multi2 (\[$*&]) { 1 } multi2 @myarray;/;
697 unless $@ =~ /Type of arg 1 to main::multi2 must be one of \[\$\*&\] /;
698 print "ok ", $i++, "\n";
699 eval q/sub multi3 (\[$@]) { 1 } multi3 %myhash;/;
701 unless $@ =~ /Type of arg 1 to main::multi3 must be one of \[\$\@\] /;
702 print "ok ", $i++, "\n";
703 eval q/sub multi4 ($\[%]) { 1 } multi4 1, &mysub;/;
705 unless $@ =~ /Type of arg 2 to main::multi4 must be one of \[%\] /;
706 print "ok ", $i++, "\n";
707 eval q/sub multi5 (\[$@]$) { 1 } multi5 *myglob;/;
709 unless $@ =~ /Type of arg 1 to main::multi5 must be one of \[\$\@\] /
710 && $@ =~ /Not enough arguments/;
711 print "ok ", $i++, "\n";
714 # check that obviously bad prototypes are getting warnings
718 local $SIG{__WARN__} = sub { $warn .= join("",@_) };
720 eval 'sub badproto (@bar) { 1; }';
721 print "not " unless $warn =~ /Illegal character in prototype for main::badproto : \@bar/;
722 print "ok ", $i++, " checking badproto - (\@bar)\n";
724 eval 'sub badproto2 (bar) { 1; }';
725 print "not " unless $warn =~ /Illegal character in prototype for main::badproto2 : bar/;
726 print "ok ", $i++, " checking badproto2 - (bar)\n";
728 eval 'sub badproto3 (&$bar$@) { 1; }';
729 print "not " unless $warn =~ /Illegal character in prototype for main::badproto3 : &\$bar\$\@/;
730 print "ok ", $i++, " checking badproto3 - (&\$bar\$\@)\n";
732 eval 'sub badproto4 (@ $b ar) { 1; }';
733 # This one emits two warnings
734 print "not " unless $warn =~ /Illegal character in prototype for main::badproto4 : \@ \$b ar/;
735 print "ok ", $i++, " checking badproto4 - (\@ \$b ar) - illegal character\n";
736 print "not " unless $warn =~ /Prototype after '\@' for main::badproto4 : \@ \$b ar/;
737 print "ok ", $i++, " checking badproto4 - (\@ \$b ar) - prototype after '\@'\n";
739 eval 'sub badproto5 ($_$) { 1; }';
740 print "not " unless $warn =~ /Illegal character after '_' in prototype for main::badproto5 : \$_\$/;
741 print "ok ", $i++, " checking badproto5 - (\$_\$) - illegal character after '_'\n";
742 print "not " if $warn =~ /Illegal character in prototype for main::badproto5 : \$_\$/;
743 print "ok ", $i++, " checking badproto5 - (\$_\$) - but not just illegal character\n";
745 eval 'sub badproto6 (bar_) { 1; }';
746 print "not " unless $warn =~ /Illegal character in prototype for main::badproto6 : bar_/;
747 print "ok ", $i++, " checking badproto6 - (bar_) - illegal character\n";
748 print "not " if $warn =~ /Illegal character after '_' in prototype for main::badproto6 : bar_/;
749 print "ok ", $i++, " checking badproto6 - (bar_) - shouldn't add \"after '_'\"\n";
751 eval 'sub badproto7 (_;bar) { 1; }';
752 print "not " unless $warn =~ /Illegal character in prototype for main::badproto7 : _;bar/;
753 print "ok ", $i++, " checking badproto7 - (_;bar) - illegal character\n";
754 print "not " if $warn =~ /Illegal character after '_' in prototype for main::badproto7 : _;bar/;
755 print "ok ", $i++, " checking badproto7 - (_;bar) - shouldn't add \"after '_'\"\n";
757 eval 'sub badproto8 (_b) { 1; }';
758 print "not " unless $warn =~ /Illegal character after '_' in prototype for main::badproto8 : _b/;
759 print "ok ", $i++, " checking badproto8 - (_b) - illegal character after '_'\n";
760 print "not " unless $warn =~ /Illegal character in prototype for main::badproto8 : _b/;
761 print "ok ", $i++, " checking badproto8 - (_b) - just illegal character\n";
763 eval 'sub badproto9 ([) { 1; }';
764 print "not " unless $warn =~ /Missing '\]' in prototype for main::badproto9 : \[/;
765 print "ok ", $i++, " checking for matching bracket\n";
767 eval 'sub badproto10 ([_]) { 1; }';
768 print "not " if $warn =~ /Missing '\]' in prototype for main::badproto10 : \[/;
769 print "ok ", $i++, " checking badproto10 - ([_]) - shouldn't trigger matching bracket\n";
770 print "not " unless $warn =~ /Illegal character after '_' in prototype for main::badproto10 : \[_\]/;
771 print "ok ", $i++, " checking badproto10 - ([_]) - should trigger after '_' warnings\n";
774 # make sure whitespace in prototypes works
775 eval "sub good (\$\t\$\n\$) { 1; }";
777 print "ok ", $i++, "\n";
781 local $SIG{__WARN__} = sub { $warnings++;};
782 $::{ckproto_test} = ' $ $ ';
783 eval 'sub ckproto_test($$){1;}';
784 print "not " if $warnings;
785 print "ok ", $i++, " Check that ckproto ignores spaces in comparisons\n";
788 # Ought to fail, doesn't in 5.8.1.
789 eval 'sub bug (\[%@]) { } my $array = [0 .. 1]; bug %$array;';
790 print "not " unless $@ =~ /Not a HASH reference/;
791 print "ok ", $i++, "\n";
794 # Test that the following prototypes make subs parse as unary functions:
795 # * \sigil \[...] ;$ ;* ;\sigil ;\[...]
797 # As a special case, make sure that ;;* is treated the same as ;*
799 unless eval 'sub uniproto1 (*) {} uniproto1 $_, 1' or warn $@;
800 print "ok ", $i++, "\n";
802 unless eval 'sub uniproto2 (\$) {} uniproto2 $_, 1' or warn $@;
803 print "ok ", $i++, "\n";
805 unless eval 'sub uniproto3 (\[$%]) {} uniproto3 %_, 1' or warn $@;
806 print "ok ", $i++, "\n";
808 unless eval 'sub uniproto4 (;$) {} uniproto4 $_, 1' or warn $@;
809 print "ok ", $i++, "\n";
811 unless eval 'sub uniproto5 (;*) {} uniproto5 $_, 1' or warn $@;
812 print "ok ", $i++, "\n";
814 unless eval 'sub uniproto6 (;\@) {} uniproto6 @_, 1' or warn $@;
815 print "ok ", $i++, "\n";
817 unless eval 'sub uniproto7 (;\[$%@]) {} uniproto7 @_, 1' or warn $@;
818 print "ok ", $i++, "\n";
820 unless eval 'sub uniproto8 (+) {} uniproto8 $_, 1' or warn $@;
821 print "ok ", $i++, "\n";
823 unless eval 'sub uniproto9 (;+) {} uniproto9 $_, 1' or warn $@;
824 print "ok ", $i++, "\n";
826 unless eval 'sub uniproto10 (;;;*) {} uniproto10 $_, 1' or warn $@;
827 print "ok ", $i++, " - uniproto10 (;;;*)\n";
829 unless eval 'sub uniproto11 ( ; ; ; * ) {} uniproto10 $_, 1' or warn $@;
830 print "ok ", $i++, " - uniproto11 ( ; ; ; *)\n";
832 unless eval 'sub uniproto12 (;;;+) {} uniproto12 $_, 1' or warn $@;
833 print "ok ", $i++, " - uniproto12 (;;;*)\n";
835 unless eval 'sub uniproto13 ( ; ; ; + ) {} uniproto13 $_, 1' or warn $@;
836 print "ok ", $i++, " - uniproto13 ( ; ; ; * )\n";
839 # Test that a trailing semicolon makes a sub have listop precedence
840 sub unilist ($;) { $_[0]+1 }
841 sub unilist2(_;) { $_[0]+1 }
842 sub unilist3(;$;) { $_[0]+1 }
843 print "not " unless (unilist 0 || 5) == 6;
844 print "ok ", $i++, "\n";
845 print "not " unless (unilist2 0 || 5) == 6;
846 print "ok ", $i++, "\n";
847 print "not " unless (unilist3 0 || 5) == 6;
848 print "ok ", $i++, "\n";
851 # Lack of prototype on a subroutine definition should override any prototype
852 # on the declaration.
855 local $SIG{__WARN__} = sub {
856 my $thiswarn = join "",@_;
857 if ($thiswarn =~ /^Prototype mismatch: sub main::z_zwap/) {
858 print 'ok ', $i++, "\n";
860 print 'not ok ', $i++, "\n";
861 print STDERR $thiswarn;
865 eval q{sub z_zwap {return @_}};
868 print "not ok ", $i++, "# $@";
870 print "ok ", $i++, "\n";
875 my @got = eval q{z_zwap(@a)};
878 print "not ok ", $i++, " # $@";
880 print "ok ", $i++, "\n";
883 if ("@got" eq "@a") {
884 print "ok ", $i++, "\n";
886 print "not ok ", $i++, " # >@got<\n";
890 # [perl #123514] prototype with no arguments
891 $_ = sub ($$$$$$$) {};
892 @_ = (1, 2, 3, prototype(), 4, 5, 6);
893 print "not " unless "@_" eq '1 2 3 $$$$$$$ 4 5 6';
894 print "ok ", $i++, " - [perl #123514] (got @_)\n";