This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
partly fix perldiag regressions identified by Tom Christiansen
[perl5.git] / t / pragma / warn / pp_hot
CommitLineData
767a6a26 1 pp_hot.c
599cee73 2
767a6a26 3 Filehandle %s never opened [pp_print]
599cee73
PM
4 $f = $a = "abc" ; print $f $a
5
767a6a26 6 Filehandle %s opened only for input [pp_print]
599cee73
PM
7 print STDIN "abc" ;
8
767a6a26 9 Filehandle %s opened only for output [pp_print]
af8c498a 10 print <STDOUT> ;
599cee73 11
9a7dcd9c 12 print() on closed filehandle %s [pp_print]
599cee73
PM
13 close STDIN ; print STDIN "abc" ;
14
767a6a26 15 uninitialized [pp_rv2av]
599cee73
PM
16 my $a = undef ; my @b = @$a
17
767a6a26 18 uninitialized [pp_rv2hv]
599cee73
PM
19 my $a = undef ; my %b = %$a
20
767a6a26 21 Odd number of elements in hash list [pp_aassign]
599cee73
PM
22 %X = (1,2,3) ;
23
767a6a26 24 Reference found where even-sized list expected [pp_aassign]
599cee73
PM
25 $X = [ 1 ..3 ];
26
767a6a26
PM
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
PM
34 close STDIN ; $a = <STDIN>;
35
767a6a26
PM
36 glob failed (child exited with status %d%s) [Perl_do_readline] <<TODO
37
38 Deep recursion on subroutine \"%s\" [Perl_sub_crush_depth]
6bc102ca 39 sub fred { fred() if $a++ < 200} fred()
599cee73 40
767a6a26 41 Deep recursion on anonymous subroutine [Perl_sub_crush_depth]
6bc102ca 42 $a = sub { &$a if $a++ < 200} &$a
599cee73 43
6bc102ca
GS
44 Possible Y2K bug: about to append an integer to '19' [pp_concat]
45 $x = "19$yy\n";
767a6a26 46
599cee73 47__END__
767a6a26 48# pp_hot.c [pp_print]
4438c4b7 49use warnings 'unopened' ;
599cee73 50$f = $a = "abc" ;
0453d815 51print $f $a;
4438c4b7 52no warnings 'unopened' ;
0453d815 53print $f $a;
599cee73
PM
54EXPECT
55Filehandle main::abc never opened at - line 4.
56########
767a6a26 57# pp_hot.c [pp_print]
4438c4b7 58use warnings 'io' ;
599cee73 59print STDIN "anc";
af8c498a
GS
60print <STDOUT>;
61print <STDERR>;
62open(FOO, ">&STDOUT") and print <FOO>;
63print getc(STDERR);
64print getc(FOO);
88c07c36 65####################################################################
37bd1396
GS
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). #
88c07c36 70####################################################################
37bd1396
GS
71#read(FOO,$_,1);
72no warnings 'io' ;
73print STDIN "anc";
599cee73
PM
74EXPECT
75Filehandle main::STDIN opened only for input at - line 3.
af8c498a
GS
76Filehandle main::STDOUT opened only for output at - line 4.
77Filehandle main::STDERR opened only for output at - line 5.
78Filehandle main::FOO opened only for output at - line 6.
79Filehandle main::STDERR opened only for output at - line 7.
80Filehandle main::FOO opened only for output at - line 8.
599cee73 81########
767a6a26 82# pp_hot.c [pp_print]
4438c4b7 83use warnings 'closed' ;
599cee73
PM
84close STDIN ;
85print STDIN "anc";
4438c4b7 86no warnings 'closed' ;
0453d815 87print STDIN "anc";
599cee73 88EXPECT
9a7dcd9c 89print() on closed filehandle main::STDIN at - line 4.
599cee73 90########
767a6a26 91# pp_hot.c [pp_rv2av]
4438c4b7 92use warnings 'uninitialized' ;
599cee73 93my $a = undef ;
0453d815 94my @b = @$a;
4438c4b7 95no warnings 'uninitialized' ;
0453d815 96my @c = @$a;
599cee73 97EXPECT
b89fed5f 98Use of uninitialized value in array dereference at - line 4.
599cee73 99########
767a6a26 100# pp_hot.c [pp_rv2hv]
4438c4b7 101use warnings 'uninitialized' ;
599cee73 102my $a = undef ;
0453d815 103my %b = %$a;
4438c4b7 104no warnings 'uninitialized' ;
0453d815 105my %c = %$a;
599cee73 106EXPECT
b89fed5f 107Use of uninitialized value in hash dereference at - line 4.
599cee73 108########
767a6a26 109# pp_hot.c [pp_aassign]
4438c4b7 110use warnings 'unsafe' ;
599cee73 111my %X ; %X = (1,2,3) ;
4438c4b7 112no warnings 'unsafe' ;
0453d815 113my %Y ; %Y = (1,2,3) ;
599cee73
PM
114EXPECT
115Odd number of elements in hash assignment at - line 3.
116########
767a6a26 117# pp_hot.c [pp_aassign]
4438c4b7 118use warnings 'unsafe' ;
599cee73 119my %X ; %X = [1 .. 3] ;
4438c4b7 120no warnings 'unsafe' ;
0453d815 121my %Y ; %Y = [1 .. 3] ;
599cee73
PM
122EXPECT
123Reference found where even-sized list expected at - line 3.
124########
767a6a26 125# pp_hot.c [Perl_do_readline]
4438c4b7 126use warnings 'closed' ;
599cee73 127close STDIN ; $a = <STDIN> ;
4438c4b7 128no warnings 'closed' ;
0453d815 129$a = <STDIN> ;
599cee73 130EXPECT
9a7dcd9c 131readline() on closed filehandle main::STDIN at - line 3.
599cee73 132########
767a6a26
PM
133# pp_hot.c [Perl_do_readline]
134use warnings 'io' ;
135my $file = "./xcv" ; unlink $file ;
136open (FH, ">./xcv") ;
137my $a = <FH> ;
138no warnings 'io' ;
139$a = <FH> ;
140unlink $file ;
141EXPECT
142Filehandle main::FH opened only for output at - line 5.
143########
144# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 145use warnings 'recursion' ;
599cee73
PM
146sub fred
147{
148 fred() if $a++ < 200
149}
4a925ff6
GS
150{
151 local $SIG{__WARN__} = sub {
152 die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
153 };
154 fred();
155}
599cee73 156EXPECT
4a925ff6 157ok
599cee73 158########
767a6a26 159# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 160no warnings 'recursion' ;
0453d815
PM
161sub 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}
171EXPECT
172
173########
767a6a26 174# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 175use warnings 'recursion' ;
599cee73
PM
176$b = sub
177{
178 &$b if $a++ < 200
179} ;
180
181&$b ;
182EXPECT
183Deep recursion on anonymous subroutine at - line 5.
0453d815 184########
767a6a26 185# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 186no warnings 'recursion' ;
0453d815
PM
187$b = sub
188{
189 &$b if $a++ < 200
190} ;
191
192&$b ;
193EXPECT
6bc102ca
GS
194########
195# pp_hot.c [pp_concat]
196use warnings 'misc';
197use Config;
198BEGIN {
199 unless ($Config{ccflags} =~ /Y2KWARN/) {
200 print "SKIPPED\n# perl not built with -DPERL_Y2KWARN";
201 exit 0;
202 }
203}
204my $x;
205my $yy = 78;
206$x = "19$yy\n";
207$x = "19" . $yy . "\n";
208$x = "319$yy\n";
209$x = "319" . $yy . "\n";
210no warnings 'misc';
211$x = "19$yy\n";
212$x = "19" . $yy . "\n";
213EXPECT
214Possible Y2K bug: about to append an integer to '19' at - line 12.
215Possible Y2K bug: about to append an integer to '19' at - line 13.