#!./perl
#
# Contributed by Graham Barr <Graham.Barr@tiuk.ti.com>
#
# So far there are tests for the following prototypes.
# none, () ($) ($@) ($%) ($;$) (&) (&\@) (&@) (%) (\%) (\@)
#
# It is impossible to test every prototype that can be specified, but
# we should test as many as we can.
#
BEGIN {
chdir 't' if -d 't';
}
use strict;
print "1..141\n";
my $i = 1;
my $c = shift;
print '#' x 25,"\n";
print '#' x 25,"\n";
print "not "
}
@_ = qw(a b c d);
my @array;
my %hash;
##
##
##
scalar(@_)
}
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
##
##
##
scalar(@_)
}
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
eval "no_args(1)";
print "not " unless $@;
printf "ok %d\n",$i++;
##
##
##
scalar(@_)
}
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
eval "one_args(1,2)";
print "not " unless $@;
printf "ok %d\n",$i++;
eval "one_args()";
print "not " unless $@;
printf "ok %d\n",$i++;
}
one_a_args(@_);
##
##
##
scalar(@_)
}
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
eval "over_one_args()";
print "not " unless $@;
printf "ok %d\n",$i++;
}
over_one_a_args(@_);
over_one_a_args(@_,1);
over_one_a_args(@_,1,2);
over_one_a_args(@_,@_);
##
##
##
scalar(@_)
}
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
eval "scalar_and_hash()";
print "not " unless $@;
printf "ok %d\n",$i++;
}
scalar_and_hash_a(@_);
scalar_and_hash_a(@_,1);
scalar_and_hash_a(@_,1,2);
scalar_and_hash_a(@_,@_);
##
##
##
scalar(@_)
}
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
printf "ok %d\n",$i++;
eval "one_or_two()";
print "not " unless $@;
printf "ok %d\n",$i++;
eval "one_or_two(1,2,3)";
print "not " unless $@;
printf "ok %d\n",$i++;
}
one_or_two_a(@_);
one_or_two_a(@_,1);
one_or_two_a(@_,@_);
##
##
##
&{$_[0]};
}
eval 'a_sub @array';
##
##
##
&{$_[0]};
}
eval 'a_subx @array';
##
##
##
}
print "\n";
##
##
##
my $sub = shift;
}
print "\n";
##
##
##
}
##
##
##
$_[0]->{'b'} = 2;
}
%hash = ( a => 1);
a_hash_ref %hash;
##
##
##
}
array_ref_plus @array, @more; }
print @array;
my $p;
print "ok ", $i++, "\n";
print "ok ", $i++, "\n";
print "ok ", $i++, "\n";
print "# CORE:Foo => ($p), \$@ => `$@'\nnot "
print "ok ", $i++, "\n";
# correctly note too-short parameter lists that don't end with '$',
# a possible regression.
print "ok ", $i++, "\n";
print "ok ", $i++, "\n";
sub X::foo3;
print "ok ", $i++, "\n";
print "ok ", $i++, "\n";
# test if the (*) prototype allows barewords, constants, scalar expressions,
# globs and globrefs (just as CORE::open() does), all under stricture
print "ok $i - star FOO\n";
}; $i++;
print "ok $i - star(FOO)\n";
}); $i++;
}; $i++;
}); $i++;
print "ok $i - star \$star\n";
}; $i++;
print "ok $i - star(\$star)\n";
}); $i++;
print "ok $i - star *FOO\n";
}; $i++;
print "ok $i - star(*FOO)\n";
}); $i++;
print "ok $i - star \\*FOO\n";
}; $i++;
print "ok $i - star(\\*FOO)\n";
}); $i++;
print "ok $i - star2 FOO, BAR\n";
}; $i++;
print "ok $i - star2(Bar::BAZ, FOO)\n"
}); $i++;
print "ok $i - star2 BAR(), FOO\n"
}; $i++;
print "ok $i - star2(FOO, BAR())\n";
}); $i++;
}; $i++;
}); $i++;
print "ok $i - star2 \$star, \$star\n";
}; $i++;
print "ok $i - star2(\$star, \$star)\n";
}); $i++;
print "ok $i - star2 *FOO, *BAR\n";
}; $i++;
print "ok $i - star2(*FOO, *BAR)\n";
}); $i++;
print "ok $i - star2 \*FOO, \*BAR\n";
}; $i++;
print "ok $i - star2(\*FOO, \*BAR)\n";
}); $i++;
# test scalarref prototype
print "ok $_[1] - sreftest\n";
}
{
}
# test prototypes when they are evaled and there is a syntax error
# Byacc generates the string "syntax error". Bison gives the
# string "parse error".
#
eval $eval;
print "ok ", $i++, "\n";
}
# Not $$;$;$
print "ok ", $i++, "\n";
# recv takes a scalar reference for its second argument
print "ok ", $i++, "\n";
{
my $myvar;
my @myarray;
my %myhash;
local *myglob;
print "ok ", $i++, "\n";
print "ok ", $i++, "\n";
print "ok ", $i++, "\n";
print "ok ", $i++, "\n";
print "ok ", $i++, "\n";
print "ok ", $i++, "\n";
print "ok ", $i++, "\n";
print "ok ", $i++, "\n";
print "ok ", $i++, "\n";
print "ok ", $i++, "\n";
}
# check that obviously bad prototypes are getting warnings
{
eval 'sub badproto (@bar) { 1; }';
print "ok ", $i++, "\n";
eval 'sub badproto2 (bar) { 1; }';
print "ok ", $i++, "\n";
eval 'sub badproto3 (&$bar$@) { 1; }';
print "ok ", $i++, "\n";
eval 'sub badproto4 (@ $b ar) { 1; }';
print "ok ", $i++, "\n";
}
# make sure whitespace in prototypes works
eval "sub good (\$\t\$\n\$) { 1; }";
print "not " if $@;
print "ok ", $i++, "\n";
eval 'sub bug (\[%@]) { } my $array = [0 .. 1]; bug %$array;';
print "ok ", $i++, " # TODO Ought to fail, doesn't in 5.8.2\n";