This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perlapi: Fix grammar
[perl5.git] / t / lib / warnings / 2use
1 Check lexical warnings functionality
2
3 TODO
4   check that the warning hierarchy works.
5
6 __END__
7
8 #  check illegal category is caught
9 use warnings 'this-should-never-be-a-warning-category' ;
10 EXPECT
11 Unknown warnings category 'this-should-never-be-a-warning-category' at - line 3.
12 BEGIN failed--compilation aborted at - line 3.
13 ########
14
15 # Check compile time scope of pragma
16 use warnings 'syntax' ;
17 {
18     no warnings ;
19     my $a =+ 1 ;
20 }
21 my $a =+ 1 ;
22 EXPECT
23 Reversed += operator at - line 8.
24 ########
25
26 # Check compile time scope of pragma
27 no warnings;
28 {
29     use warnings 'syntax' ;
30     my $a =+ 1 ;
31 }
32 my $a =+ 1 ;
33 EXPECT
34 Reversed += operator at - line 6.
35 ########
36
37 # Check runtime scope of pragma
38 use warnings 'uninitialized' ;
39 {
40     no warnings ;
41     my $b ; chop $b ;
42 }
43 my $b ; chop $b ;
44 EXPECT
45 Use of uninitialized value $b in scalar chop at - line 8.
46 ########
47
48 # Check runtime scope of pragma
49 no warnings ;
50 {
51     use warnings 'uninitialized' ;
52     my $b ; chop $b ;
53 }
54 my $b ; chop $b ;
55 EXPECT
56 Use of uninitialized value $b in scalar chop at - line 6.
57 ########
58
59 # Check runtime scope of pragma
60 no warnings ;
61 {
62     use warnings 'uninitialized' ;
63     $a = sub { my $b ; chop $b ; }
64 }
65 &$a ;
66 EXPECT
67 Use of uninitialized value $b in scalar chop at - line 6.
68 ########
69
70 use warnings 'syntax' ;
71 my $a =+ 1 ;
72 EXPECT
73 Reversed += operator at - line 3.
74 ########
75 -w
76 no warnings 'reserved' ;
77 foo.bar;
78 EXPECT
79 Useless use of a constant ("foobar") in void context at - line 3.
80 ########
81
82 --FILE-- abc
83 my $a =+ 1 ;
84 1;
85 --FILE-- 
86 use warnings 'syntax' ;
87 require "./abc";
88 EXPECT
89
90 ########
91
92 --FILE-- abc
93 use warnings 'syntax' ;
94 1;
95 --FILE-- 
96 require "./abc";
97 my $a =+ 1 ;
98 EXPECT
99
100 ########
101
102 --FILE-- abc
103 use warnings 'syntax' ;
104 my $a =+ 1 ;
105 1;
106 --FILE-- 
107 use warnings 'uninitialized' ;
108 require "./abc";
109 my $a ; chop $a ;
110 EXPECT
111 Reversed += operator at ./abc line 2.
112 Use of uninitialized value $a in scalar chop at - line 3.
113 ########
114
115 --FILE-- abc.pm
116 use warnings 'syntax' ;
117 my $a =+ 1 ;
118 1;
119 --FILE-- 
120 use warnings 'uninitialized' ;
121 use abc;
122 my $a ; chop $a ;
123 EXPECT
124 Reversed += operator at abc.pm line 2.
125 Use of uninitialized value $a in scalar chop at - line 3.
126 ########
127
128 # Check scope of pragma with eval
129 use warnings;
130 {
131     no warnings ;
132     eval {
133         my $b ; chop $b ;
134     }; print STDERR $@ ;
135     my $b ; chop $b ;
136 }
137 EXPECT
138
139 ########
140
141 # Check scope of pragma with eval
142 use warnings;
143 {
144     no warnings ;
145     eval {
146         use warnings 'uninitialized' ;
147         my $b ; chop $b ;
148     }; print STDERR $@ ;
149     my $b ; chop $b ;
150 }
151 EXPECT
152 Use of uninitialized value $b in scalar chop at - line 8.
153 ########
154
155 # Check scope of pragma with eval
156 no warnings;
157 {
158     use warnings 'uninitialized' ;
159     eval {
160         my $b ; chop $b ;
161     }; print STDERR $@ ;
162     my $b ; chop $b ;
163 }
164 EXPECT
165 Use of uninitialized value $b in scalar chop at - line 7.
166 Use of uninitialized value $b in scalar chop at - line 9.
167 ########
168
169 # Check scope of pragma with eval
170 no warnings;
171 {
172     use warnings 'uninitialized' ;
173     eval {
174         no warnings ;
175         my $b ; chop $b ;
176     }; print STDERR $@ ;
177     my $b ; chop $b ;
178 }
179 EXPECT
180 Use of uninitialized value $b in scalar chop at - line 10.
181 ########
182
183 # Check scope of pragma with eval
184 use warnings;
185 {
186     no warnings ;
187     eval {
188         my $a =+ 1 ;
189     }; print STDERR $@ ;
190     my $a =+ 1 ;
191 }
192 EXPECT
193
194 ########
195
196 # Check scope of pragma with eval
197 use warnings;
198 {
199     no warnings ;
200     eval {
201         use warnings 'syntax' ;
202         my $a =+ 1 ;
203     }; print STDERR $@ ;
204     my $a =+ 1 ;
205 }
206 EXPECT
207 Reversed += operator at - line 8.
208 ########
209
210 # Check scope of pragma with eval
211 no warnings;
212 {
213     use warnings 'syntax' ;
214     eval {
215         my $a =+ 1 ;
216     }; print STDERR $@ ;
217     my $a =+ 1 ;
218 }
219 EXPECT
220 Reversed += operator at - line 7.
221 Reversed += operator at - line 9.
222 ########
223
224 # Check scope of pragma with eval
225 no warnings;
226 {
227     use warnings 'syntax' ;
228     eval {
229         no warnings ;
230         my $a =+ 1 ;
231     }; print STDERR $@ ;
232     my $a =+ 1 ;
233 }
234 EXPECT
235 Reversed += operator at - line 10.
236 ########
237
238 # Check scope of pragma with eval
239 use warnings;
240 {
241     no warnings ;
242     eval '
243         my $b ; chop $b ;
244     '; print STDERR $@ ;
245     my $b ; chop $b ;
246 }
247 EXPECT
248
249 ########
250
251 # Check scope of pragma with eval
252 use warnings;
253 {
254     no warnings ;
255     eval q[ 
256         use warnings 'uninitialized' ;
257         my $b ; chop $b ;
258     ]; print STDERR $@;
259     my $b ; chop $b ;
260 }
261 EXPECT
262 Use of uninitialized value $b in scalar chop at (eval 1) line 3.
263 ########
264
265 # Check scope of pragma with eval
266 no warnings;
267 {
268     use warnings 'uninitialized' ;
269     eval '
270         my $b ; chop $b ;
271     '; print STDERR $@ ;
272     my $b ; chop $b ;
273 }
274 EXPECT
275 Use of uninitialized value $b in scalar chop at (eval 1) line 2.
276 Use of uninitialized value $b in scalar chop at - line 9.
277 ########
278
279 # Check scope of pragma with eval
280 no warnings;
281 {
282     use warnings 'uninitialized' ;
283     eval '
284         no warnings ;
285         my $b ; chop $b ;
286     '; print STDERR $@ ;
287     my $b ; chop $b ;
288 }
289 EXPECT
290 Use of uninitialized value $b in scalar chop at - line 10.
291 ########
292
293 # Check scope of pragma with eval
294 use warnings;
295 {
296     no warnings ;
297     eval '
298         my $a =+ 1 ;
299     '; print STDERR $@ ;
300     my $a =+ 1 ;
301 }
302 EXPECT
303
304 ########
305
306 # Check scope of pragma with eval
307 use warnings;
308 {
309     no warnings ;
310     eval q[ 
311         use warnings 'syntax' ;
312         my $a =+ 1 ;
313     ]; print STDERR $@;
314     my $a =+ 1 ;
315 }
316 EXPECT
317 Reversed += operator at (eval 1) line 3.
318 ########
319
320 # Check scope of pragma with eval
321 no warnings;
322 {
323     use warnings 'syntax' ;
324     eval '
325         my $a =+ 1 ;
326     '; print STDERR $@;
327     my $a =+ 1 ;
328 }
329 EXPECT
330 Reversed += operator at - line 9.
331 Reversed += operator at (eval 1) line 2.
332 ########
333
334 # Check scope of pragma with eval
335 no warnings;
336 {
337     use warnings 'syntax' ;
338     eval '
339         no warnings ;
340         my $a =+ 1 ;
341     '; print STDERR $@;
342     my $a =+ 1 ;
343 }
344 EXPECT
345 Reversed += operator at - line 10.
346 ########
347
348 # Check the additive nature of the pragma
349 my $a =+ 1 ;
350 my $a ; chop $a ;
351 use warnings 'syntax' ;
352 $a =+ 1 ;
353 my $b ; chop $b ;
354 use warnings 'uninitialized' ;
355 my $c ; chop $c ;
356 no warnings 'syntax' ;
357 $a =+ 1 ;
358 EXPECT
359 Reversed += operator at - line 6.
360 Use of uninitialized value $c in scalar chop at - line 9.
361 ########
362
363 # Check that deprecation warnings are not implicitly disabled by use
364 $*;
365 use warnings "void";
366 $#;
367 EXPECT
368 $* is no longer supported. Its use will be fatal in Perl 5.30 at - line 3.
369 $# is no longer supported. Its use will be fatal in Perl 5.30 at - line 5.
370 Useless use of a variable in void context at - line 5.
371 ########
372
373 # Check that deprecation warnings are not implicitly disabled by no
374 $*;
375 no warnings "void";
376 $#;
377 EXPECT
378 $* is no longer supported. Its use will be fatal in Perl 5.30 at - line 3.
379 $# is no longer supported. Its use will be fatal in Perl 5.30 at - line 5.