integrate mainline changes
[p5sagit/p5-mst-13.2.git] / t / pragma / warn / pp_hot
1   pp_hot.c      
2
3   Filehandle %s never opened                    [pp_print]
4     $f = $a = "abc" ; print $f $a
5
6   Filehandle %s opened only for input           [pp_print]
7     print STDIN "abc" ;
8
9   Filehandle %s opened only for output          [pp_print]
10     print <STDOUT> ;
11
12   print on closed filehandle %s                 [pp_print]
13     close STDIN ; print STDIN "abc" ;
14
15   uninitialized                                 [pp_rv2av]
16         my $a = undef ; my @b = @$a
17
18   uninitialized                                 [pp_rv2hv]
19         my $a = undef ; my %b = %$a
20
21   Odd number of elements in hash list           [pp_aassign]
22         %X = (1,2,3) ;
23
24   Reference found where even-sized list expected [pp_aassign]
25         $X = [ 1 ..3 ];
26
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
33   Read on closed filehandle %s                  [Perl_do_readline]
34     close STDIN ; $a = <STDIN>;
35
36   glob failed (child exited with status %d%s)   [Perl_do_readline] <<TODO
37
38   Deep recursion on subroutine \"%s\"           [Perl_sub_crush_depth]
39     sub fred { fred() if $a++ < 200} fred()
40
41   Deep recursion on anonymous subroutine        [Perl_sub_crush_depth]
42     $a = sub { &$a if $a++ < 200} &$a
43
44   Possible Y2K bug: about to append an integer to '19' [pp_concat]
45     $x     = "19$yy\n";
46
47 __END__
48 # pp_hot.c [pp_print]
49 use warnings 'unopened' ;
50 $f = $a = "abc" ; 
51 print $f $a;
52 no warnings 'unopened' ;
53 print $f $a;
54 EXPECT
55 Filehandle main::abc never opened at - line 4.
56 ########
57 # pp_hot.c [pp_print]
58 use warnings 'io' ;
59 print STDIN "anc";
60 print <STDOUT>;
61 print <STDERR>;
62 open(FOO, ">&STDOUT") and print <FOO>;
63 print getc(STDERR);
64 print getc(FOO);
65 ####################################################################
66 # The next test is known to fail on some systems (Linux/BSD+glibc, #
67 # NeXT among others.  glibc should be fixed in the next version,   #
68 # but it appears other platforms have little hope.  We skip it for #
69 # now (on the grounds that it is "just" a warning).                #
70 ####################################################################
71 #read(FOO,$_,1);
72 no warnings 'io' ;
73 print STDIN "anc";
74 EXPECT
75 Filehandle main::STDIN opened only for input at - line 3.
76 Filehandle main::STDOUT opened only for output at - line 4.
77 Filehandle main::STDERR opened only for output at - line 5.
78 Filehandle main::FOO opened only for output at - line 6.
79 Filehandle main::STDERR opened only for output at - line 7.
80 Filehandle main::FOO opened only for output at - line 8.
81 ########
82 # pp_hot.c [pp_print]
83 use warnings 'closed' ;
84 close STDIN ;
85 print STDIN "anc";
86 no warnings 'closed' ;
87 print STDIN "anc";
88 EXPECT
89 print on closed filehandle main::STDIN at - line 4.
90 ########
91 # pp_hot.c [pp_rv2av]
92 use warnings 'uninitialized' ;
93 my $a = undef ;
94 my @b = @$a;
95 no warnings 'uninitialized' ;
96 my @c = @$a;
97 EXPECT
98 Use of uninitialized value in array dereference at - line 4.
99 ########
100 # pp_hot.c [pp_rv2hv]
101 use warnings 'uninitialized' ;
102 my $a = undef ;
103 my %b = %$a;
104 no warnings 'uninitialized' ;
105 my %c = %$a;
106 EXPECT
107 Use of uninitialized value in hash dereference at - line 4.
108 ########
109 # pp_hot.c [pp_aassign]
110 use warnings 'unsafe' ;
111 my %X ; %X = (1,2,3) ;
112 no warnings 'unsafe' ;
113 my %Y ; %Y = (1,2,3) ;
114 EXPECT
115 Odd number of elements in hash assignment at - line 3.
116 ########
117 # pp_hot.c [pp_aassign]
118 use warnings 'unsafe' ;
119 my %X ; %X = [1 .. 3] ;
120 no warnings 'unsafe' ;
121 my %Y ; %Y = [1 .. 3] ;
122 EXPECT
123 Reference found where even-sized list expected at - line 3.
124 ########
125 # pp_hot.c [Perl_do_readline]
126 use warnings 'closed' ;
127 close STDIN ; $a = <STDIN> ;
128 no warnings 'closed' ;
129 $a = <STDIN> ;
130 EXPECT
131 Read on closed filehandle main::STDIN at - line 3.
132 ########
133 # pp_hot.c [Perl_do_readline]
134 use warnings 'io' ;
135 my $file = "./xcv" ; unlink $file ;
136 open (FH, ">./xcv") ;
137 my $a = <FH> ;
138 no warnings 'io' ;
139 $a = <FH> ;
140 unlink $file ;
141 EXPECT
142 Filehandle main::FH opened only for output at - line 5.
143 ########
144 # pp_hot.c [Perl_sub_crush_depth]
145 use warnings 'recursion' ;
146 sub fred 
147
148     fred() if $a++ < 200
149
150 {
151   local $SIG{__WARN__} = sub {
152     die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
153   };
154   fred();
155 }
156 EXPECT
157 ok
158 ########
159 # pp_hot.c [Perl_sub_crush_depth]
160 no warnings 'recursion' ;
161 sub fred 
162
163     fred() if $a++ < 200
164
165 {
166   local $SIG{__WARN__} = sub {
167     die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
168   };
169   fred();
170 }
171 EXPECT
172
173 ########
174 # pp_hot.c [Perl_sub_crush_depth]
175 use warnings 'recursion' ;
176 $b = sub 
177
178     &$b if $a++ < 200
179 }  ;
180
181 &$b ;
182 EXPECT
183 Deep recursion on anonymous subroutine at - line 5.
184 ########
185 # pp_hot.c [Perl_sub_crush_depth]
186 no warnings 'recursion' ;
187 $b = sub 
188
189     &$b if $a++ < 200
190 }  ;
191
192 &$b ;
193 EXPECT
194 ########
195 # pp_hot.c [pp_concat]
196 use warnings 'misc';
197 use Config;
198 BEGIN {
199     unless ($Config{ccflags} =~ /Y2KWARN/) {
200         print "SKIPPED\n# perl not built with -DPERL_Y2KWARN";
201         exit 0;
202     }
203 }
204 my $x;
205 my $yy = 78;
206 $x     = "19$yy\n";
207 $x     = "19" . $yy . "\n";
208 $x     = "319$yy\n";
209 $x     = "319" . $yy . "\n";
210 no warnings 'misc';
211 $x     = "19$yy\n";
212 $x     = "19" . $yy . "\n";
213 EXPECT
214 Possible Y2K bug: about to append an integer to '19' at - line 12.
215 Possible Y2K bug: about to append an integer to '19' at - line 13.