This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix bug in change#3728 that might free COPs prematurely;
[perl5.git] / t / pragma / warn / pp_hot
CommitLineData
599cee73
PM
1 pp_hot.c AOK
2
3 Filehandle %s never opened
4 $f = $a = "abc" ; print $f $a
5
6 Filehandle %s opened only for input
7 print STDIN "abc" ;
8
af8c498a
GS
9 Filehandle %s opened only for output
10 print <STDOUT> ;
599cee73
PM
11
12 print on closed filehandle %s
13 close STDIN ; print STDIN "abc" ;
14
15 uninitialized
16 my $a = undef ; my @b = @$a
17
18 uninitialized
19 my $a = undef ; my %b = %$a
20
21 Odd number of elements in hash list
22 %X = (1,2,3) ;
23
24 Reference found where even-sized list expected
25 $X = [ 1 ..3 ];
26
af8c498a 27 Read on closed filehandle %s
599cee73
PM
28 close STDIN ; $a = <STDIN>;
29
30 Deep recursion on subroutine \"%s\"
31 sub fred { fred() if $a++ < 200} fred()
32
33 Deep recursion on anonymous subroutine
34 $a = sub { &$a if $a++ < 200} &$a
35
36__END__
37# pp_hot.c
38use warning 'unopened' ;
39$f = $a = "abc" ;
0453d815
PM
40print $f $a;
41no warning 'unopened' ;
42print $f $a;
599cee73
PM
43EXPECT
44Filehandle main::abc never opened at - line 4.
45########
46# pp_hot.c
47use warning 'io' ;
48print STDIN "anc";
af8c498a
GS
49print <STDOUT>;
50print <STDERR>;
51open(FOO, ">&STDOUT") and print <FOO>;
52print getc(STDERR);
53print getc(FOO);
54read(FOO,$_,1);
0453d815
PM
55no warning 'io' ;
56print STDIN "anc";
599cee73
PM
57EXPECT
58Filehandle main::STDIN opened only for input at - line 3.
af8c498a
GS
59Filehandle main::STDOUT opened only for output at - line 4.
60Filehandle main::STDERR opened only for output at - line 5.
61Filehandle main::FOO opened only for output at - line 6.
62Filehandle main::STDERR opened only for output at - line 7.
63Filehandle main::FOO opened only for output at - line 8.
64Filehandle main::FOO opened only for output at - line 9.
599cee73
PM
65########
66# pp_hot.c
67use warning 'closed' ;
68close STDIN ;
69print STDIN "anc";
0453d815
PM
70no warning 'closed' ;
71print STDIN "anc";
599cee73
PM
72EXPECT
73print on closed filehandle main::STDIN at - line 4.
74########
75# pp_hot.c
76use warning 'uninitialized' ;
77my $a = undef ;
0453d815
PM
78my @b = @$a;
79no warning 'uninitialized' ;
80my @c = @$a;
599cee73
PM
81EXPECT
82Use of uninitialized value at - line 4.
83########
84# pp_hot.c
85use warning 'uninitialized' ;
86my $a = undef ;
0453d815
PM
87my %b = %$a;
88no warning 'uninitialized' ;
89my %c = %$a;
599cee73
PM
90EXPECT
91Use of uninitialized value at - line 4.
92########
93# pp_hot.c
94use warning 'unsafe' ;
95my %X ; %X = (1,2,3) ;
0453d815
PM
96no warning 'unsafe' ;
97my %Y ; %Y = (1,2,3) ;
599cee73
PM
98EXPECT
99Odd number of elements in hash assignment at - line 3.
100########
101# pp_hot.c
102use warning 'unsafe' ;
103my %X ; %X = [1 .. 3] ;
0453d815
PM
104no warning 'unsafe' ;
105my %Y ; %Y = [1 .. 3] ;
599cee73
PM
106EXPECT
107Reference found where even-sized list expected at - line 3.
108########
109# pp_hot.c
110use warning 'closed' ;
111close STDIN ; $a = <STDIN> ;
0453d815
PM
112no warning 'closed' ;
113$a = <STDIN> ;
599cee73 114EXPECT
af8c498a 115Read on closed filehandle main::STDIN at - line 3.
599cee73
PM
116########
117# pp_hot.c
118use warning 'recursion' ;
119sub fred
120{
121 fred() if $a++ < 200
122}
4a925ff6
GS
123{
124 local $SIG{__WARN__} = sub {
125 die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
126 };
127 fred();
128}
599cee73 129EXPECT
4a925ff6 130ok
599cee73
PM
131########
132# pp_hot.c
0453d815
PM
133no warning 'recursion' ;
134sub fred
135{
136 fred() if $a++ < 200
137}
138{
139 local $SIG{__WARN__} = sub {
140 die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
141 };
142 fred();
143}
144EXPECT
145
146########
147# pp_hot.c
599cee73
PM
148use warning 'recursion' ;
149$b = sub
150{
151 &$b if $a++ < 200
152} ;
153
154&$b ;
155EXPECT
156Deep recursion on anonymous subroutine at - line 5.
0453d815
PM
157########
158# pp_hot.c
159no warning 'recursion' ;
160$b = sub
161{
162 &$b if $a++ < 200
163} ;
164
165&$b ;
166EXPECT
167