1Check FATAL functionality
2
3__END__
4
5# Check compile time warning
6use warnings FATAL => 'syntax' ;
7{
8    no warnings ;
9    $a =+ 1 ;
10}
11$a =+ 1 ;
12print STDERR "The End.\n" ;
13EXPECT
14Reversed += operator at - line 8.
15########
16
17# Check compile time warning
18use warnings FATAL => 'all' ;
19{
20    no warnings ;
21    my $a =+ 1 ;
22}
23my $a =+ 1 ;
24print STDERR "The End.\n" ;
25EXPECT
26Reversed += operator at - line 8.
27########
28
29# Check runtime scope of pragma
30use warnings FATAL => 'uninitialized' ;
31{
32    no warnings ;
33    my $b ; chop $b ;
34}
35my $b ; chop $b ;
36print STDERR "The End.\n" ;
37EXPECT
38Use of uninitialized value $b in scalar chop at - line 8.
39########
40
41# Check runtime scope of pragma
42use warnings FATAL => 'all' ;
43{
44    no warnings ;
45    my $b ; chop $b ;
46}
47my $b ; chop $b ;
48print STDERR "The End.\n" ;
49EXPECT
50Use of uninitialized value $b in scalar chop at - line 8.
51########
52
53# Check runtime scope of pragma
54no warnings ;
55{
56    use warnings FATAL => 'uninitialized' ;
57    $a = sub { my $b ; chop $b ; }
58}
59&$a ;
60print STDERR "The End.\n" ;
61EXPECT
62Use of uninitialized value $b in scalar chop at - line 6.
63########
64
65# Check runtime scope of pragma
66no warnings ;
67{
68    use warnings FATAL => 'all' ;
69    $a = sub { my $b ; chop $b ; }
70}
71&$a ;
72print STDERR "The End.\n" ;
73EXPECT
74Use of uninitialized value $b in scalar chop at - line 6.
75########
76
77--FILE-- abc
78$a =+ 1 ;
791;
80--FILE--
81use warnings FATAL => 'syntax' ;
82require "./abc";
83EXPECT
84
85########
86
87--FILE-- abc
88use warnings FATAL => 'syntax' ;
891;
90--FILE--
91require "./abc";
92$a =+ 1 ;
93EXPECT
94
95########
96
97--FILE-- abc
98use warnings 'syntax' ;
99$a =+ 1 ;
1001;
101--FILE--
102use warnings FATAL => 'uninitialized' ;
103require "./abc";
104my $a ; chop $a ;
105print STDERR "The End.\n" ;
106EXPECT
107Reversed += operator at ./abc line 2.
108Use of uninitialized value $a in scalar chop at - line 3.
109########
110
111--FILE-- abc.pm
112use warnings 'syntax' ;
113$a =+ 1 ;
1141;
115--FILE--
116use warnings FATAL => 'uninitialized' ;
117use abc;
118my $a ; chop $a ;
119print STDERR "The End.\n" ;
120EXPECT
121Reversed += operator at abc.pm line 2.
122Use of uninitialized value $a in scalar chop at - line 3.
123########
124
125# Check scope of pragma with eval
126no warnings ;
127eval {
128    use warnings FATAL => 'uninitialized' ;
129    my $b ; chop $b ;
130}; print STDERR "-- $@" ;
131my $b ; chop $b ;
132print STDERR "The End.\n" ;
133EXPECT
134-- Use of uninitialized value $b in scalar chop at - line 6.
135The End.
136########
137
138# Check scope of pragma with eval
139use warnings FATAL => 'uninitialized' ;
140eval {
141    my $b ; chop $b ;
142}; print STDERR "-- $@" ;
143my $b ; chop $b ;
144print STDERR "The End.\n" ;
145EXPECT
146-- Use of uninitialized value $b in scalar chop at - line 5.
147Use of uninitialized value $b in scalar chop at - line 7.
148########
149
150# Check scope of pragma with eval
151use warnings FATAL => 'uninitialized' ;
152eval {
153    no warnings ;
154    my $b ; chop $b ;
155}; print STDERR $@ ;
156my $b ; chop $b ;
157print STDERR "The End.\n" ;
158EXPECT
159Use of uninitialized value $b in scalar chop at - line 8.
160########
161
162# Check scope of pragma with eval
163no warnings ;
164eval {
165    use warnings FATAL => 'syntax' ;
166    $a =+ 1 ;
167}; print STDERR "-- $@" ;
168$a =+ 1 ;
169print STDERR "The End.\n" ;
170EXPECT
171Reversed += operator at - line 6.
172########
173
174# Check scope of pragma with eval
175use warnings FATAL => 'syntax' ;
176eval {
177    $a =+ 1 ;
178}; print STDERR "-- $@" ;
179$a =+ 1 ;
180print STDERR "The End.\n" ;
181EXPECT
182Reversed += operator at - line 5.
183########
184
185# Check scope of pragma with eval
186use warnings FATAL => 'syntax' ;
187eval {
188    no warnings ;
189    $a =+ 1 ;
190}; print STDERR $@ ;
191$a =+ 1 ;
192print STDERR "The End.\n" ;
193EXPECT
194Reversed += operator at - line 8.
195########
196
197# Check scope of pragma with eval
198no warnings ;
199eval {
200    use warnings FATAL => 'syntax' ;
201}; print STDERR $@ ;
202$a =+ 1 ;
203print STDERR "The End.\n" ;
204EXPECT
205The End.
206########
207
208# Check scope of pragma with eval
209no warnings ;
210eval q[
211    use warnings FATAL => 'uninitialized' ;
212    my $b ; chop $b ;
213]; print STDERR "-- $@";
214my $b ; chop $b ;
215print STDERR "The End.\n" ;
216EXPECT
217-- Use of uninitialized value $b in scalar chop at (eval 1) line 3.
218The End.
219########
220
221# Check scope of pragma with eval
222use warnings FATAL => 'uninitialized' ;
223eval '
224    my $b ; chop $b ;
225'; print STDERR "-- $@" ;
226my $b ; chop $b ;
227print STDERR "The End.\n" ;
228EXPECT
229-- Use of uninitialized value $b in scalar chop at (eval 1) line 2.
230Use of uninitialized value $b in scalar chop at - line 7.
231########
232
233# Check scope of pragma with eval
234use warnings FATAL => 'uninitialized' ;
235eval '
236    no warnings ;
237    my $b ; chop $b ;
238'; print STDERR $@ ;
239my $b ; chop $b ;
240print STDERR "The End.\n" ;
241EXPECT
242Use of uninitialized value $b in scalar chop at - line 8.
243########
244
245# Check scope of pragma with eval
246no warnings ;
247eval q[
248    use warnings FATAL => 'syntax' ;
249    $a =+ 1 ;
250]; print STDERR "-- $@";
251$a =+ 1 ;
252print STDERR "The End.\n" ;
253EXPECT
254-- Reversed += operator at (eval 1) line 3.
255The End.
256########
257
258# Check scope of pragma with eval
259use warnings FATAL => 'syntax' ;
260eval '
261    $a =+ 1 ;
262'; print STDERR "-- $@";
263print STDERR "The End.\n" ;
264EXPECT
265-- Reversed += operator at (eval 1) line 2.
266The End.
267########
268
269# Check scope of pragma with eval
270use warnings FATAL => 'syntax' ;
271eval '
272    no warnings ;
273    $a =+ 1 ;
274'; print STDERR "-- $@";
275$a =+ 1 ;
276print STDERR "The End.\n" ;
277EXPECT
278Reversed += operator at - line 8.
279########
280# TODO ? !$Config{usethreads} && $::UTF8 && ($ENV{PERL_DESTRUCT_LEVEL} || 0) > 1 ? "Parser leaks OPs, which leak shared hash keys" : ''
281
282use warnings 'void' ;
283
284time ;
285
286{
287    use warnings FATAL => qw(void) ;
288    $a = "abc";
289    length $a ;
290}
291
292join "", 1,2,3 ;
293
294print "done\n" ;
295EXPECT
296Useless use of time in void context at - line 4.
297Useless use of length in void context at - line 9.
298########
299# TODO ? !$Config{usethreads} && $::UTF8 && ($ENV{PERL_DESTRUCT_LEVEL} || 0) > 1 ? "Parser leaks OPs, which leak shared hash keys" : ''
300
301use warnings ;
302
303time ;
304
305{
306    use warnings FATAL => qw(void) ;
307    $a = "abc";
308    length $a ;
309}
310
311join "", 1,2,3 ;
312
313print "done\n" ;
314EXPECT
315Useless use of time in void context at - line 4.
316Useless use of length in void context at - line 9.
317########
318
319use warnings FATAL => 'all';
320{
321    no warnings;
322    my $b ; chop $b;
323    {
324        use warnings ;
325        my $b ; chop $b;
326    }
327}
328my $b ; chop $b;
329print STDERR "The End.\n" ;
330EXPECT
331Use of uninitialized value $b in scalar chop at - line 8.
332Use of uninitialized value $b in scalar chop at - line 11.
333########
334
335use warnings FATAL => 'all';
336{
337    no warnings FATAL => 'all';
338    my $b ; chop $b;
339    {
340        use warnings ;
341        my $b ; chop $b;
342    }
343}
344my $b ; chop $b;
345print STDERR "The End.\n" ;
346EXPECT
347Use of uninitialized value $b in scalar chop at - line 8.
348Use of uninitialized value $b in scalar chop at - line 11.
349########
350
351use warnings FATAL => 'all';
352{
353    no warnings 'syntax';
354    {
355        use warnings ;
356        my $b ; chop $b;
357    }
358}
359my $b ; chop $b;
360print STDERR "The End.\n" ;
361EXPECT
362Use of uninitialized value $b in scalar chop at - line 7.
363########
364
365use warnings FATAL => 'syntax', NONFATAL => 'void' ;
366
367$a = "abc";
368length $a;
369print STDERR "The End.\n" ;
370EXPECT
371Useless use of length in void context at - line 5.
372The End.
373########
374
375use warnings FATAL => 'all', NONFATAL => 'void' ;
376
377$a = "abc";
378length $a;
379print STDERR "The End.\n" ;
380EXPECT
381Useless use of length in void context at - line 5.
382The End.
383########
384
385use warnings FATAL => 'all', NONFATAL => 'void' ;
386
387my $a ; chomp $a;
388
389$b = "abc" ;
390length $b;
391print STDERR "The End.\n" ;
392EXPECT
393Useless use of length in void context at - line 7.
394Use of uninitialized value $a in scalar chomp at - line 4.
395########
396
397use warnings FATAL => 'void', NONFATAL => 'void' ;
398$a = "abc";
399length $a;
400print STDERR "The End.\n" ;
401EXPECT
402Useless use of length in void context at - line 4.
403The End.
404########
405# TODO ? !$Config{usethreads} && $::UTF8 && ($ENV{PERL_DESTRUCT_LEVEL} || 0) > 1 ? "Parser leaks OPs, which leak shared hash keys" : ''
406
407use warnings NONFATAL => 'void', FATAL => 'void' ;
408$a = "abc";
409length $a;
410print STDERR "The End.\n" ;
411EXPECT
412Useless use of length in void context at - line 4.
413########
414
415use warnings FATAL => 'all', NONFATAL => 'io';
416no warnings 'once';
417
418open(F, "<true\ncd");
419open(G, "<truecd\n");
420open(H, "<truecd\n\0");
421close "fred" ;
422print STDERR "The End.\n" ;
423EXPECT
424Unsuccessful open on filename containing newline at - line 6.
425Unsuccessful open on filename containing newline at - line 7.
426close() on unopened filehandle fred at - line 8.
427The End.
428########
429
430use warnings FATAL => 'all', NONFATAL => 'io', FATAL => 'unopened' ;
431no warnings 'once';
432
433open(F, "<truecd\n");
434close "fred" ;
435print STDERR "The End.\n" ;
436EXPECT
437Unsuccessful open on filename containing newline at - line 5.
438close() on unopened filehandle fred at - line 6.
439########
440
441# 'use warnings' test as the basis for the following tests
442use warnings ;
443my $a = oct "7777777777777777777777777777777777778" ;
444my $b =+ 1 ;
445my $c ; chop $c ;
446print STDERR "The End.\n" ;
447EXPECT
448Reversed += operator at - line 5.
449Integer overflow in octal number at - line 4.
450Illegal octal digit '8' ignored at - line 4.
451Octal number > 037777777777 non-portable at - line 4.
452Use of uninitialized value $c in scalar chop at - line 6.
453The End.
454########
455
456# 'use warnings NONFATAL=>"all"' should be the same as 'use warnings'
457use warnings NONFATAL=>"all" ;
458my $a = oct "7777777777777777777777777777777777778" ;
459my $b =+ 1 ;
460my $c ; chop $c ;
461print STDERR "The End.\n" ;
462EXPECT
463Reversed += operator at - line 5.
464Integer overflow in octal number at - line 4.
465Illegal octal digit '8' ignored at - line 4.
466Octal number > 037777777777 non-portable at - line 4.
467Use of uninitialized value $c in scalar chop at - line 6.
468The End.
469########
470
471# 'use warnings "NONFATAL"' should be the same as 'use warnings' [perl #120977]
472use warnings "NONFATAL" ;
473my $a = oct "7777777777777777777777777777777777778" ;
474my $b =+ 1 ;
475my $c ; chop $c ;
476print STDERR "The End.\n" ;
477EXPECT
478Reversed += operator at - line 5.
479Integer overflow in octal number at - line 4.
480Illegal octal digit '8' ignored at - line 4.
481Octal number > 037777777777 non-portable at - line 4.
482Use of uninitialized value $c in scalar chop at - line 6.
483The End.
484########
485
486# 'use warnings "FATAL"' should be the same as 'use warnings FATAL=>"all"' [perl #120977]
487use warnings "FATAL" ;
488{
489    no warnings ;
490    my $a =+ 1 ;
491}
492my $a =+ 1 ;
493print STDERR "The End.\n" ;
494EXPECT
495Reversed += operator at - line 8.
496########
497
498# 'use warnings "FATAL"' should be the same as 'use warnings FATAL=>"all"' [perl #120977]
499use warnings "FATAL" ;
500{
501    no warnings ;
502    my $a = oct "7777777777777777777777777777777777778" ;
503}
504my $a = oct "7777777777777777777777777777777777778" ;
505print STDERR "The End.\n" ;
506EXPECT
507Integer overflow in octal number at - line 8.
508########
509
510# 'no warnings FATAL=>"all"' should be the same as 'no warnings'
511use warnings ;
512{
513    no warnings FATAL=>"all" ;
514    my $a = oct "7777777777777777777777777777777777778" ;
515    my $b =+ 1 ;
516    my $c ; chop $c ;
517}
518my $a =+ 1 ;
519print STDERR "The End.\n" ;
520EXPECT
521Reversed += operator at - line 10.
522The End.
523########
524
525# 'no warnings "FATAL"' should be the same as 'no warnings' [perl #120977]
526use warnings ;
527{
528    no warnings "FATAL" ;
529    my $a = oct "7777777777777777777777777777777777778" ;
530    my $b =+ 1 ;
531    my $c ; chop $c ;
532}
533my $a =+ 1 ;
534print STDERR "The End.\n" ;
535EXPECT
536Reversed += operator at - line 10.
537The End.
538########
539
540# fatal warnings shouldn't hide parse errors [perl #122966]
541use warnings FATAL => 'all';
542if (1 {
543    my $x = "hello";
544    print $x, "\n";
545}
546EXPECT
547syntax error at - line 4, near "1 {"
548"my" variable $x masks earlier declaration in same statement at - line 6.
549syntax error at - line 7, near "}"
550Execution of - aborted due to compilation errors.
551########
552
553# fatal warnings in DESTROY should be made non-fatal [perl #123398]
554# This test will blow up your memory with SEGV without the patch
555package Foo;
556use strict; use utf8; use warnings FATAL => 'all';
557sub new {
558    return bless{ 'field' => undef }, 'Foo';
559}
560sub DESTROY {
561    my $self = shift;
562    $self->{'field'}->missing_method;
563}
564package main;
565my $foo = new Foo;
566undef($foo);
567EXPECT
568	(in cleanup) Can't call method "missing_method" on an undefined value at - line 11.
569