xref: /openbsd/gnu/usr.bin/perl/t/lib/warnings/2use (revision 5dea098c)
1Check lexical warnings functionality
2
3TODO
4  check that the warning hierarchy works.
5
6__END__
7
8#  check illegal category is caught
9use warnings 'this-should-never-be-a-warning-category' ;
10EXPECT
11Unknown warnings category 'this-should-never-be-a-warning-category' at - line 3.
12BEGIN failed--compilation aborted at - line 3.
13########
14
15# Check compile time scope of pragma
16use warnings 'syntax' ;
17{
18    no warnings ;
19    my $a =+ 1 ;
20}
21my $a =+ 1 ;
22EXPECT
23Reversed += operator at - line 8.
24########
25
26# Check compile time scope of pragma
27no warnings;
28{
29    use warnings 'syntax' ;
30    my $a =+ 1 ;
31}
32my $a =+ 1 ;
33EXPECT
34Reversed += operator at - line 6.
35########
36
37# Check runtime scope of pragma
38use warnings 'uninitialized' ;
39{
40    no warnings ;
41    my $b ; chop $b ;
42}
43my $b ; chop $b ;
44EXPECT
45Use of uninitialized value $b in scalar chop at - line 8.
46########
47
48# Check runtime scope of pragma
49no warnings ;
50{
51    use warnings 'uninitialized' ;
52    my $b ; chop $b ;
53}
54my $b ; chop $b ;
55EXPECT
56Use of uninitialized value $b in scalar chop at - line 6.
57########
58
59# Check runtime scope of pragma
60no warnings ;
61{
62    use warnings 'uninitialized' ;
63    $a = sub { my $b ; chop $b ; }
64}
65&$a ;
66EXPECT
67Use of uninitialized value $b in scalar chop at - line 6.
68########
69
70use warnings 'syntax' ;
71my $a =+ 1 ;
72EXPECT
73Reversed += operator at - line 3.
74########
75-w
76no warnings 'reserved' ;
77foo.bar;
78EXPECT
79Useless use of a constant ("foobar") in void context at - line 3.
80########
81
82# Check -negative import with no other args
83use warnings qw(-syntax);
84sub foo { 'foo' }
85my $a =+ 1 ;          # syntax:        shouldn't warn, it was never turned on
86*foo = sub { 'bar' }; # redefine:      shouldn't warn, it was never turned on
87$a = 'foo' . undef;   # uninitialized: shouldn't warn, it was never turned on
88EXPECT
89########
90
91# Check -negative import after turning all warnings on
92use warnings qw(all -syntax);
93sub foo { 'foo' }
94my $a =+ 1 ;          # syntax:        shouldn't warn, we've turned that off
95*foo = sub { 'bar' }; # redefine:      should warn, as there was an explicit 'all'
96$a = 'foo' . undef;   # uninitialized: should warn, as there was an explicit 'all'
97EXPECT
98Subroutine main::foo redefined at - line 6.
99Use of uninitialized value in concatenation (.) or string at - line 7.
100########
101
102# Check -negative import with an explicit import
103use warnings qw(redefine -syntax);
104sub foo { 'foo' }
105my $a =+ 1 ;          # syntax:        shouldn't warn, it was never turned on
106*foo = sub { 'bar' }; # redefine:      should warn, as there was an explicit 'redefine'
107$a = 'foo' . undef;   # uninitialized: shouldn't warn, as explicit 'redefine' means no implicit 'all'
108EXPECT
109Subroutine main::foo redefined at - line 6.
110########
111
112# Check multiple -negative imports
113use warnings qw(all -syntax -uninitialized);
114sub foo { 'foo' }
115my $a =+ 1 ;          # syntax:        shouldn't warn, we've turned that off
116*foo = sub { 'bar' }; # redefine:      should warn, as there was an explicit 'all'
117$a = 'foo' . undef;   # uninitialized: shouldn't warn, we've turned it off
118EXPECT
119Subroutine main::foo redefined at - line 6.
120########
121
122# Check mixed list of +ve and -ve imports
123use warnings qw(all -once -syntax parenthesis);
124sub foo { 'foo' }
125*foo = sub { 'bar' };  # redefined:   should warn, as it was turned on by 'all'
126my $a =+ 1 ;           # syntax:      shouldn't warn, we've turned that off
127my $foo, $bar = @_;    # parenthesis: should warn, as we turned that back on after disabling 'syntax'
128EXPECT
129Parentheses missing around "my" list at - line 7.
130Subroutine main::foo redefined at - line 5.
131########
132
133--FILE-- abc
134my $a =+ 1 ;
1351;
136--FILE--
137use warnings 'syntax' ;
138require "./abc";
139EXPECT
140
141########
142
143--FILE-- abc
144use warnings 'syntax' ;
1451;
146--FILE--
147require "./abc";
148my $a =+ 1 ;
149EXPECT
150
151########
152
153--FILE-- abc
154use warnings 'syntax' ;
155my $a =+ 1 ;
1561;
157--FILE--
158use warnings 'uninitialized' ;
159require "./abc";
160my $a ; chop $a ;
161EXPECT
162Reversed += operator at ./abc line 2.
163Use of uninitialized value $a in scalar chop at - line 3.
164########
165
166--FILE-- abc.pm
167use warnings 'syntax' ;
168my $a =+ 1 ;
1691;
170--FILE--
171use warnings 'uninitialized' ;
172use abc;
173my $a ; chop $a ;
174EXPECT
175Reversed += operator at abc.pm line 2.
176Use of uninitialized value $a in scalar chop at - line 3.
177########
178
179# Check scope of pragma with eval
180use warnings;
181{
182    no warnings ;
183    eval {
184        my $b ; chop $b ;
185    }; print STDERR $@ ;
186    my $b ; chop $b ;
187}
188EXPECT
189
190########
191
192# Check scope of pragma with eval
193use warnings;
194{
195    no warnings ;
196    eval {
197        use warnings 'uninitialized' ;
198        my $b ; chop $b ;
199    }; print STDERR $@ ;
200    my $b ; chop $b ;
201}
202EXPECT
203Use of uninitialized value $b in scalar chop at - line 8.
204########
205
206# Check scope of pragma with eval
207no warnings;
208{
209    use warnings 'uninitialized' ;
210    eval {
211        my $b ; chop $b ;
212    }; print STDERR $@ ;
213    my $b ; chop $b ;
214}
215EXPECT
216Use of uninitialized value $b in scalar chop at - line 7.
217Use of uninitialized value $b in scalar chop at - line 9.
218########
219
220# Check scope of pragma with eval
221no warnings;
222{
223    use warnings 'uninitialized' ;
224    eval {
225        no warnings ;
226        my $b ; chop $b ;
227    }; print STDERR $@ ;
228    my $b ; chop $b ;
229}
230EXPECT
231Use of uninitialized value $b in scalar chop at - line 10.
232########
233
234# Check scope of pragma with eval
235use warnings;
236{
237    no warnings ;
238    eval {
239        my $a =+ 1 ;
240    }; print STDERR $@ ;
241    my $a =+ 1 ;
242}
243EXPECT
244
245########
246
247# Check scope of pragma with eval
248use warnings;
249{
250    no warnings ;
251    eval {
252        use warnings 'syntax' ;
253        my $a =+ 1 ;
254    }; print STDERR $@ ;
255    my $a =+ 1 ;
256}
257EXPECT
258Reversed += operator at - line 8.
259########
260
261# Check scope of pragma with eval
262no warnings;
263{
264    use warnings 'syntax' ;
265    eval {
266        my $a =+ 1 ;
267    }; print STDERR $@ ;
268    my $a =+ 1 ;
269}
270EXPECT
271Reversed += operator at - line 7.
272Reversed += operator at - line 9.
273########
274
275# Check scope of pragma with eval
276no warnings;
277{
278    use warnings 'syntax' ;
279    eval {
280        no warnings ;
281        my $a =+ 1 ;
282    }; print STDERR $@ ;
283    my $a =+ 1 ;
284}
285EXPECT
286Reversed += operator at - line 10.
287########
288
289# Check scope of pragma with eval
290use warnings;
291{
292    no warnings ;
293    eval '
294        my $b ; chop $b ;
295    '; print STDERR $@ ;
296    my $b ; chop $b ;
297}
298EXPECT
299
300########
301
302# Check scope of pragma with eval
303use warnings;
304{
305    no warnings ;
306    eval q[
307        use warnings 'uninitialized' ;
308        my $b ; chop $b ;
309    ]; print STDERR $@;
310    my $b ; chop $b ;
311}
312EXPECT
313Use of uninitialized value $b in scalar chop at (eval 1) line 3.
314########
315
316# Check scope of pragma with eval
317no warnings;
318{
319    use warnings 'uninitialized' ;
320    eval '
321        my $b ; chop $b ;
322    '; print STDERR $@ ;
323    my $b ; chop $b ;
324}
325EXPECT
326Use of uninitialized value $b in scalar chop at (eval 1) line 2.
327Use of uninitialized value $b in scalar chop at - line 9.
328########
329
330# Check scope of pragma with eval
331no warnings;
332{
333    use warnings 'uninitialized' ;
334    eval '
335        no warnings ;
336        my $b ; chop $b ;
337    '; print STDERR $@ ;
338    my $b ; chop $b ;
339}
340EXPECT
341Use of uninitialized value $b in scalar chop at - line 10.
342########
343
344# Check scope of pragma with eval
345use warnings;
346{
347    no warnings ;
348    eval '
349        my $a =+ 1 ;
350    '; print STDERR $@ ;
351    my $a =+ 1 ;
352}
353EXPECT
354
355########
356
357# Check scope of pragma with eval
358use warnings;
359{
360    no warnings ;
361    eval q[
362        use warnings 'syntax' ;
363        my $a =+ 1 ;
364    ]; print STDERR $@;
365    my $a =+ 1 ;
366}
367EXPECT
368Reversed += operator at (eval 1) line 3.
369########
370
371# Check scope of pragma with eval
372no warnings;
373{
374    use warnings 'syntax' ;
375    eval '
376        my $a =+ 1 ;
377    '; print STDERR $@;
378    my $a =+ 1 ;
379}
380EXPECT
381Reversed += operator at - line 9.
382Reversed += operator at (eval 1) line 2.
383########
384
385# Check scope of pragma with eval
386no warnings;
387{
388    use warnings 'syntax' ;
389    eval '
390        no warnings ;
391        my $a =+ 1 ;
392    '; print STDERR $@;
393    my $a =+ 1 ;
394}
395EXPECT
396Reversed += operator at - line 10.
397########
398
399# Check the additive nature of the pragma
400my $a =+ 1 ;
401my $a ; chop $a ;
402use warnings 'syntax' ;
403$a =+ 1 ;
404my $b ; chop $b ;
405use warnings 'uninitialized' ;
406my $c ; chop $c ;
407no warnings 'syntax' ;
408$a =+ 1 ;
409EXPECT
410Reversed += operator at - line 6.
411Use of uninitialized value $c in scalar chop at - line 9.
412########
413