| 1 | Check strict vars functionality
|
|---|
| 2 |
|
|---|
| 3 | __END__
|
|---|
| 4 |
|
|---|
| 5 | # no strict, should build & run ok.
|
|---|
| 6 | Fred ;
|
|---|
| 7 | my $fred ;
|
|---|
| 8 | $b = "fred" ;
|
|---|
| 9 | $a = $$b ;
|
|---|
| 10 | EXPECT
|
|---|
| 11 |
|
|---|
| 12 | ########
|
|---|
| 13 |
|
|---|
| 14 | use strict qw(subs refs) ;
|
|---|
| 15 | $fred ;
|
|---|
| 16 | EXPECT
|
|---|
| 17 |
|
|---|
| 18 | ########
|
|---|
| 19 |
|
|---|
| 20 | use strict ;
|
|---|
| 21 | no strict 'vars' ;
|
|---|
| 22 | $fred ;
|
|---|
| 23 | EXPECT
|
|---|
| 24 |
|
|---|
| 25 | ########
|
|---|
| 26 |
|
|---|
| 27 | # strict vars - no error
|
|---|
| 28 | use strict 'vars' ;
|
|---|
| 29 | use vars qw( $freddy) ;
|
|---|
| 30 | BEGIN { *freddy = \$joe::shmoe; }
|
|---|
| 31 | $freddy = 2 ;
|
|---|
| 32 | EXPECT
|
|---|
| 33 |
|
|---|
| 34 | ########
|
|---|
| 35 |
|
|---|
| 36 | # strict vars - no error
|
|---|
| 37 | use strict 'vars' ;
|
|---|
| 38 | use vars qw( $freddy) ;
|
|---|
| 39 | local $abc::joe ;
|
|---|
| 40 | my $fred ;
|
|---|
| 41 | my $b = \$fred ;
|
|---|
| 42 | $Fred::ABC = 1 ;
|
|---|
| 43 | $freddy = 2 ;
|
|---|
| 44 | EXPECT
|
|---|
| 45 |
|
|---|
| 46 | ########
|
|---|
| 47 |
|
|---|
| 48 | # strict vars - error
|
|---|
| 49 | use strict ;
|
|---|
| 50 | $fred ;
|
|---|
| 51 | EXPECT
|
|---|
| 52 | Global symbol "$fred" requires explicit package name at - line 4.
|
|---|
| 53 | Execution of - aborted due to compilation errors.
|
|---|
| 54 | ########
|
|---|
| 55 |
|
|---|
| 56 | # strict vars - error
|
|---|
| 57 | use strict 'vars' ;
|
|---|
| 58 | <$fred> ;
|
|---|
| 59 | EXPECT
|
|---|
| 60 | Global symbol "$fred" requires explicit package name at - line 4.
|
|---|
| 61 | Execution of - aborted due to compilation errors.
|
|---|
| 62 | ########
|
|---|
| 63 |
|
|---|
| 64 | # strict vars - error
|
|---|
| 65 | use strict 'vars' ;
|
|---|
| 66 | local $fred ;
|
|---|
| 67 | EXPECT
|
|---|
| 68 | Global symbol "$fred" requires explicit package name at - line 4.
|
|---|
| 69 | Execution of - aborted due to compilation errors.
|
|---|
| 70 | ########
|
|---|
| 71 |
|
|---|
| 72 | # Check compile time scope of strict vars pragma
|
|---|
| 73 | use strict 'vars' ;
|
|---|
| 74 | {
|
|---|
| 75 | no strict ;
|
|---|
| 76 | $joe = 1 ;
|
|---|
| 77 | }
|
|---|
| 78 | $joe = 1 ;
|
|---|
| 79 | EXPECT
|
|---|
| 80 | Variable "$joe" is not imported at - line 8.
|
|---|
| 81 | Global symbol "$joe" requires explicit package name at - line 8.
|
|---|
| 82 | Execution of - aborted due to compilation errors.
|
|---|
| 83 | ########
|
|---|
| 84 |
|
|---|
| 85 | # Check compile time scope of strict vars pragma
|
|---|
| 86 | no strict;
|
|---|
| 87 | {
|
|---|
| 88 | use strict 'vars' ;
|
|---|
| 89 | $joe = 1 ;
|
|---|
| 90 | }
|
|---|
| 91 | $joe = 1 ;
|
|---|
| 92 | EXPECT
|
|---|
| 93 | Global symbol "$joe" requires explicit package name at - line 6.
|
|---|
| 94 | Execution of - aborted due to compilation errors.
|
|---|
| 95 | ########
|
|---|
| 96 |
|
|---|
| 97 | --FILE-- abc
|
|---|
| 98 | $joe = 1 ;
|
|---|
| 99 | 1;
|
|---|
| 100 | --FILE--
|
|---|
| 101 | use strict 'vars' ;
|
|---|
| 102 | require "./abc";
|
|---|
| 103 | EXPECT
|
|---|
| 104 |
|
|---|
| 105 | ########
|
|---|
| 106 |
|
|---|
| 107 | --FILE-- abc
|
|---|
| 108 | use strict 'vars' ;
|
|---|
| 109 | 1;
|
|---|
| 110 | --FILE--
|
|---|
| 111 | require "./abc";
|
|---|
| 112 | $joe = 1 ;
|
|---|
| 113 | EXPECT
|
|---|
| 114 |
|
|---|
| 115 | ########
|
|---|
| 116 |
|
|---|
| 117 | --FILE-- abc
|
|---|
| 118 | use strict 'vars' ;
|
|---|
| 119 | $joe = 1 ;
|
|---|
| 120 | 1;
|
|---|
| 121 | --FILE--
|
|---|
| 122 | $joe = 1 ;
|
|---|
| 123 | require "./abc";
|
|---|
| 124 | EXPECT
|
|---|
| 125 | Variable "$joe" is not imported at ./abc line 2.
|
|---|
| 126 | Global symbol "$joe" requires explicit package name at ./abc line 2.
|
|---|
| 127 | Compilation failed in require at - line 2.
|
|---|
| 128 | ########
|
|---|
| 129 |
|
|---|
| 130 | --FILE-- abc.pm
|
|---|
| 131 | use strict 'vars' ;
|
|---|
| 132 | $joe = 1 ;
|
|---|
| 133 | 1;
|
|---|
| 134 | --FILE--
|
|---|
| 135 | $joe = 1 ;
|
|---|
| 136 | use abc;
|
|---|
| 137 | EXPECT
|
|---|
| 138 | Variable "$joe" is not imported at abc.pm line 2.
|
|---|
| 139 | Global symbol "$joe" requires explicit package name at abc.pm line 2.
|
|---|
| 140 | Compilation failed in require at - line 2.
|
|---|
| 141 | BEGIN failed--compilation aborted at - line 2.
|
|---|
| 142 | ########
|
|---|
| 143 |
|
|---|
| 144 | --FILE-- abc.pm
|
|---|
| 145 | package Burp;
|
|---|
| 146 | use strict;
|
|---|
| 147 | $a = 1;$f = 1;$k = 1; # just to get beyond the limit...
|
|---|
| 148 | $b = 1;$g = 1;$l = 1;
|
|---|
| 149 | $c = 1;$h = 1;$m = 1;
|
|---|
| 150 | $d = 1;$i = 1;$n = 1;
|
|---|
| 151 | $e = 1;$j = 1;$o = 1;
|
|---|
| 152 | $p = 0b12;
|
|---|
| 153 | --FILE--
|
|---|
| 154 | use abc;
|
|---|
| 155 | EXPECT
|
|---|
| 156 | Global symbol "$f" requires explicit package name at abc.pm line 3.
|
|---|
| 157 | Global symbol "$k" requires explicit package name at abc.pm line 3.
|
|---|
| 158 | Global symbol "$g" requires explicit package name at abc.pm line 4.
|
|---|
| 159 | Global symbol "$l" requires explicit package name at abc.pm line 4.
|
|---|
| 160 | Global symbol "$c" requires explicit package name at abc.pm line 5.
|
|---|
| 161 | Global symbol "$h" requires explicit package name at abc.pm line 5.
|
|---|
| 162 | Global symbol "$m" requires explicit package name at abc.pm line 5.
|
|---|
| 163 | Global symbol "$d" requires explicit package name at abc.pm line 6.
|
|---|
| 164 | Global symbol "$i" requires explicit package name at abc.pm line 6.
|
|---|
| 165 | Global symbol "$n" requires explicit package name at abc.pm line 6.
|
|---|
| 166 | Global symbol "$e" requires explicit package name at abc.pm line 7.
|
|---|
| 167 | Global symbol "$j" requires explicit package name at abc.pm line 7.
|
|---|
| 168 | Global symbol "$o" requires explicit package name at abc.pm line 7.
|
|---|
| 169 | Global symbol "$p" requires explicit package name at abc.pm line 8.
|
|---|
| 170 | Illegal binary digit '2' at abc.pm line 8, at end of line
|
|---|
| 171 | abc.pm has too many errors.
|
|---|
| 172 | Compilation failed in require at - line 1.
|
|---|
| 173 | BEGIN failed--compilation aborted at - line 1.
|
|---|
| 174 | ########
|
|---|
| 175 |
|
|---|
| 176 | # Check scope of pragma with eval
|
|---|
| 177 | no strict ;
|
|---|
| 178 | eval {
|
|---|
| 179 | $joe = 1 ;
|
|---|
| 180 | };
|
|---|
| 181 | print STDERR $@;
|
|---|
| 182 | $joe = 1 ;
|
|---|
| 183 | EXPECT
|
|---|
| 184 |
|
|---|
| 185 | ########
|
|---|
| 186 |
|
|---|
| 187 | # Check scope of pragma with eval
|
|---|
| 188 | no strict ;
|
|---|
| 189 | eval {
|
|---|
| 190 | use strict 'vars' ;
|
|---|
| 191 | $joe = 1 ;
|
|---|
| 192 | };
|
|---|
| 193 | print STDERR $@;
|
|---|
| 194 | $joe = 1 ;
|
|---|
| 195 | EXPECT
|
|---|
| 196 | Global symbol "$joe" requires explicit package name at - line 6.
|
|---|
| 197 | Execution of - aborted due to compilation errors.
|
|---|
| 198 | ########
|
|---|
| 199 |
|
|---|
| 200 | # Check scope of pragma with eval
|
|---|
| 201 | use strict 'vars' ;
|
|---|
| 202 | eval {
|
|---|
| 203 | $joe = 1 ;
|
|---|
| 204 | };
|
|---|
| 205 | print STDERR $@;
|
|---|
| 206 | $joe = 1 ;
|
|---|
| 207 | EXPECT
|
|---|
| 208 | Global symbol "$joe" requires explicit package name at - line 5.
|
|---|
| 209 | Global symbol "$joe" requires explicit package name at - line 8.
|
|---|
| 210 | Execution of - aborted due to compilation errors.
|
|---|
| 211 | ########
|
|---|
| 212 |
|
|---|
| 213 | # Check scope of pragma with eval
|
|---|
| 214 | use strict 'vars' ;
|
|---|
| 215 | eval {
|
|---|
| 216 | no strict ;
|
|---|
| 217 | $joe = 1 ;
|
|---|
| 218 | };
|
|---|
| 219 | print STDERR $@;
|
|---|
| 220 | $joe = 1 ;
|
|---|
| 221 | EXPECT
|
|---|
| 222 | Variable "$joe" is not imported at - line 9.
|
|---|
| 223 | Global symbol "$joe" requires explicit package name at - line 9.
|
|---|
| 224 | Execution of - aborted due to compilation errors.
|
|---|
| 225 | ########
|
|---|
| 226 |
|
|---|
| 227 | # Check scope of pragma with eval
|
|---|
| 228 | no strict ;
|
|---|
| 229 | eval '
|
|---|
| 230 | $joe = 1 ;
|
|---|
| 231 | '; print STDERR $@ ;
|
|---|
| 232 | $joe = 1 ;
|
|---|
| 233 | EXPECT
|
|---|
| 234 |
|
|---|
| 235 | ########
|
|---|
| 236 |
|
|---|
| 237 | # Check scope of pragma with eval
|
|---|
| 238 | no strict ;
|
|---|
| 239 | eval q[
|
|---|
|
|---|