This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
update perldiag for change#4707
[perl5.git] / t / pragma / warn / pp_sys
1   pp_sys.c      AOK
2
3   untie attempted while %d inner references still exist [pp_untie]
4     sub TIESCALAR { bless [] } ; tie $a, 'main'; untie $a ;
5
6   Filehandle %s opened only for input           [pp_leavewrite]
7     format STDIN =
8     .
9     write STDIN;
10
11   Write on closed filehandle %s                 [pp_leavewrite]
12     format STDIN =
13     .
14     close STDIN;
15     write STDIN ;
16
17   page overflow                                 [pp_leavewrite]
18
19   Filehandle %s never opened                    [pp_prtf]
20     $a = "abc"; printf $a "fred"
21
22   Filehandle %s opened only for input           [pp_prtf]
23     $a = "abc"; 
24     printf $a "fred"
25
26   printf on closed filehandle %s                [pp_prtf]
27     close STDIN ;
28     printf STDIN "fred"
29
30   Syswrite on closed filehandle                 [pp_send]
31     close STDIN; 
32     syswrite STDIN, "fred", 1;
33
34   Send on closed socket                         [pp_send]
35     close STDIN; 
36     send STDIN, "fred", 1
37
38   bind() on closed fd                           [pp_bind]
39     close STDIN; 
40     bind STDIN, "fred" ;
41
42
43   connect() on closed fd                        [pp_connect]
44     close STDIN; 
45     connect STDIN, "fred" ;
46
47   listen() on closed fd                         [pp_listen]
48     close STDIN; 
49     listen STDIN, 2;
50
51   accept() on closed fd                         [pp_accept]
52     close STDIN; 
53     accept STDIN, "fred" ;
54
55   shutdown() on closed fd                       [pp_shutdown]
56     close STDIN; 
57     shutdown STDIN, 0;
58
59   [gs]etsockopt() on closed fd                  [pp_ssockopt]
60     close STDIN; 
61     setsockopt STDIN, 1,2,3;
62     getsockopt STDIN, 1,2;
63
64   get{sock, peer}name() on closed fd            [pp_getpeername]
65     close STDIN; 
66     getsockname STDIN;
67     getpeername STDIN;
68
69   warn(warn_nl, "stat");                        [pp_stat]
70
71   Test on unopened file <%s>
72         close STDIN ; -T STDIN ;
73
74   warn(warn_nl, "open");                        [pp_fttext]
75     -T "abc\ndef" ;
76
77   Filehandle %s opened only for output          [pp_sysread]
78         my $file = "./xcv" ;
79         open(F, ">$file") ; 
80         my $a = sysread(F, $a,10) ;
81   
82   
83
84 __END__
85 # pp_sys.c [pp_untie]
86 use warnings 'untie' ;
87 sub TIESCALAR { bless [] } ; 
88 $b = tie $a, 'main'; 
89 untie $a ;
90 no warnings 'untie' ;
91 $c = tie $d, 'main'; 
92 untie $d ;
93 EXPECT
94 untie attempted while 1 inner references still exist at - line 5.
95 ########
96 # pp_sys.c [pp_leavewrite]
97 use warnings 'io' ;
98 format STDIN =
99 .
100 write STDIN;
101 no warnings 'io' ;
102 write STDIN;
103 EXPECT
104 Filehandle main::STDIN opened only for input at - line 5.
105 ########
106 # pp_sys.c [pp_leavewrite]
107 use warnings 'closed' ;
108 format STDIN =
109 .
110 close STDIN;
111 write STDIN;
112 no warnings 'closed' ;
113 write STDIN;
114 EXPECT
115 Write on closed filehandle main::STDIN at - line 6.
116 ########
117 # pp_sys.c [pp_leavewrite]
118 use warnings 'io' ;
119 format STDOUT_TOP =
120 abc
121 .
122 format STDOUT =
123 def
124 ghi
125 .
126 $= = 1 ;
127 $- =1 ;
128 open STDOUT, ">".($^O eq 'VMS'? 'NL:' : '/dev/null') ;
129 write ;
130 no warnings 'io' ;
131 write ;
132 EXPECT
133 page overflow at - line 13.
134 ########
135 # pp_sys.c [pp_prtf]
136 use warnings 'unopened' ;
137 $a = "abc"; 
138 printf $a "fred";
139 no warnings 'unopened' ;
140 printf $a "fred";
141 EXPECT
142 Filehandle main::abc never opened at - line 4.
143 ########
144 # pp_sys.c [pp_prtf]
145 use warnings 'closed' ;
146 close STDIN ;
147 printf STDIN "fred";
148 no warnings 'closed' ;
149 printf STDIN "fred";
150 EXPECT
151 printf on closed filehandle main::STDIN at - line 4.
152 ########
153 # pp_sys.c [pp_prtf]
154 use warnings 'io' ;
155 printf STDIN "fred";
156 no warnings 'io' ;
157 printf STDIN "fred";
158 EXPECT
159 Filehandle main::STDIN opened only for input at - line 3.
160 ########
161 # pp_sys.c [pp_send]
162 use warnings 'closed' ;
163 close STDIN; 
164 syswrite STDIN, "fred", 1;
165 no warnings 'closed' ;
166 syswrite STDIN, "fred", 1;
167 EXPECT
168 Syswrite on closed filehandle at - line 4.
169 ########
170 # pp_sys.c [pp_prtf pp_send pp_bind pp_connect pp_listen pp_accept pp_shutdown pp_ssockopt ppp_getpeername]
171 use warnings 'io' ;
172 use Config; 
173 BEGIN { 
174   if ( $^O ne 'VMS' and ! $Config{d_socket}) {
175     print <<EOM ;
176 SKIPPED
177 # send not present
178 # bind not present
179 # connect not present
180 # accept not present
181 # shutdown not present
182 # setsockopt not present
183 # getsockopt not present
184 # getsockname not present
185 # getpeername not present
186 EOM
187     exit ;
188   } 
189 }
190 close STDIN; 
191 send STDIN, "fred", 1;
192 bind STDIN, "fred" ;
193 connect STDIN, "fred" ;
194 listen STDIN, 2;
195 accept STDIN, "fred" ;
196 shutdown STDIN, 0;
197 setsockopt STDIN, 1,2,3;
198 getsockopt STDIN, 1,2;
199 getsockname STDIN;
200 getpeername STDIN;
201 no warnings 'io' ;
202 send STDIN, "fred", 1;
203 bind STDIN, "fred" ;
204 connect STDIN, "fred" ;
205 listen STDIN, 2;
206 accept STDIN, "fred" ;
207 shutdown STDIN, 0;
208 setsockopt STDIN, 1,2,3;
209 getsockopt STDIN, 1,2;
210 getsockname STDIN;
211 getpeername STDIN;
212 EXPECT
213 Send on closed socket at - line 22.
214 bind() on closed fd at - line 23.
215 connect() on closed fd at - line 24.
216 listen() on closed fd at - line 25.
217 accept() on closed fd at - line 26.
218 shutdown() on closed fd at - line 27.
219 [gs]etsockopt() on closed fd at - line 28.
220 [gs]etsockopt() on closed fd at - line 29.
221 get{sock, peer}name() on closed fd at - line 30.
222 get{sock, peer}name() on closed fd at - line 31.
223 ########
224 # pp_sys.c [pp_stat]
225 use warnings 'newline' ;
226 stat "abc\ndef";
227 no warnings 'newline' ;
228 stat "abc\ndef";
229 EXPECT
230 Unsuccessful stat on filename containing newline at - line 3.
231 ########
232 # pp_sys.c [pp_fttext]
233 use warnings 'unopened' ;
234 close STDIN ; 
235 -T STDIN ;
236 no warnings 'unopened' ;
237 -T STDIN ;
238 EXPECT
239 Test on unopened file <STDIN> at - line 4.
240 ########
241 # pp_sys.c [pp_fttext]
242 use warnings 'newline' ;
243 -T "abc\ndef" ;
244 no warnings 'newline' ;
245 -T "abc\ndef" ;
246 EXPECT
247 Unsuccessful open on filename containing newline at - line 3.
248 ########
249 # pp_sys.c [pp_sysread]
250 use warnings 'io' ;
251 my $file = "./xcv" ;
252 open(F, ">$file") ; 
253 my $a = sysread(F, $a,10) ;
254 no warnings 'io' ;
255 my $a = sysread(F, $a,10) ;
256 close F ;
257 unlink $file ;
258 EXPECT
259 Filehandle main::F opened only for output at - line 5.