1*0Sstevel@tonic-gate#!./perl 2*0Sstevel@tonic-gate# 3*0Sstevel@tonic-gate# Contributed by Graham Barr <Graham.Barr@tiuk.ti.com> 4*0Sstevel@tonic-gate# 5*0Sstevel@tonic-gate# So far there are tests for the following prototypes. 6*0Sstevel@tonic-gate# none, () ($) ($@) ($%) ($;$) (&) (&\@) (&@) (%) (\%) (\@) 7*0Sstevel@tonic-gate# 8*0Sstevel@tonic-gate# It is impossible to test every prototype that can be specified, but 9*0Sstevel@tonic-gate# we should test as many as we can. 10*0Sstevel@tonic-gate# 11*0Sstevel@tonic-gate 12*0Sstevel@tonic-gateBEGIN { 13*0Sstevel@tonic-gate chdir 't' if -d 't'; 14*0Sstevel@tonic-gate @INC = '../lib'; 15*0Sstevel@tonic-gate} 16*0Sstevel@tonic-gate 17*0Sstevel@tonic-gateuse strict; 18*0Sstevel@tonic-gate 19*0Sstevel@tonic-gateprint "1..141\n"; 20*0Sstevel@tonic-gate 21*0Sstevel@tonic-gatemy $i = 1; 22*0Sstevel@tonic-gate 23*0Sstevel@tonic-gatesub testing (&$) { 24*0Sstevel@tonic-gate my $p = prototype(shift); 25*0Sstevel@tonic-gate my $c = shift; 26*0Sstevel@tonic-gate my $what = defined $c ? '(' . $p . ')' : 'no prototype'; 27*0Sstevel@tonic-gate print '#' x 25,"\n"; 28*0Sstevel@tonic-gate print '# Testing ',$what,"\n"; 29*0Sstevel@tonic-gate print '#' x 25,"\n"; 30*0Sstevel@tonic-gate print "not " 31*0Sstevel@tonic-gate if((defined($p) && defined($c) && $p ne $c) 32*0Sstevel@tonic-gate || (defined($p) != defined($c))); 33*0Sstevel@tonic-gate printf "ok %d\n",$i++; 34*0Sstevel@tonic-gate} 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate@_ = qw(a b c d); 37*0Sstevel@tonic-gatemy @array; 38*0Sstevel@tonic-gatemy %hash; 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate## 41*0Sstevel@tonic-gate## 42*0Sstevel@tonic-gate## 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gatetesting \&no_proto, undef; 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gatesub no_proto { 47*0Sstevel@tonic-gate print "# \@_ = (",join(",",@_),")\n"; 48*0Sstevel@tonic-gate scalar(@_) 49*0Sstevel@tonic-gate} 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gateprint "not " unless 0 == no_proto(); 52*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 53*0Sstevel@tonic-gate 54*0Sstevel@tonic-gateprint "not " unless 1 == no_proto(5); 55*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 56*0Sstevel@tonic-gate 57*0Sstevel@tonic-gateprint "not " unless 4 == &no_proto; 58*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gateprint "not " unless 1 == no_proto +6; 61*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gateprint "not " unless 4 == no_proto(@_); 64*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate## 67*0Sstevel@tonic-gate## 68*0Sstevel@tonic-gate## 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gatetesting \&no_args, ''; 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gatesub no_args () { 74*0Sstevel@tonic-gate print "# \@_ = (",join(",",@_),")\n"; 75*0Sstevel@tonic-gate scalar(@_) 76*0Sstevel@tonic-gate} 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gateprint "not " unless 0 == no_args(); 79*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gateprint "not " unless 0 == no_args; 82*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gateprint "not " unless 5 == no_args +5; 85*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gateprint "not " unless 4 == &no_args; 88*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gateprint "not " unless 2 == &no_args(1,2); 91*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gateeval "no_args(1)"; 94*0Sstevel@tonic-gateprint "not " unless $@; 95*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gate## 98*0Sstevel@tonic-gate## 99*0Sstevel@tonic-gate## 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gatetesting \&one_args, '$'; 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gatesub one_args ($) { 104*0Sstevel@tonic-gate print "# \@_ = (",join(",",@_),")\n"; 105*0Sstevel@tonic-gate scalar(@_) 106*0Sstevel@tonic-gate} 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gateprint "not " unless 1 == one_args(1); 109*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gateprint "not " unless 1 == one_args +5; 112*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 113*0Sstevel@tonic-gate 114*0Sstevel@tonic-gateprint "not " unless 4 == &one_args; 115*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 116*0Sstevel@tonic-gate 117*0Sstevel@tonic-gateprint "not " unless 2 == &one_args(1,2); 118*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gateeval "one_args(1,2)"; 121*0Sstevel@tonic-gateprint "not " unless $@; 122*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 123*0Sstevel@tonic-gate 124*0Sstevel@tonic-gateeval "one_args()"; 125*0Sstevel@tonic-gateprint "not " unless $@; 126*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 127*0Sstevel@tonic-gate 128*0Sstevel@tonic-gatesub one_a_args ($) { 129*0Sstevel@tonic-gate print "# \@_ = (",join(",",@_),")\n"; 130*0Sstevel@tonic-gate print "not " unless @_ == 1 && $_[0] == 4; 131*0Sstevel@tonic-gate printf "ok %d\n",$i++; 132*0Sstevel@tonic-gate} 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gateone_a_args(@_); 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate## 137*0Sstevel@tonic-gate## 138*0Sstevel@tonic-gate## 139*0Sstevel@tonic-gate 140*0Sstevel@tonic-gatetesting \&over_one_args, '$@'; 141*0Sstevel@tonic-gate 142*0Sstevel@tonic-gatesub over_one_args ($@) { 143*0Sstevel@tonic-gate print "# \@_ = (",join(",",@_),")\n"; 144*0Sstevel@tonic-gate scalar(@_) 145*0Sstevel@tonic-gate} 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gateprint "not " unless 1 == over_one_args(1); 148*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gateprint "not " unless 2 == over_one_args(1,2); 151*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gateprint "not " unless 1 == over_one_args +5; 154*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 155*0Sstevel@tonic-gate 156*0Sstevel@tonic-gateprint "not " unless 4 == &over_one_args; 157*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 158*0Sstevel@tonic-gate 159*0Sstevel@tonic-gateprint "not " unless 2 == &over_one_args(1,2); 160*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gateprint "not " unless 5 == &over_one_args(1,@_); 163*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 164*0Sstevel@tonic-gate 165*0Sstevel@tonic-gateeval "over_one_args()"; 166*0Sstevel@tonic-gateprint "not " unless $@; 167*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gatesub over_one_a_args ($@) { 170*0Sstevel@tonic-gate print "# \@_ = (",join(",",@_),")\n"; 171*0Sstevel@tonic-gate print "not " unless @_ >= 1 && $_[0] == 4; 172*0Sstevel@tonic-gate printf "ok %d\n",$i++; 173*0Sstevel@tonic-gate} 174*0Sstevel@tonic-gate 175*0Sstevel@tonic-gateover_one_a_args(@_); 176*0Sstevel@tonic-gateover_one_a_args(@_,1); 177*0Sstevel@tonic-gateover_one_a_args(@_,1,2); 178*0Sstevel@tonic-gateover_one_a_args(@_,@_); 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gate## 181*0Sstevel@tonic-gate## 182*0Sstevel@tonic-gate## 183*0Sstevel@tonic-gate 184*0Sstevel@tonic-gatetesting \&scalar_and_hash, '$%'; 185*0Sstevel@tonic-gate 186*0Sstevel@tonic-gatesub scalar_and_hash ($%) { 187*0Sstevel@tonic-gate print "# \@_ = (",join(",",@_),")\n"; 188*0Sstevel@tonic-gate scalar(@_) 189*0Sstevel@tonic-gate} 190*0Sstevel@tonic-gate 191*0Sstevel@tonic-gateprint "not " unless 1 == scalar_and_hash(1); 192*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 193*0Sstevel@tonic-gate 194*0Sstevel@tonic-gateprint "not " unless 3 == scalar_and_hash(1,2,3); 195*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 196*0Sstevel@tonic-gate 197*0Sstevel@tonic-gateprint "not " unless 1 == scalar_and_hash +5; 198*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 199*0Sstevel@tonic-gate 200*0Sstevel@tonic-gateprint "not " unless 4 == &scalar_and_hash; 201*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 202*0Sstevel@tonic-gate 203*0Sstevel@tonic-gateprint "not " unless 2 == &scalar_and_hash(1,2); 204*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 205*0Sstevel@tonic-gate 206*0Sstevel@tonic-gateprint "not " unless 5 == &scalar_and_hash(1,@_); 207*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 208*0Sstevel@tonic-gate 209*0Sstevel@tonic-gateeval "scalar_and_hash()"; 210*0Sstevel@tonic-gateprint "not " unless $@; 211*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 212*0Sstevel@tonic-gate 213*0Sstevel@tonic-gatesub scalar_and_hash_a ($@) { 214*0Sstevel@tonic-gate print "# \@_ = (",join(",",@_),")\n"; 215*0Sstevel@tonic-gate print "not " unless @_ >= 1 && $_[0] == 4; 216*0Sstevel@tonic-gate printf "ok %d\n",$i++; 217*0Sstevel@tonic-gate} 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gatescalar_and_hash_a(@_); 220*0Sstevel@tonic-gatescalar_and_hash_a(@_,1); 221*0Sstevel@tonic-gatescalar_and_hash_a(@_,1,2); 222*0Sstevel@tonic-gatescalar_and_hash_a(@_,@_); 223*0Sstevel@tonic-gate 224*0Sstevel@tonic-gate## 225*0Sstevel@tonic-gate## 226*0Sstevel@tonic-gate## 227*0Sstevel@tonic-gate 228*0Sstevel@tonic-gatetesting \&one_or_two, '$;$'; 229*0Sstevel@tonic-gate 230*0Sstevel@tonic-gatesub one_or_two ($;$) { 231*0Sstevel@tonic-gate print "# \@_ = (",join(",",@_),")\n"; 232*0Sstevel@tonic-gate scalar(@_) 233*0Sstevel@tonic-gate} 234*0Sstevel@tonic-gate 235*0Sstevel@tonic-gateprint "not " unless 1 == one_or_two(1); 236*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 237*0Sstevel@tonic-gate 238*0Sstevel@tonic-gateprint "not " unless 2 == one_or_two(1,3); 239*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 240*0Sstevel@tonic-gate 241*0Sstevel@tonic-gateprint "not " unless 1 == one_or_two +5; 242*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 243*0Sstevel@tonic-gate 244*0Sstevel@tonic-gateprint "not " unless 4 == &one_or_two; 245*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 246*0Sstevel@tonic-gate 247*0Sstevel@tonic-gateprint "not " unless 3 == &one_or_two(1,2,3); 248*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 249*0Sstevel@tonic-gate 250*0Sstevel@tonic-gateprint "not " unless 5 == &one_or_two(1,@_); 251*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 252*0Sstevel@tonic-gate 253*0Sstevel@tonic-gateeval "one_or_two()"; 254*0Sstevel@tonic-gateprint "not " unless $@; 255*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 256*0Sstevel@tonic-gate 257*0Sstevel@tonic-gateeval "one_or_two(1,2,3)"; 258*0Sstevel@tonic-gateprint "not " unless $@; 259*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 260*0Sstevel@tonic-gate 261*0Sstevel@tonic-gatesub one_or_two_a ($;$) { 262*0Sstevel@tonic-gate print "# \@_ = (",join(",",@_),")\n"; 263*0Sstevel@tonic-gate print "not " unless @_ >= 1 && $_[0] == 4; 264*0Sstevel@tonic-gate printf "ok %d\n",$i++; 265*0Sstevel@tonic-gate} 266*0Sstevel@tonic-gate 267*0Sstevel@tonic-gateone_or_two_a(@_); 268*0Sstevel@tonic-gateone_or_two_a(@_,1); 269*0Sstevel@tonic-gateone_or_two_a(@_,@_); 270*0Sstevel@tonic-gate 271*0Sstevel@tonic-gate## 272*0Sstevel@tonic-gate## 273*0Sstevel@tonic-gate## 274*0Sstevel@tonic-gate 275*0Sstevel@tonic-gatetesting \&a_sub, '&'; 276*0Sstevel@tonic-gate 277*0Sstevel@tonic-gatesub a_sub (&) { 278*0Sstevel@tonic-gate print "# \@_ = (",join(",",@_),")\n"; 279*0Sstevel@tonic-gate &{$_[0]}; 280*0Sstevel@tonic-gate} 281*0Sstevel@tonic-gate 282*0Sstevel@tonic-gatesub tmp_sub_1 { printf "ok %d\n",$i++ } 283*0Sstevel@tonic-gate 284*0Sstevel@tonic-gatea_sub { printf "ok %d\n",$i++ }; 285*0Sstevel@tonic-gatea_sub \&tmp_sub_1; 286*0Sstevel@tonic-gate 287*0Sstevel@tonic-gate@array = ( \&tmp_sub_1 ); 288*0Sstevel@tonic-gateeval 'a_sub @array'; 289*0Sstevel@tonic-gateprint "not " unless $@; 290*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 291*0Sstevel@tonic-gate 292*0Sstevel@tonic-gate## 293*0Sstevel@tonic-gate## 294*0Sstevel@tonic-gate## 295*0Sstevel@tonic-gate 296*0Sstevel@tonic-gatetesting \&a_subx, '\&'; 297*0Sstevel@tonic-gate 298*0Sstevel@tonic-gatesub a_subx (\&) { 299*0Sstevel@tonic-gate print "# \@_ = (",join(",",@_),")\n"; 300*0Sstevel@tonic-gate &{$_[0]}; 301*0Sstevel@tonic-gate} 302*0Sstevel@tonic-gate 303*0Sstevel@tonic-gatesub tmp_sub_2 { printf "ok %d\n",$i++ } 304*0Sstevel@tonic-gatea_subx &tmp_sub_2; 305*0Sstevel@tonic-gate 306*0Sstevel@tonic-gate@array = ( \&tmp_sub_2 ); 307*0Sstevel@tonic-gateeval 'a_subx @array'; 308*0Sstevel@tonic-gateprint "not " unless $@; 309*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 310*0Sstevel@tonic-gate 311*0Sstevel@tonic-gate## 312*0Sstevel@tonic-gate## 313*0Sstevel@tonic-gate## 314*0Sstevel@tonic-gate 315*0Sstevel@tonic-gatetesting \&sub_aref, '&\@'; 316*0Sstevel@tonic-gate 317*0Sstevel@tonic-gatesub sub_aref (&\@) { 318*0Sstevel@tonic-gate print "# \@_ = (",join(",",@_),")\n"; 319*0Sstevel@tonic-gate my($sub,$array) = @_; 320*0Sstevel@tonic-gate print "not " unless @_ == 2 && @{$array} == 4; 321*0Sstevel@tonic-gate print map { &{$sub}($_) } @{$array} 322*0Sstevel@tonic-gate} 323*0Sstevel@tonic-gate 324*0Sstevel@tonic-gate@array = (qw(O K)," ", $i++); 325*0Sstevel@tonic-gatesub_aref { lc shift } @array; 326*0Sstevel@tonic-gateprint "\n"; 327*0Sstevel@tonic-gate 328*0Sstevel@tonic-gate## 329*0Sstevel@tonic-gate## 330*0Sstevel@tonic-gate## 331*0Sstevel@tonic-gate 332*0Sstevel@tonic-gatetesting \&sub_array, '&@'; 333*0Sstevel@tonic-gate 334*0Sstevel@tonic-gatesub sub_array (&@) { 335*0Sstevel@tonic-gate print "# \@_ = (",join(",",@_),")\n"; 336*0Sstevel@tonic-gate print "not " unless @_ == 5; 337*0Sstevel@tonic-gate my $sub = shift; 338*0Sstevel@tonic-gate print map { &{$sub}($_) } @_ 339*0Sstevel@tonic-gate} 340*0Sstevel@tonic-gate 341*0Sstevel@tonic-gate@array = (qw(O K)," ", $i++); 342*0Sstevel@tonic-gatesub_array { lc shift } @array; 343*0Sstevel@tonic-gatesub_array { lc shift } ('O', 'K', ' ', $i++); 344*0Sstevel@tonic-gateprint "\n"; 345*0Sstevel@tonic-gate 346*0Sstevel@tonic-gate## 347*0Sstevel@tonic-gate## 348*0Sstevel@tonic-gate## 349*0Sstevel@tonic-gate 350*0Sstevel@tonic-gatetesting \&a_hash, '%'; 351*0Sstevel@tonic-gate 352*0Sstevel@tonic-gatesub a_hash (%) { 353*0Sstevel@tonic-gate print "# \@_ = (",join(",",@_),")\n"; 354*0Sstevel@tonic-gate scalar(@_); 355*0Sstevel@tonic-gate} 356*0Sstevel@tonic-gate 357*0Sstevel@tonic-gateprint "not " unless 1 == a_hash 'a'; 358*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 359*0Sstevel@tonic-gate 360*0Sstevel@tonic-gateprint "not " unless 2 == a_hash 'a','b'; 361*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 362*0Sstevel@tonic-gate 363*0Sstevel@tonic-gate## 364*0Sstevel@tonic-gate## 365*0Sstevel@tonic-gate## 366*0Sstevel@tonic-gate 367*0Sstevel@tonic-gatetesting \&a_hash_ref, '\%'; 368*0Sstevel@tonic-gate 369*0Sstevel@tonic-gatesub a_hash_ref (\%) { 370*0Sstevel@tonic-gate print "# \@_ = (",join(",",@_),")\n"; 371*0Sstevel@tonic-gate print "not " unless ref($_[0]) && $_[0]->{'a'}; 372*0Sstevel@tonic-gate printf "ok %d\n",$i++; 373*0Sstevel@tonic-gate $_[0]->{'b'} = 2; 374*0Sstevel@tonic-gate} 375*0Sstevel@tonic-gate 376*0Sstevel@tonic-gate%hash = ( a => 1); 377*0Sstevel@tonic-gatea_hash_ref %hash; 378*0Sstevel@tonic-gateprint "not " unless $hash{'b'} == 2; 379*0Sstevel@tonic-gateprintf "ok %d\n",$i++; 380*0Sstevel@tonic-gate 381*0Sstevel@tonic-gate## 382*0Sstevel@tonic-gate## 383*0Sstevel@tonic-gate## 384*0Sstevel@tonic-gate 385*0Sstevel@tonic-gatetesting \&array_ref_plus, '\@@'; 386*0Sstevel@tonic-gate 387*0Sstevel@tonic-gatesub array_ref_plus (\@@) { 388*0Sstevel@tonic-gate print "# \@_ = (",join(",",@_),")\n"; 389*0Sstevel@tonic-gate print "not " unless @_ == 2 && ref($_[0]) && 1 == @{$_[0]} && $_[1] eq 'x'; 390*0Sstevel@tonic-gate printf "ok %d\n",$i++; 391*0Sstevel@tonic-gate @{$_[0]} = (qw(ok)," ",$i++,"\n"); 392*0Sstevel@tonic-gate} 393*0Sstevel@tonic-gate 394*0Sstevel@tonic-gate@array = ('a'); 395*0Sstevel@tonic-gate{ my @more = ('x'); 396*0Sstevel@tonic-gate array_ref_plus @array, @more; } 397*0Sstevel@tonic-gateprint "not " unless @array == 4; 398*0Sstevel@tonic-gateprint @array; 399*0Sstevel@tonic-gate 400*0Sstevel@tonic-gatemy $p; 401*0Sstevel@tonic-gateprint "not " if defined prototype('CORE::print'); 402*0Sstevel@tonic-gateprint "ok ", $i++, "\n"; 403*0Sstevel@tonic-gate 404*0Sstevel@tonic-gateprint "not " if defined prototype('CORE::system'); 405*0Sstevel@tonic-gateprint "ok ", $i++, "\n"; 406*0Sstevel@tonic-gate 407*0Sstevel@tonic-gateprint "# CORE::open => ($p)\nnot " if ($p = prototype('CORE::open')) ne '*;$@'; 408*0Sstevel@tonic-gateprint "ok ", $i++, "\n"; 409*0Sstevel@tonic-gate 410*0Sstevel@tonic-gateprint "# CORE:Foo => ($p), \$@ => `$@'\nnot " 411*0Sstevel@tonic-gate if defined ($p = eval { prototype('CORE::Foo') or 1 }) or $@ !~ /^Can't find an opnumber/; 412*0Sstevel@tonic-gateprint "ok ", $i++, "\n"; 413*0Sstevel@tonic-gate 414*0Sstevel@tonic-gate# correctly note too-short parameter lists that don't end with '$', 415*0Sstevel@tonic-gate# a possible regression. 416*0Sstevel@tonic-gate 417*0Sstevel@tonic-gatesub foo1 ($\@); 418*0Sstevel@tonic-gateeval q{ foo1 "s" }; 419*0Sstevel@tonic-gateprint "not " unless $@ =~ /^Not enough/; 420*0Sstevel@tonic-gateprint "ok ", $i++, "\n"; 421*0Sstevel@tonic-gate 422*0Sstevel@tonic-gatesub foo2 ($\%); 423*0Sstevel@tonic-gateeval q{ foo2 "s" }; 424*0Sstevel@tonic-gateprint "not " unless $@ =~ /^Not enough/; 425*0Sstevel@tonic-gateprint "ok ", $i++, "\n"; 426*0Sstevel@tonic-gate 427*0Sstevel@tonic-gatesub X::foo3; 428*0Sstevel@tonic-gate*X::foo3 = sub {'ok'}; 429*0Sstevel@tonic-gateprint "# $@not " unless eval {X->foo3} eq 'ok'; 430*0Sstevel@tonic-gateprint "ok ", $i++, "\n"; 431*0Sstevel@tonic-gate 432*0Sstevel@tonic-gatesub X::foo4 ($); 433*0Sstevel@tonic-gate*X::foo4 = sub ($) {'ok'}; 434*0Sstevel@tonic-gateprint "not " unless X->foo4 eq 'ok'; 435*0Sstevel@tonic-gateprint "ok ", $i++, "\n"; 436*0Sstevel@tonic-gate 437*0Sstevel@tonic-gate# test if the (*) prototype allows barewords, constants, scalar expressions, 438*0Sstevel@tonic-gate# globs and globrefs (just as CORE::open() does), all under stricture 439*0Sstevel@tonic-gatesub star (*&) { &{$_[1]} } 440*0Sstevel@tonic-gatesub star2 (**&) { &{$_[2]} } 441*0Sstevel@tonic-gatesub BAR { "quux" } 442*0Sstevel@tonic-gatesub Bar::BAZ { "quuz" } 443*0Sstevel@tonic-gatemy $star = 'FOO'; 444*0Sstevel@tonic-gatestar FOO, sub { 445*0Sstevel@tonic-gate print "not " unless $_[0] eq 'FOO'; 446*0Sstevel@tonic-gate print "ok $i - star FOO\n"; 447*0Sstevel@tonic-gate}; $i++; 448*0Sstevel@tonic-gatestar(FOO, sub { 449*0Sstevel@tonic-gate print "not " unless $_[0] eq 'FOO'; 450*0Sstevel@tonic-gate print "ok $i - star(FOO)\n"; 451*0Sstevel@tonic-gate }); $i++; 452*0Sstevel@tonic-gatestar "FOO", sub { 453*0Sstevel@tonic-gate print "not " unless $_[0] eq 'FOO'; 454*0Sstevel@tonic-gate print qq/ok $i - star "FOO"\n/; 455*0Sstevel@tonic-gate}; $i++; 456*0Sstevel@tonic-gatestar("FOO", sub { 457*0Sstevel@tonic-gate print "not " unless $_[0] eq 'FOO'; 458*0Sstevel@tonic-gate print qq/ok $i - star("FOO")\n/; 459*0Sstevel@tonic-gate }); $i++; 460*0Sstevel@tonic-gatestar $star, sub { 461*0Sstevel@tonic-gate print "not " unless $_[0] eq 'FOO'; 462*0Sstevel@tonic-gate print "ok $i - star \$star\n"; 463*0Sstevel@tonic-gate}; $i++; 464*0Sstevel@tonic-gatestar($star, sub { 465*0Sstevel@tonic-gate print "not " unless $_[0] eq 'FOO'; 466*0Sstevel@tonic-gate print "ok $i - star(\$star)\n"; 467*0Sstevel@tonic-gate }); $i++; 468*0Sstevel@tonic-gatestar *FOO, sub { 469*0Sstevel@tonic-gate print "not " unless $_[0] eq \*FOO; 470*0Sstevel@tonic-gate print "ok $i - star *FOO\n"; 471*0Sstevel@tonic-gate}; $i++; 472*0Sstevel@tonic-gatestar(*FOO, sub { 473*0Sstevel@tonic-gate print "not " unless $_[0] eq \*FOO; 474*0Sstevel@tonic-gate print "ok $i - star(*FOO)\n"; 475*0Sstevel@tonic-gate }); $i++; 476*0Sstevel@tonic-gatestar \*FOO, sub { 477*0Sstevel@tonic-gate print "not " unless $_[0] eq \*FOO; 478*0Sstevel@tonic-gate print "ok $i - star \\*FOO\n"; 479*0Sstevel@tonic-gate}; $i++; 480*0Sstevel@tonic-gatestar(\*FOO, sub { 481*0Sstevel@tonic-gate print "not " unless $_[0] eq \*FOO; 482*0Sstevel@tonic-gate print "ok $i - star(\\*FOO)\n"; 483*0Sstevel@tonic-gate }); $i++; 484*0Sstevel@tonic-gatestar2 FOO, BAR, sub { 485*0Sstevel@tonic-gate print "not " unless $_[0] eq 'FOO' and $_[1] eq 'BAR'; 486*0Sstevel@tonic-gate print "ok $i - star2 FOO, BAR\n"; 487*0Sstevel@tonic-gate}; $i++; 488*0Sstevel@tonic-gatestar2(Bar::BAZ, FOO, sub { 489*0Sstevel@tonic-gate print "not " unless $_[0] eq 'Bar::BAZ' and $_[1] eq 'FOO'; 490*0Sstevel@tonic-gate print "ok $i - star2(Bar::BAZ, FOO)\n" 491*0Sstevel@tonic-gate }); $i++; 492*0Sstevel@tonic-gatestar2 BAR(), FOO, sub { 493*0Sstevel@tonic-gate print "not " unless $_[0] eq 'quux' and $_[1] eq 'FOO'; 494*0Sstevel@tonic-gate print "ok $i - star2 BAR(), FOO\n" 495*0Sstevel@tonic-gate}; $i++; 496*0Sstevel@tonic-gatestar2(FOO, BAR(), sub { 497*0Sstevel@tonic-gate print "not " unless $_[0] eq 'FOO' and $_[1] eq 'quux'; 498*0Sstevel@tonic-gate print "ok $i - star2(FOO, BAR())\n"; 499*0Sstevel@tonic-gate }); $i++; 500*0Sstevel@tonic-gatestar2 "FOO", "BAR", sub { 501*0Sstevel@tonic-gate print "not " unless $_[0] eq 'FOO' and $_[1] eq 'BAR'; 502*0Sstevel@tonic-gate print qq/ok $i - star2 "FOO", "BAR"\n/; 503*0Sstevel@tonic-gate}; $i++; 504*0Sstevel@tonic-gatestar2("FOO", "BAR", sub { 505*0Sstevel@tonic-gate print "not " unless $_[0] eq 'FOO' and $_[1] eq 'BAR'; 506*0Sstevel@tonic-gate print qq/ok $i - star2("FOO", "BAR")\n/; 507*0Sstevel@tonic-gate }); $i++; 508*0Sstevel@tonic-gatestar2 $star, $star, sub { 509*0Sstevel@tonic-gate print "not " unless $_[0] eq 'FOO' and $_[1] eq 'FOO'; 510*0Sstevel@tonic-gate print "ok $i - star2 \$star, \$star\n"; 511*0Sstevel@tonic-gate}; $i++; 512*0Sstevel@tonic-gatestar2($star, $star, sub { 513*0Sstevel@tonic-gate print "not " unless $_[0] eq 'FOO' and $_[1] eq 'FOO'; 514*0Sstevel@tonic-gate print "ok $i - star2(\$star, \$star)\n"; 515*0Sstevel@tonic-gate }); $i++; 516*0Sstevel@tonic-gatestar2 *FOO, *BAR, sub { 517*0Sstevel@tonic-gate print "not " unless $_[0] eq \*FOO and $_[1] eq \*BAR; 518*0Sstevel@tonic-gate print "ok $i - star2 *FOO, *BAR\n"; 519*0Sstevel@tonic-gate}; $i++; 520*0Sstevel@tonic-gatestar2(*FOO, *BAR, sub { 521*0Sstevel@tonic-gate print "not " unless $_[0] eq \*FOO and $_[1] eq \*BAR; 522*0Sstevel@tonic-gate print "ok $i - star2(*FOO, *BAR)\n"; 523*0Sstevel@tonic-gate }); $i++; 524*0Sstevel@tonic-gatestar2 \*FOO, \*BAR, sub { 525*0Sstevel@tonic-gate no strict 'refs'; 526*0Sstevel@tonic-gate print "not " unless $_[0] eq \*{'FOO'} and $_[1] eq \*{'BAR'}; 527*0Sstevel@tonic-gate print "ok $i - star2 \*FOO, \*BAR\n"; 528*0Sstevel@tonic-gate}; $i++; 529*0Sstevel@tonic-gatestar2(\*FOO, \*BAR, sub { 530*0Sstevel@tonic-gate no strict 'refs'; 531*0Sstevel@tonic-gate print "not " unless $_[0] eq \*{'FOO'} and $_[1] eq \*{'BAR'}; 532*0Sstevel@tonic-gate print "ok $i - star2(\*FOO, \*BAR)\n"; 533*0Sstevel@tonic-gate }); $i++; 534*0Sstevel@tonic-gate 535*0Sstevel@tonic-gate# test scalarref prototype 536*0Sstevel@tonic-gatesub sreftest (\$$) { 537*0Sstevel@tonic-gate print "not " unless ref $_[0]; 538*0Sstevel@tonic-gate print "ok $_[1] - sreftest\n"; 539*0Sstevel@tonic-gate} 540*0Sstevel@tonic-gate{ 541*0Sstevel@tonic-gate no strict 'vars'; 542*0Sstevel@tonic-gate sreftest my $sref, $i++; 543*0Sstevel@tonic-gate sreftest($helem{$i}, $i++); 544*0Sstevel@tonic-gate sreftest $aelem[0], $i++; 545*0Sstevel@tonic-gate} 546*0Sstevel@tonic-gate 547*0Sstevel@tonic-gate# test prototypes when they are evaled and there is a syntax error 548*0Sstevel@tonic-gate# Byacc generates the string "syntax error". Bison gives the 549*0Sstevel@tonic-gate# string "parse error". 550*0Sstevel@tonic-gate# 551*0Sstevel@tonic-gatefor my $p ( "", qw{ () ($) ($@) ($%) ($;$) (&) (&\@) (&@) (%) (\%) (\@) } ) { 552*0Sstevel@tonic-gate no warnings 'prototype'; 553*0Sstevel@tonic-gate my $eval = "sub evaled_subroutine $p { &void *; }"; 554*0Sstevel@tonic-gate eval $eval; 555*0Sstevel@tonic-gate print "# eval[$eval]\nnot " unless $@ && $@ =~ /(parse|syntax) error/i; 556*0Sstevel@tonic-gate print "ok ", $i++, "\n"; 557*0Sstevel@tonic-gate} 558*0Sstevel@tonic-gate 559*0Sstevel@tonic-gate# Not $$;$;$ 560*0Sstevel@tonic-gateprint "not " unless prototype "CORE::substr" eq '$$;$$'; 561*0Sstevel@tonic-gateprint "ok ", $i++, "\n"; 562*0Sstevel@tonic-gate 563*0Sstevel@tonic-gate# recv takes a scalar reference for its second argument 564*0Sstevel@tonic-gateprint "not " unless prototype "CORE::recv" eq '*\\$$$'; 565*0Sstevel@tonic-gateprint "ok ", $i++, "\n"; 566*0Sstevel@tonic-gate 567*0Sstevel@tonic-gate{ 568*0Sstevel@tonic-gate my $myvar; 569*0Sstevel@tonic-gate my @myarray; 570*0Sstevel@tonic-gate my %myhash; 571*0Sstevel@tonic-gate sub mysub { print "not calling mysub I hope\n" } 572*0Sstevel@tonic-gate local *myglob; 573*0Sstevel@tonic-gate 574*0Sstevel@tonic-gate sub myref (\[$@%&*]) { print "# $_[0]\n"; return "$_[0]" } 575*0Sstevel@tonic-gate 576*0Sstevel@tonic-gate print "not " unless myref($myvar) =~ /^SCALAR\(/; 577*0Sstevel@tonic-gate print "ok ", $i++, "\n"; 578*0Sstevel@tonic-gate print "not " unless myref(@myarray) =~ /^ARRAY\(/; 579*0Sstevel@tonic-gate print "ok ", $i++, "\n"; 580*0Sstevel@tonic-gate print "not " unless myref(%myhash) =~ /^HASH\(/; 581*0Sstevel@tonic-gate print "ok ", $i++, "\n"; 582*0Sstevel@tonic-gate print "not " unless myref(&mysub) =~ /^CODE\(/; 583*0Sstevel@tonic-gate print "ok ", $i++, "\n"; 584*0Sstevel@tonic-gate print "not " unless myref(*myglob) =~ /^GLOB\(/; 585*0Sstevel@tonic-gate print "ok ", $i++, "\n"; 586*0Sstevel@tonic-gate 587*0Sstevel@tonic-gate eval q/sub multi1 (\[%@]) { 1 } multi1 $myvar;/; 588*0Sstevel@tonic-gate print "not " unless $@ =~ /Type of arg 1 to main::multi1 must be one of/; 589*0Sstevel@tonic-gate print "ok ", $i++, "\n"; 590*0Sstevel@tonic-gate eval q/sub multi2 (\[$*&]) { 1 } multi2 @myarray;/; 591*0Sstevel@tonic-gate print "not " unless $@ =~ /Type of arg 1 to main::multi2 must be one of/; 592*0Sstevel@tonic-gate print "ok ", $i++, "\n"; 593*0Sstevel@tonic-gate eval q/sub multi3 (\[$@]) { 1 } multi3 %myhash;/; 594*0Sstevel@tonic-gate print "not " unless $@ =~ /Type of arg 1 to main::multi3 must be one of/; 595*0Sstevel@tonic-gate print "ok ", $i++, "\n"; 596*0Sstevel@tonic-gate eval q/sub multi4 ($\[%]) { 1 } multi4 1, &mysub;/; 597*0Sstevel@tonic-gate print "not " unless $@ =~ /Type of arg 2 to main::multi4 must be one of/; 598*0Sstevel@tonic-gate print "ok ", $i++, "\n"; 599*0Sstevel@tonic-gate eval q/sub multi5 (\[$@]$) { 1 } multi5 *myglob;/; 600*0Sstevel@tonic-gate print "not " unless $@ =~ /Type of arg 1 to main::multi5 must be one of/ 601*0Sstevel@tonic-gate && $@ =~ /Not enough arguments/; 602*0Sstevel@tonic-gate print "ok ", $i++, "\n"; 603*0Sstevel@tonic-gate} 604*0Sstevel@tonic-gate 605*0Sstevel@tonic-gate# check that obviously bad prototypes are getting warnings 606*0Sstevel@tonic-gate{ 607*0Sstevel@tonic-gate use warnings 'syntax'; 608*0Sstevel@tonic-gate my $warn = ""; 609*0Sstevel@tonic-gate local $SIG{__WARN__} = sub { $warn .= join("",@_) }; 610*0Sstevel@tonic-gate 611*0Sstevel@tonic-gate eval 'sub badproto (@bar) { 1; }'; 612*0Sstevel@tonic-gate print "not " unless $warn =~ /Illegal character in prototype for main::badproto : \@bar/; 613*0Sstevel@tonic-gate print "ok ", $i++, "\n"; 614*0Sstevel@tonic-gate 615*0Sstevel@tonic-gate eval 'sub badproto2 (bar) { 1; }'; 616*0Sstevel@tonic-gate print "not " unless $warn =~ /Illegal character in prototype for main::badproto2 : bar/; 617*0Sstevel@tonic-gate print "ok ", $i++, "\n"; 618*0Sstevel@tonic-gate 619*0Sstevel@tonic-gate eval 'sub badproto3 (&$bar$@) { 1; }'; 620*0Sstevel@tonic-gate print "not " unless $warn =~ /Illegal character in prototype for main::badproto3 : &\$bar\$\@/; 621*0Sstevel@tonic-gate print "ok ", $i++, "\n"; 622*0Sstevel@tonic-gate 623*0Sstevel@tonic-gate eval 'sub badproto4 (@ $b ar) { 1; }'; 624*0Sstevel@tonic-gate print "not " unless $warn =~ /Illegal character in prototype for main::badproto4 : \@\$bar/; 625*0Sstevel@tonic-gate print "ok ", $i++, "\n"; 626*0Sstevel@tonic-gate} 627*0Sstevel@tonic-gate 628*0Sstevel@tonic-gate# make sure whitespace in prototypes works 629*0Sstevel@tonic-gateeval "sub good (\$\t\$\n\$) { 1; }"; 630*0Sstevel@tonic-gateprint "not " if $@; 631*0Sstevel@tonic-gateprint "ok ", $i++, "\n"; 632*0Sstevel@tonic-gate 633*0Sstevel@tonic-gateeval 'sub bug (\[%@]) { } my $array = [0 .. 1]; bug %$array;'; 634*0Sstevel@tonic-gateprint "not " unless $@ =~ /Not a HASH reference/; 635*0Sstevel@tonic-gateprint "ok ", $i++, " # TODO Ought to fail, doesn't in 5.8.2\n"; 636