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