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