1*0Sstevel@tonic-gateCheck strict subs functionality 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gate__END__ 4*0Sstevel@tonic-gate 5*0Sstevel@tonic-gate# no strict, should build & run ok. 6*0Sstevel@tonic-gateFred ; 7*0Sstevel@tonic-gatemy $fred ; 8*0Sstevel@tonic-gate$b = "fred" ; 9*0Sstevel@tonic-gate$a = $$b ; 10*0Sstevel@tonic-gateEXPECT 11*0Sstevel@tonic-gate 12*0Sstevel@tonic-gate######## 13*0Sstevel@tonic-gate 14*0Sstevel@tonic-gateuse strict qw(refs vars); 15*0Sstevel@tonic-gateFred ; 16*0Sstevel@tonic-gateEXPECT 17*0Sstevel@tonic-gate 18*0Sstevel@tonic-gate######## 19*0Sstevel@tonic-gate 20*0Sstevel@tonic-gateuse strict ; 21*0Sstevel@tonic-gateno strict 'subs' ; 22*0Sstevel@tonic-gateFred ; 23*0Sstevel@tonic-gateEXPECT 24*0Sstevel@tonic-gate 25*0Sstevel@tonic-gate######## 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate# strict subs - error 28*0Sstevel@tonic-gateuse strict 'subs' ; 29*0Sstevel@tonic-gatemy @a = (1..2); 30*0Sstevel@tonic-gatemy $b = xyz; 31*0Sstevel@tonic-gateEXPECT 32*0Sstevel@tonic-gateBareword "xyz" not allowed while "strict subs" in use at - line 5. 33*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 34*0Sstevel@tonic-gate######## 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate# strict subs - error 37*0Sstevel@tonic-gateuse strict 'subs' ; 38*0Sstevel@tonic-gateFred ; 39*0Sstevel@tonic-gateEXPECT 40*0Sstevel@tonic-gateBareword "Fred" not allowed while "strict subs" in use at - line 4. 41*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 42*0Sstevel@tonic-gate######## 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate# strict subs - error 45*0Sstevel@tonic-gateuse strict 'subs' ; 46*0Sstevel@tonic-gatemy @a = (A..Z); 47*0Sstevel@tonic-gateEXPECT 48*0Sstevel@tonic-gateBareword "Z" not allowed while "strict subs" in use at - line 4. 49*0Sstevel@tonic-gateBareword "A" not allowed while "strict subs" in use at - line 4. 50*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 51*0Sstevel@tonic-gate######## 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate# strict subs - error 54*0Sstevel@tonic-gateuse strict 'subs' ; 55*0Sstevel@tonic-gatemy $a = (B..Y); 56*0Sstevel@tonic-gateEXPECT 57*0Sstevel@tonic-gateBareword "Y" not allowed while "strict subs" in use at - line 4. 58*0Sstevel@tonic-gateBareword "B" not allowed while "strict subs" in use at - line 4. 59*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 60*0Sstevel@tonic-gate######## 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate# strict subs - error 63*0Sstevel@tonic-gateuse strict ; 64*0Sstevel@tonic-gateFred ; 65*0Sstevel@tonic-gateEXPECT 66*0Sstevel@tonic-gateBareword "Fred" not allowed while "strict subs" in use at - line 4. 67*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 68*0Sstevel@tonic-gate######## 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate# strict subs - no error 71*0Sstevel@tonic-gateuse strict 'subs' ; 72*0Sstevel@tonic-gatesub Fred {} 73*0Sstevel@tonic-gateFred ; 74*0Sstevel@tonic-gateEXPECT 75*0Sstevel@tonic-gate 76*0Sstevel@tonic-gate######## 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gate# Check compile time scope of strict subs pragma 79*0Sstevel@tonic-gateuse strict 'subs' ; 80*0Sstevel@tonic-gate{ 81*0Sstevel@tonic-gate no strict ; 82*0Sstevel@tonic-gate my $a = Fred ; 83*0Sstevel@tonic-gate} 84*0Sstevel@tonic-gatemy $a = Fred ; 85*0Sstevel@tonic-gateEXPECT 86*0Sstevel@tonic-gateBareword "Fred" not allowed while "strict subs" in use at - line 8. 87*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 88*0Sstevel@tonic-gate######## 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate# Check compile time scope of strict subs pragma 91*0Sstevel@tonic-gateno strict; 92*0Sstevel@tonic-gate{ 93*0Sstevel@tonic-gate use strict 'subs' ; 94*0Sstevel@tonic-gate my $a = Fred ; 95*0Sstevel@tonic-gate} 96*0Sstevel@tonic-gatemy $a = Fred ; 97*0Sstevel@tonic-gateEXPECT 98*0Sstevel@tonic-gateBareword "Fred" not allowed while "strict subs" in use at - line 6. 99*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 100*0Sstevel@tonic-gate######## 101*0Sstevel@tonic-gate 102*0Sstevel@tonic-gate# Check compile time scope of strict vars pragma 103*0Sstevel@tonic-gateuse strict 'vars' ; 104*0Sstevel@tonic-gate{ 105*0Sstevel@tonic-gate no strict ; 106*0Sstevel@tonic-gate $joe = 1 ; 107*0Sstevel@tonic-gate} 108*0Sstevel@tonic-gate$joe = 1 ; 109*0Sstevel@tonic-gateEXPECT 110*0Sstevel@tonic-gateVariable "$joe" is not imported at - line 8. 111*0Sstevel@tonic-gateGlobal symbol "$joe" requires explicit package name at - line 8. 112*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 113*0Sstevel@tonic-gate######## 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate# Check compile time scope of strict vars pragma 116*0Sstevel@tonic-gateno strict; 117*0Sstevel@tonic-gate{ 118*0Sstevel@tonic-gate use strict 'vars' ; 119*0Sstevel@tonic-gate $joe = 1 ; 120*0Sstevel@tonic-gate} 121*0Sstevel@tonic-gate$joe = 1 ; 122*0Sstevel@tonic-gateEXPECT 123*0Sstevel@tonic-gateGlobal symbol "$joe" requires explicit package name at - line 6. 124*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 125*0Sstevel@tonic-gate######## 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate# Check runtime scope of strict refs pragma 128*0Sstevel@tonic-gateuse strict 'refs'; 129*0Sstevel@tonic-gatemy $fred ; 130*0Sstevel@tonic-gatemy $b = "fred" ; 131*0Sstevel@tonic-gate{ 132*0Sstevel@tonic-gate no strict ; 133*0Sstevel@tonic-gate my $a = $$b ; 134*0Sstevel@tonic-gate} 135*0Sstevel@tonic-gatemy $a = $$b ; 136*0Sstevel@tonic-gateEXPECT 137*0Sstevel@tonic-gateCan't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 10. 138*0Sstevel@tonic-gate######## 139*0Sstevel@tonic-gate 140*0Sstevel@tonic-gate# Check runtime scope of strict refs pragma 141*0Sstevel@tonic-gateno strict ; 142*0Sstevel@tonic-gatemy $fred ; 143*0Sstevel@tonic-gatemy $b = "fred" ; 144*0Sstevel@tonic-gate{ 145*0Sstevel@tonic-gate use strict 'refs' ; 146*0Sstevel@tonic-gate my $a = $$b ; 147*0Sstevel@tonic-gate} 148*0Sstevel@tonic-gatemy $a = $$b ; 149*0Sstevel@tonic-gateEXPECT 150*0Sstevel@tonic-gateCan't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8. 151*0Sstevel@tonic-gate######## 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate# Check runtime scope of strict refs pragma 154*0Sstevel@tonic-gateno strict ; 155*0Sstevel@tonic-gatemy $fred ; 156*0Sstevel@tonic-gatemy $b = "fred" ; 157*0Sstevel@tonic-gate{ 158*0Sstevel@tonic-gate use strict 'refs' ; 159*0Sstevel@tonic-gate $a = sub { my $c = $$b ; } 160*0Sstevel@tonic-gate} 161*0Sstevel@tonic-gate&$a ; 162*0Sstevel@tonic-gateEXPECT 163*0Sstevel@tonic-gateCan't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8. 164*0Sstevel@tonic-gate######## 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gateuse strict 'subs' ; 167*0Sstevel@tonic-gatemy $a = Fred ; 168*0Sstevel@tonic-gateEXPECT 169*0Sstevel@tonic-gateBareword "Fred" not allowed while "strict subs" in use at - line 3. 170*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 171*0Sstevel@tonic-gate######## 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gate--FILE-- abc 174*0Sstevel@tonic-gatemy $a = Fred ; 175*0Sstevel@tonic-gate1; 176*0Sstevel@tonic-gate--FILE-- 177*0Sstevel@tonic-gateuse strict 'subs' ; 178*0Sstevel@tonic-gaterequire "./abc"; 179*0Sstevel@tonic-gateEXPECT 180*0Sstevel@tonic-gate 181*0Sstevel@tonic-gate######## 182*0Sstevel@tonic-gate 183*0Sstevel@tonic-gate--FILE-- abc 184*0Sstevel@tonic-gateuse strict 'subs' ; 185*0Sstevel@tonic-gate1; 186*0Sstevel@tonic-gate--FILE-- 187*0Sstevel@tonic-gaterequire "./abc"; 188*0Sstevel@tonic-gatemy $a = Fred ; 189*0Sstevel@tonic-gateEXPECT 190*0Sstevel@tonic-gate 191*0Sstevel@tonic-gate######## 192*0Sstevel@tonic-gate 193*0Sstevel@tonic-gate--FILE-- abc 194*0Sstevel@tonic-gateuse strict 'subs' ; 195*0Sstevel@tonic-gatemy $a = Fred ; 196*0Sstevel@tonic-gate1; 197*0Sstevel@tonic-gate--FILE-- 198*0Sstevel@tonic-gateFred ; 199*0Sstevel@tonic-gaterequire "./abc"; 200*0Sstevel@tonic-gateEXPECT 201*0Sstevel@tonic-gateBareword "Fred" not allowed while "strict subs" in use at ./abc line 2. 202*0Sstevel@tonic-gateCompilation failed in require at - line 2. 203*0Sstevel@tonic-gate######## 204*0Sstevel@tonic-gate 205*0Sstevel@tonic-gate--FILE-- abc.pm 206*0Sstevel@tonic-gateuse strict 'subs' ; 207*0Sstevel@tonic-gatemy $a = Fred ; 208*0Sstevel@tonic-gate1; 209*0Sstevel@tonic-gate--FILE-- 210*0Sstevel@tonic-gateFred ; 211*0Sstevel@tonic-gateuse abc; 212*0Sstevel@tonic-gateEXPECT 213*0Sstevel@tonic-gateBareword "Fred" not allowed while "strict subs" in use at abc.pm line 2. 214*0Sstevel@tonic-gateCompilation failed in require at - line 2. 215*0Sstevel@tonic-gateBEGIN failed--compilation aborted at - line 2. 216*0Sstevel@tonic-gate######## 217*0Sstevel@tonic-gate 218*0Sstevel@tonic-gate# Check scope of pragma with eval 219*0Sstevel@tonic-gateno strict ; 220*0Sstevel@tonic-gateeval { 221*0Sstevel@tonic-gate my $a = Fred ; 222*0Sstevel@tonic-gate}; 223*0Sstevel@tonic-gateprint STDERR $@; 224*0Sstevel@tonic-gatemy $a = Fred ; 225*0Sstevel@tonic-gateEXPECT 226*0Sstevel@tonic-gate 227*0Sstevel@tonic-gate######## 228*0Sstevel@tonic-gate 229*0Sstevel@tonic-gate# Check scope of pragma with eval 230*0Sstevel@tonic-gateno strict ; 231*0Sstevel@tonic-gateeval { 232*0Sstevel@tonic-gate use strict 'subs' ; 233*0Sstevel@tonic-gate my $a = Fred ; 234*0Sstevel@tonic-gate}; 235*0Sstevel@tonic-gateprint STDERR $@; 236*0Sstevel@tonic-gatemy $a = Fred ; 237*0Sstevel@tonic-gateEXPECT 238*0Sstevel@tonic-gateBareword "Fred" not allowed while "strict subs" in use at - line 6. 239*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 240*0Sstevel@tonic-gate######## 241*0Sstevel@tonic-gate 242*0Sstevel@tonic-gate# Check scope of pragma with eval 243*0Sstevel@tonic-gateuse strict 'subs' ; 244*0Sstevel@tonic-gateeval { 245*0Sstevel@tonic-gate my $a = Fred ; 246*0Sstevel@tonic-gate}; 247*0Sstevel@tonic-gateprint STDERR $@; 248*0Sstevel@tonic-gatemy $a = Fred ; 249*0Sstevel@tonic-gateEXPECT 250*0Sstevel@tonic-gateBareword "Fred" not allowed while "strict subs" in use at - line 5. 251*0Sstevel@tonic-gateBareword "Fred" not allowed while "strict subs" in use at - line 8. 252*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 253*0Sstevel@tonic-gate######## 254*0Sstevel@tonic-gate 255*0Sstevel@tonic-gate# Check scope of pragma with eval 256*0Sstevel@tonic-gateuse strict 'subs' ; 257*0Sstevel@tonic-gateeval { 258*0Sstevel@tonic-gate no strict ; 259*0Sstevel@tonic-gate my $a = Fred ; 260*0Sstevel@tonic-gate}; 261*0Sstevel@tonic-gateprint STDERR $@; 262*0Sstevel@tonic-gatemy $a = Fred ; 263*0Sstevel@tonic-gateEXPECT 264*0Sstevel@tonic-gateBareword "Fred" not allowed while "strict subs" in use at - line 9. 265*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 266*0Sstevel@tonic-gate######## 267*0Sstevel@tonic-gate 268*0Sstevel@tonic-gate# Check scope of pragma with eval 269*0Sstevel@tonic-gateno strict ; 270*0Sstevel@tonic-gateeval ' 271*0Sstevel@tonic-gate Fred ; 272*0Sstevel@tonic-gate'; print STDERR $@ ; 273*0Sstevel@tonic-gateFred ; 274*0Sstevel@tonic-gateEXPECT 275*0Sstevel@tonic-gate 276*0Sstevel@tonic-gate######## 277*0Sstevel@tonic-gate 278*0Sstevel@tonic-gate# Check scope of pragma with eval 279*0Sstevel@tonic-gateno strict ; 280*0Sstevel@tonic-gateeval q[ 281*0Sstevel@tonic-gate use strict 'subs' ; 282*0Sstevel@tonic-gate Fred ; 283*0Sstevel@tonic-gate]; print STDERR $@; 284*0Sstevel@tonic-gateEXPECT 285*0Sstevel@tonic-gateBareword "Fred" not allowed while "strict subs" in use at (eval 1) line 3. 286*0Sstevel@tonic-gate######## 287*0Sstevel@tonic-gate 288*0Sstevel@tonic-gate# Check scope of pragma with eval 289*0Sstevel@tonic-gateuse strict 'subs' ; 290*0Sstevel@tonic-gateeval ' 291*0Sstevel@tonic-gate Fred ; 292*0Sstevel@tonic-gate'; print STDERR $@ ; 293*0Sstevel@tonic-gateEXPECT 294*0Sstevel@tonic-gateBareword "Fred" not allowed while "strict subs" in use at (eval 1) line 2. 295*0Sstevel@tonic-gate######## 296*0Sstevel@tonic-gate 297*0Sstevel@tonic-gate# Check scope of pragma with eval 298*0Sstevel@tonic-gateuse strict 'subs' ; 299*0Sstevel@tonic-gateeval ' 300*0Sstevel@tonic-gate no strict ; 301*0Sstevel@tonic-gate my $a = Fred ; 302*0Sstevel@tonic-gate'; print STDERR $@; 303*0Sstevel@tonic-gatemy $a = Fred ; 304*0Sstevel@tonic-gateEXPECT 305*0Sstevel@tonic-gateBareword "Fred" not allowed while "strict subs" in use at - line 8. 306*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 307*0Sstevel@tonic-gate######## 308*0Sstevel@tonic-gate 309*0Sstevel@tonic-gate# see if Foo->Bar(...) etc work under strictures 310*0Sstevel@tonic-gateuse strict; 311*0Sstevel@tonic-gatepackage Foo; sub Bar { print "@_\n" } 312*0Sstevel@tonic-gateFoo->Bar('a',1); 313*0Sstevel@tonic-gateBar Foo ('b',2); 314*0Sstevel@tonic-gateFoo->Bar(qw/c 3/); 315*0Sstevel@tonic-gateBar Foo (qw/d 4/); 316*0Sstevel@tonic-gateFoo::->Bar('A',1); 317*0Sstevel@tonic-gateBar Foo:: ('B',2); 318*0Sstevel@tonic-gateFoo::->Bar(qw/C 3/); 319*0Sstevel@tonic-gateBar Foo:: (qw/D 4/); 320*0Sstevel@tonic-gateEXPECT 321*0Sstevel@tonic-gateFoo a 1 322*0Sstevel@tonic-gateFoo b 2 323*0Sstevel@tonic-gateFoo c 3 324*0Sstevel@tonic-gateFoo d 4 325*0Sstevel@tonic-gateFoo A 1 326*0Sstevel@tonic-gateFoo B 2 327*0Sstevel@tonic-gateFoo C 3 328*0Sstevel@tonic-gateFoo D 4 329*0Sstevel@tonic-gate######## 330*0Sstevel@tonic-gate 331*0Sstevel@tonic-gate# Check that barewords on the RHS of a regex match are caught 332*0Sstevel@tonic-gateuse strict; 333*0Sstevel@tonic-gate"" =~ foo; 334*0Sstevel@tonic-gateEXPECT 335*0Sstevel@tonic-gateBareword "foo" not allowed while "strict subs" in use at - line 4. 336*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 337*0Sstevel@tonic-gate 338*0Sstevel@tonic-gate######## 339*0Sstevel@tonic-gate 340*0Sstevel@tonic-gate# ID 20020703.002 341*0Sstevel@tonic-gateuse strict; 342*0Sstevel@tonic-gateuse warnings; 343*0Sstevel@tonic-gatemy $abc = XYZ ? 1 : 0; 344*0Sstevel@tonic-gateprint "$abc\n"; 345*0Sstevel@tonic-gateEXPECT 346*0Sstevel@tonic-gateBareword "XYZ" not allowed while "strict subs" in use at - line 5. 347*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 348*0Sstevel@tonic-gate######## 349*0Sstevel@tonic-gate 350*0Sstevel@tonic-gate# [perl #10021] 351*0Sstevel@tonic-gateuse strict; 352*0Sstevel@tonic-gateuse warnings; 353*0Sstevel@tonic-gateprint "" if BAREWORD; 354*0Sstevel@tonic-gateEXPECT 355*0Sstevel@tonic-gateBareword "BAREWORD" not allowed while "strict subs" in use at - line 5. 356*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 357*0Sstevel@tonic-gate######## 358*0Sstevel@tonic-gate# Ticket: 18927 359*0Sstevel@tonic-gateuse strict 'subs'; 360*0Sstevel@tonic-gateprint 1..1, bad; 361*0Sstevel@tonic-gateEXPECT 362*0Sstevel@tonic-gateBareword "bad" not allowed while "strict subs" in use at - line 3. 363*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 364*0Sstevel@tonic-gate######## 365*0Sstevel@tonic-gate# [perl #25147] 366*0Sstevel@tonic-gateuse strict; 367*0Sstevel@tonic-gateprint "" if BAREWORD; 368*0Sstevel@tonic-gateEXPECT 369*0Sstevel@tonic-gateBareword "BAREWORD" not allowed while "strict subs" in use at - line 3. 370*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 371*0Sstevel@tonic-gate######## 372*0Sstevel@tonic-gate# [perl #26910] hints not propagated into (?{...}) 373*0Sstevel@tonic-gateuse strict 'subs'; 374*0Sstevel@tonic-gateqr/(?{my $x=foo})/; 375*0Sstevel@tonic-gateEXPECT 376*0Sstevel@tonic-gateBareword "foo" not allowed while "strict subs" in use at (re_eval 1) line 1. 377*0Sstevel@tonic-gateCompilation failed in regexp at - line 3. 378*0Sstevel@tonic-gate######## 379*0Sstevel@tonic-gate# [perl #27628] strict 'subs' didn't warn on bareword array index 380*0Sstevel@tonic-gateuse strict 'subs'; 381*0Sstevel@tonic-gatemy $x=$a[FOO]; 382*0Sstevel@tonic-gateEXPECT 383*0Sstevel@tonic-gateBareword "FOO" not allowed while "strict subs" in use at - line 3. 384*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 385*0Sstevel@tonic-gate######## 386*0Sstevel@tonic-gateuse strict 'subs'; 387*0Sstevel@tonic-gatemy @a;my $x=$a[FOO]; 388*0Sstevel@tonic-gateEXPECT 389*0Sstevel@tonic-gateBareword "FOO" not allowed while "strict subs" in use at - line 2. 390*0Sstevel@tonic-gateExecution of - aborted due to compilation errors. 391