RE: mixing FATAL and non-FATAL warnings
[p5sagit/p5-mst-13.2.git] / t / lib / warnings / pp_hot
CommitLineData
767a6a26 1 pp_hot.c
599cee73 2
2dd78f96 3 print() on unopened filehandle abc [pp_print]
599cee73 4 $f = $a = "abc" ; print $f $a
5
767a6a26 6 Filehandle %s opened only for input [pp_print]
599cee73 7 print STDIN "abc" ;
8
767a6a26 9 Filehandle %s opened only for output [pp_print]
977289e4 10 $a = <STDOUT> ;
599cee73 11
9a7dcd9c 12 print() on closed filehandle %s [pp_print]
599cee73 13 close STDIN ; print STDIN "abc" ;
14
767a6a26 15 uninitialized [pp_rv2av]
599cee73 16 my $a = undef ; my @b = @$a
17
767a6a26 18 uninitialized [pp_rv2hv]
599cee73 19 my $a = undef ; my %b = %$a
20
767a6a26 21 Odd number of elements in hash list [pp_aassign]
599cee73 22 %X = (1,2,3) ;
23
767a6a26 24 Reference found where even-sized list expected [pp_aassign]
599cee73 25 $X = [ 1 ..3 ];
26
767a6a26 27 Filehandle %s opened only for output [Perl_do_readline]
28 open (FH, ">./xcv") ;
29 my $a = <FH> ;
30
31 glob failed (can't start child: %s) [Perl_do_readline] <<TODO
32
9a7dcd9c 33 readline() on closed filehandle %s [Perl_do_readline]
599cee73 34 close STDIN ; $a = <STDIN>;
35
790090df 36 readline() on closed filehandle %s [Perl_do_readline]
37 readline(NONESUCH);
38
767a6a26 39 glob failed (child exited with status %d%s) [Perl_do_readline] <<TODO
40
41 Deep recursion on subroutine \"%s\" [Perl_sub_crush_depth]
6bc102ca 42 sub fred { fred() if $a++ < 200} fred()
599cee73 43
767a6a26 44 Deep recursion on anonymous subroutine [Perl_sub_crush_depth]
6bc102ca 45 $a = sub { &$a if $a++ < 200} &$a
599cee73 46
6bc102ca 47 Possible Y2K bug: about to append an integer to '19' [pp_concat]
48 $x = "19$yy\n";
767a6a26 49
d804643f 50 Use of reference "%s" as array index [pp_aelem]
51 $x[\1]
52
599cee73 53__END__
767a6a26 54# pp_hot.c [pp_print]
4438c4b7 55use warnings 'unopened' ;
599cee73 56$f = $a = "abc" ;
0453d815 57print $f $a;
4438c4b7 58no warnings 'unopened' ;
0453d815 59print $f $a;
599cee73 60EXPECT
2dd78f96 61print() on unopened filehandle abc at - line 4.
599cee73 62########
767a6a26 63# pp_hot.c [pp_print]
4438c4b7 64use warnings 'io' ;
977289e4 65# There is no guarantee that STDOUT is output only, or STDIN input only.
66# Certainly on some BSDs (at least FreeBSD, Darwin, BSDi) file descriptors
67# 1 and 2 are opened read/write on the tty, and the IO layers may reflect this.
68# So we must make our own file handle that is read only.
69my $file = "./xcv" ; unlink $file ;
70open (FH, ">$file") or die $! ;
71close FH or die $! ;
72die "There is no file $file" unless -f $file ;
73open (FH, "<$file") or die $! ;
74print FH "anc" ;
75open(FOO, "<&FH") or die $! ;
76print FOO "anc" ;
37bd1396 77no warnings 'io' ;
977289e4 78print FH "anc" ;
79print FOO "anc" ;
80use warnings 'io' ;
81print FH "anc" ;
82print FOO "anc" ;
83close (FH) or die $! ;
84close (FOO) or die $! ;
85unlink $file ;
599cee73 86EXPECT
977289e4 87Filehandle FH opened only for input at - line 12.
88Filehandle FOO opened only for input at - line 14.
89Filehandle FH opened only for input at - line 19.
90Filehandle FOO opened only for input at - line 20.
599cee73 91########
767a6a26 92# pp_hot.c [pp_print]
4438c4b7 93use warnings 'closed' ;
599cee73 94close STDIN ;
95print STDIN "anc";
69282e91 96opendir STDIN, ".";
97print STDIN "anc";
98closedir STDIN;
4438c4b7 99no warnings 'closed' ;
0453d815 100print STDIN "anc";
69282e91 101opendir STDIN, ".";
102print STDIN "anc";
599cee73 103EXPECT
43693395 104print() on closed filehandle STDIN at - line 4.
105print() on closed filehandle STDIN at - line 6.
106 (Are you trying to call print() on dirhandle STDIN?)
599cee73 107########
f55e507d 108# pp_hot.c [pp_print]
109# [ID 20020425.012] from Dave Steiner <steiner@bakerst.rutgers.edu>
110# This goes segv on 5.7.3
111use warnings 'closed' ;
112my $fh = *STDOUT{IO};
113close STDOUT or die "Can't close STDOUT";
114print $fh "Shouldn't print anything, but shouldn't SEGV either\n";
115EXPECT
116print() on closed filehandle at - line 7.
117########
f62cb720 118# pp_hot.c [pp_print]
119package foo;
120use warnings 'closed';
121open my $fh1, "nonexistent";
122print $fh1 42;
123open $fh2, "nonexistent";
124print $fh2 42;
125open $bar::fh3, "nonexistent";
126print $bar::fh3 42;
127open bar::FH4, "nonexistent";
128print bar::FH4 42;
129EXPECT
130print() on closed filehandle $fh1 at - line 5.
131print() on closed filehandle $fh2 at - line 7.
132print() on closed filehandle $fh3 at - line 9.
133print() on closed filehandle FH4 at - line 11.
134########
767a6a26 135# pp_hot.c [pp_rv2av]
4438c4b7 136use warnings 'uninitialized' ;
599cee73 137my $a = undef ;
0453d815 138my @b = @$a;
4438c4b7 139no warnings 'uninitialized' ;
0453d815 140my @c = @$a;
599cee73 141EXPECT
b89fed5f 142Use of uninitialized value in array dereference at - line 4.
599cee73 143########
767a6a26 144# pp_hot.c [pp_rv2hv]
4438c4b7 145use warnings 'uninitialized' ;
599cee73 146my $a = undef ;
0453d815 147my %b = %$a;
4438c4b7 148no warnings 'uninitialized' ;
0453d815 149my %c = %$a;
599cee73 150EXPECT
b89fed5f 151Use of uninitialized value in hash dereference at - line 4.
599cee73 152########
767a6a26 153# pp_hot.c [pp_aassign]
e476b1b5 154use warnings 'misc' ;
599cee73 155my %X ; %X = (1,2,3) ;
e476b1b5 156no warnings 'misc' ;
0453d815 157my %Y ; %Y = (1,2,3) ;
599cee73 158EXPECT
159Odd number of elements in hash assignment at - line 3.
160########
767a6a26 161# pp_hot.c [pp_aassign]
e476b1b5 162use warnings 'misc' ;
599cee73 163my %X ; %X = [1 .. 3] ;
e476b1b5 164no warnings 'misc' ;
0453d815 165my %Y ; %Y = [1 .. 3] ;
599cee73 166EXPECT
167Reference found where even-sized list expected at - line 3.
168########
767a6a26 169# pp_hot.c [Perl_do_readline]
4438c4b7 170use warnings 'closed' ;
69282e91 171close STDIN ; $a = <STDIN> ;
172opendir STDIN, "." ; $a = <STDIN> ;
173closedir STDIN;
4438c4b7 174no warnings 'closed' ;
69282e91 175opendir STDIN, "." ; $a = <STDIN> ;
0453d815 176$a = <STDIN> ;
599cee73 177EXPECT
43693395 178readline() on closed filehandle STDIN at - line 3.
179readline() on closed filehandle STDIN at - line 4.
180 (Are you trying to call readline() on dirhandle STDIN?)
599cee73 181########
767a6a26 182# pp_hot.c [Perl_do_readline]
183use warnings 'io' ;
184my $file = "./xcv" ; unlink $file ;
977289e4 185open (FH, ">$file") or die $! ;
767a6a26 186my $a = <FH> ;
187no warnings 'io' ;
188$a = <FH> ;
977289e4 189use warnings 'io' ;
190open(FOO, ">&FH") or die $! ;
191$a = <FOO> ;
192no warnings 'io' ;
193$a = <FOO> ;
194use warnings 'io' ;
195$a = <FOO> ;
196$a = <FH> ;
197close (FH) or die $! ;
198close (FOO) or die $! ;
767a6a26 199unlink $file ;
200EXPECT
43693395 201Filehandle FH opened only for output at - line 5.
977289e4 202Filehandle FOO opened only for output at - line 10.
203Filehandle FOO opened only for output at - line 14.
204Filehandle FH opened only for output at - line 15.
767a6a26 205########
206# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 207use warnings 'recursion' ;
599cee73 208sub fred
209{
210 fred() if $a++ < 200
211}
4a925ff6 212{
213 local $SIG{__WARN__} = sub {
214 die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
215 };
216 fred();
217}
599cee73 218EXPECT
4a925ff6 219ok
599cee73 220########
767a6a26 221# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 222no warnings 'recursion' ;
0453d815 223sub fred
224{
225 fred() if $a++ < 200
226}
227{
228 local $SIG{__WARN__} = sub {
229 die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
230 };
231 fred();
232}
233EXPECT
234
235########
767a6a26 236# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 237use warnings 'recursion' ;
599cee73 238$b = sub
239{
240 &$b if $a++ < 200
241} ;
242
243&$b ;
244EXPECT
245Deep recursion on anonymous subroutine at - line 5.
0453d815 246########
767a6a26 247# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 248no warnings 'recursion' ;
0453d815 249$b = sub
250{
251 &$b if $a++ < 200
252} ;
253
254&$b ;
255EXPECT
6bc102ca 256########
257# pp_hot.c [pp_concat]
8d6d96c1 258use warnings 'uninitialized';
259my($x, $y);
260sub a { shift }
261a($x . "x"); # should warn once
262a($x . $y); # should warn twice
263$x .= $y; # should warn once
264$y .= $y; # should warn once
265EXPECT
266Use of uninitialized value in concatenation (.) or string at - line 5.
267Use of uninitialized value in concatenation (.) or string at - line 6.
268Use of uninitialized value in concatenation (.) or string at - line 6.
269Use of uninitialized value in concatenation (.) or string at - line 7.
270Use of uninitialized value in concatenation (.) or string at - line 8.
271########
272# pp_hot.c [pp_concat]
e476b1b5 273use warnings 'y2k';
6bc102ca 274use Config;
275BEGIN {
276 unless ($Config{ccflags} =~ /Y2KWARN/) {
277 print "SKIPPED\n# perl not built with -DPERL_Y2KWARN";
278 exit 0;
279 }
280}
281my $x;
282my $yy = 78;
283$x = "19$yy\n";
284$x = "19" . $yy . "\n";
285$x = "319$yy\n";
286$x = "319" . $yy . "\n";
777b0c87 287$yy = 19;
288$x = "ok $yy\n";
289$yy = 9;
290$x = 1 . $yy;
e476b1b5 291no warnings 'y2k';
6bc102ca 292$x = "19$yy\n";
293$x = "19" . $yy . "\n";
294EXPECT
295Possible Y2K bug: about to append an integer to '19' at - line 12.
296Possible Y2K bug: about to append an integer to '19' at - line 13.
d804643f 297########
298# pp_hot.c [pp_aelem]
299{
300use warnings 'misc';
301print $x[\1];
302}
303{
304no warnings 'misc';
305print $x[\1];
306}
307
308EXPECT
309OPTION regex
310Use of reference ".*" as array index at - line 4.
1f1cc344 311########
312# pp_hot.c [pp_aelem]
313package Foo;use overload q("") => sub {};package main;$a = bless {}, "Foo";
314$b = {};
315{
316use warnings 'misc';
317print $x[$a];
318print $x[$b];
319}
320{
321no warnings 'misc';
322print $x[$a];
323print $x[$b];
324}
325
326EXPECT
327OPTION regex
328Use of reference ".*" as array index at - line 7.