Commit | Line | Data |
8ebc5c01 |
1 | Check strict subs 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(refs vars); |
15 | Fred ; |
16 | EXPECT |
17 | |
18 | ######## |
19 | |
20 | use strict ; |
21 | no strict 'subs' ; |
22 | Fred ; |
23 | EXPECT |
24 | |
25 | ######## |
26 | |
27 | # strict subs - error |
28 | use strict 'subs' ; |
29 | Fred ; |
30 | EXPECT |
31 | Bareword "Fred" not allowed while "strict subs" in use at - line 4. |
32 | Execution of - aborted due to compilation errors. |
33 | ######## |
34 | |
35 | # strict subs - error |
7d4045d4 |
36 | use strict 'subs' ; |
37 | my @a = (A..Z); |
38 | EXPECT |
39 | Bareword "Z" not allowed while "strict subs" in use at - line 4. |
40 | Bareword "A" not allowed while "strict subs" in use at - line 4. |
41 | Execution of - aborted due to compilation errors. |
42 | ######## |
43 | |
44 | # strict subs - error |
45 | use strict 'subs' ; |
46 | my $a = (B..Y); |
47 | EXPECT |
48 | Bareword "Y" not allowed while "strict subs" in use at - line 4. |
49 | Bareword "B" not allowed while "strict subs" in use at - line 4. |
50 | Execution of - aborted due to compilation errors. |
51 | ######## |
52 | |
53 | # strict subs - error |
8ebc5c01 |
54 | use strict ; |
55 | Fred ; |
56 | EXPECT |
57 | Bareword "Fred" not allowed while "strict subs" in use at - line 4. |
58 | Execution of - aborted due to compilation errors. |
59 | ######## |
60 | |
61 | # strict subs - no error |
62 | use strict 'subs' ; |
63 | sub Fred {} |
64 | Fred ; |
65 | EXPECT |
66 | |
67 | ######## |
68 | |
69 | # Check compile time scope of strict subs pragma |
70 | use strict 'subs' ; |
71 | { |
72 | no strict ; |
73 | my $a = Fred ; |
74 | } |
75 | my $a = Fred ; |
76 | EXPECT |
77 | Bareword "Fred" not allowed while "strict subs" in use at - line 8. |
78 | Execution of - aborted due to compilation errors. |
79 | ######## |
80 | |
81 | # Check compile time scope of strict subs pragma |
82 | no strict; |
83 | { |
84 | use strict 'subs' ; |
85 | my $a = Fred ; |
86 | } |
87 | my $a = Fred ; |
88 | EXPECT |
89 | Bareword "Fred" not allowed while "strict subs" in use at - line 6. |
90 | Execution of - aborted due to compilation errors. |
91 | ######## |
92 | |
93 | # Check compile time scope of strict vars pragma |
94 | use strict 'vars' ; |
95 | { |
96 | no strict ; |
97 | $joe = 1 ; |
98 | } |
99 | $joe = 1 ; |
100 | EXPECT |
101 | Variable "$joe" is not imported at - line 8. |
2c4aebbd |
102 | Global symbol "$joe" requires explicit package name at - line 8. |
8ebc5c01 |
103 | Execution of - aborted due to compilation errors. |
104 | ######## |
105 | |
106 | # Check compile time scope of strict vars pragma |
107 | no strict; |
108 | { |
109 | use strict 'vars' ; |
110 | $joe = 1 ; |
111 | } |
112 | $joe = 1 ; |
113 | EXPECT |
2c4aebbd |
114 | Global symbol "$joe" requires explicit package name at - line 6. |
8ebc5c01 |
115 | Execution of - aborted due to compilation errors. |
116 | ######## |
117 | |
118 | # Check runtime scope of strict refs pragma |
119 | use strict 'refs'; |
120 | my $fred ; |
121 | my $b = "fred" ; |
122 | { |
123 | no strict ; |
124 | my $a = $$b ; |
125 | } |
126 | my $a = $$b ; |
127 | EXPECT |
128 | Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 10. |
129 | ######## |
130 | |
131 | # Check runtime scope of strict refs pragma |
132 | no strict ; |
133 | my $fred ; |
134 | my $b = "fred" ; |
135 | { |
136 | use strict 'refs' ; |
137 | my $a = $$b ; |
138 | } |
139 | my $a = $$b ; |
140 | EXPECT |
141 | Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8. |
142 | ######## |
143 | |
144 | # Check runtime scope of strict refs pragma |
145 | no strict ; |
146 | my $fred ; |
147 | my $b = "fred" ; |
148 | { |
149 | use strict 'refs' ; |
150 | $a = sub { my $c = $$b ; } |
151 | } |
152 | &$a ; |
153 | EXPECT |
154 | Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8. |
155 | ######## |
156 | |
157 | use strict 'subs' ; |
158 | my $a = Fred ; |
159 | EXPECT |
160 | Bareword "Fred" not allowed while "strict subs" in use at - line 3. |
161 | Execution of - aborted due to compilation errors. |
162 | ######## |
163 | |
164 | --FILE-- abc |
165 | my $a = Fred ; |
166 | 1; |
167 | --FILE-- |
168 | use strict 'subs' ; |
169 | require "./abc"; |
170 | EXPECT |
171 | |
172 | ######## |
173 | |
174 | --FILE-- abc |
175 | use strict 'subs' ; |
176 | 1; |
177 | --FILE-- |
178 | require "./abc"; |
179 | my $a = Fred ; |
180 | EXPECT |
181 | |
182 | ######## |
183 | |
184 | --FILE-- abc |
185 | use strict 'subs' ; |
186 | my $a = Fred ; |
187 | 1; |
188 | --FILE-- |
189 | Fred ; |
190 | require "./abc"; |
191 | EXPECT |
192 | Bareword "Fred" not allowed while "strict subs" in use at ./abc line 2. |
7a2e2cd6 |
193 | Compilation failed in require at - line 2. |
8ebc5c01 |
194 | ######## |
195 | |
196 | --FILE-- abc.pm |
197 | use strict 'subs' ; |
198 | my $a = Fred ; |
199 | 1; |
200 | --FILE-- |
201 | Fred ; |
202 | use abc; |
203 | EXPECT |
204 | Bareword "Fred" not allowed while "strict subs" in use at abc.pm line 2. |
7a2e2cd6 |
205 | Compilation failed in require at - line 2. |
8ebc5c01 |
206 | BEGIN failed--compilation aborted at - line 2. |
207 | ######## |
208 | |
209 | # Check scope of pragma with eval |
210 | no strict ; |
211 | eval { |
212 | my $a = Fred ; |
213 | }; |
214 | print STDERR $@; |
215 | my $a = Fred ; |
216 | EXPECT |
217 | |
218 | ######## |
219 | |
220 | # Check scope of pragma with eval |
221 | no strict ; |
222 | eval { |
223 | use strict 'subs' ; |
224 | my $a = Fred ; |
225 | }; |
226 | print STDERR $@; |
227 | my $a = Fred ; |
228 | EXPECT |
229 | Bareword "Fred" not allowed while "strict subs" in use at - line 6. |
230 | Execution of - aborted due to compilation errors. |
231 | ######## |
232 | |
233 | # Check scope of pragma with eval |
234 | use strict 'subs' ; |
235 | eval { |
236 | my $a = Fred ; |
237 | }; |
238 | print STDERR $@; |
239 | my $a = Fred ; |
240 | EXPECT |
241 | Bareword "Fred" not allowed while "strict subs" in use at - line 5. |
242 | Bareword "Fred" not allowed while "strict subs" in use at - line 8. |
243 | Execution of - aborted due to compilation errors. |
244 | ######## |
245 | |
246 | # Check scope of pragma with eval |
247 | use strict 'subs' ; |
248 | eval { |
249 | no strict ; |
250 | my $a = Fred ; |
251 | }; |
252 | print STDERR $@; |
253 | my $a = Fred ; |
254 | EXPECT |
255 | Bareword "Fred" not allowed while "strict subs" in use at - line 9. |
256 | Execution of - aborted due to compilation errors. |
257 | ######## |
258 | |
259 | # Check scope of pragma with eval |
260 | no strict ; |
261 | eval ' |
262 | Fred ; |
263 | '; print STDERR $@ ; |
264 | Fred ; |
265 | EXPECT |
266 | |
267 | ######## |
268 | |
269 | # Check scope of pragma with eval |
270 | no strict ; |
271 | eval q[ |
272 | use strict 'subs' ; |
273 | Fred ; |
274 | ]; print STDERR $@; |
275 | EXPECT |
276 | Bareword "Fred" not allowed while "strict subs" in use at (eval 1) line 3. |
277 | ######## |
278 | |
279 | # Check scope of pragma with eval |
280 | use strict 'subs' ; |
281 | eval ' |
282 | Fred ; |
283 | '; print STDERR $@ ; |
284 | EXPECT |
285 | Bareword "Fred" not allowed while "strict subs" in use at (eval 1) line 2. |
286 | ######## |
287 | |
288 | # Check scope of pragma with eval |
289 | use strict 'subs' ; |
290 | eval ' |
291 | no strict ; |
292 | my $a = Fred ; |
293 | '; print STDERR $@; |
294 | my $a = Fred ; |
295 | EXPECT |
296 | Bareword "Fred" not allowed while "strict subs" in use at - line 8. |
297 | Execution of - aborted due to compilation errors. |
58a40671 |
298 | ######## |
299 | |
300 | # see if Foo->Bar(...) etc work under strictures |
301 | use strict; |
302 | package Foo; sub Bar { print "@_\n" } |
303 | Foo->Bar('a',1); |
304 | Bar Foo ('b',2); |
305 | Foo->Bar(qw/c 3/); |
306 | Bar Foo (qw/d 4/); |
307 | Foo::->Bar('A',1); |
308 | Bar Foo:: ('B',2); |
309 | Foo::->Bar(qw/C 3/); |
310 | Bar Foo:: (qw/D 4/); |
311 | EXPECT |
312 | Foo a 1 |
313 | Foo b 2 |
314 | Foo c 3 |
315 | Foo d 4 |
316 | Foo A 1 |
317 | Foo B 2 |
318 | Foo C 3 |
319 | Foo D 4 |