This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [PATCH] [perl #18175] B::Concise,-exec doesn't handle // operator well
[perl5.git] / t / lib / warnings / pp_sys
CommitLineData
599cee73
PM
1 pp_sys.c AOK
2
767a6a26 3 untie attempted while %d inner references still exist [pp_untie]
599cee73
PM
4 sub TIESCALAR { bless [] } ; tie $a, 'main'; untie $a ;
5
c289d2f7
JH
6 fileno() on unopened filehandle abc [pp_fileno]
7 $a = "abc"; fileno($a)
8
9 binmode() on unopened filehandle abc [pp_binmode]
10 $a = "abc"; fileno($a)
11
12 printf() on unopened filehandle abc [pp_prtf]
13 $a = "abc"; printf $a "fred"
14
767a6a26 15 Filehandle %s opened only for input [pp_leavewrite]
599cee73
PM
16 format STDIN =
17 .
18 write STDIN;
19
9a7dcd9c 20 write() on closed filehandle %s [pp_leavewrite]
599cee73
PM
21 format STDIN =
22 .
23 close STDIN;
24 write STDIN ;
25
767a6a26 26 page overflow [pp_leavewrite]
599cee73 27
2dd78f96 28 printf() on unopened filehandle abc [pp_prtf]
599cee73
PM
29 $a = "abc"; printf $a "fred"
30
767a6a26 31 Filehandle %s opened only for input [pp_prtf]
599cee73
PM
32 $a = "abc";
33 printf $a "fred"
34
9a7dcd9c 35 printf() on closed filehandle %s [pp_prtf]
599cee73
PM
36 close STDIN ;
37 printf STDIN "fred"
38
69282e91 39 syswrite() on closed filehandle %s [pp_send]
599cee73
PM
40 close STDIN;
41 syswrite STDIN, "fred", 1;
42
69282e91 43 send() on closed socket %s [pp_send]
599cee73
PM
44 close STDIN;
45 send STDIN, "fred", 1
46
69282e91 47 bind() on closed socket %s [pp_bind]
599cee73
PM
48 close STDIN;
49 bind STDIN, "fred" ;
50
51
69282e91 52 connect() on closed socket %s [pp_connect]
599cee73
PM
53 close STDIN;
54 connect STDIN, "fred" ;
55
69282e91 56 listen() on closed socket %s [pp_listen]
599cee73
PM
57 close STDIN;
58 listen STDIN, 2;
59
69282e91 60 accept() on closed socket %s [pp_accept]
599cee73 61 close STDIN;
69282e91 62 accept "fred", STDIN ;
599cee73 63
69282e91 64 shutdown() on closed socket %s [pp_shutdown]
599cee73
PM
65 close STDIN;
66 shutdown STDIN, 0;
67
69282e91
GS
68 setsockopt() on closed socket %s [pp_ssockopt]
69 getsockopt() on closed socket %s [pp_ssockopt]
599cee73
PM
70 close STDIN;
71 setsockopt STDIN, 1,2,3;
72 getsockopt STDIN, 1,2;
73
69282e91
GS
74 getsockname() on closed socket %s [pp_getpeername]
75 getpeername() on closed socket %s [pp_getpeername]
599cee73
PM
76 close STDIN;
77 getsockname STDIN;
78 getpeername STDIN;
79
69282e91 80 flock() on closed socket %s [pp_flock]
bc37a18f 81 flock() on closed socket [pp_flock]
69282e91
GS
82 close STDIN;
83 flock STDIN, 8;
bc37a18f 84 flock $a, 8;
69282e91 85
767a6a26 86 warn(warn_nl, "stat"); [pp_stat]
599cee73 87
2dd78f96
JH
88 -T on closed filehandle %s
89 stat() on closed filehandle %s
90 close STDIN ; -T STDIN ; stat(STDIN) ;
599cee73 91
767a6a26 92 warn(warn_nl, "open"); [pp_fttext]
599cee73
PM
93 -T "abc\ndef" ;
94
767a6a26
PM
95 Filehandle %s opened only for output [pp_sysread]
96 my $file = "./xcv" ;
97 open(F, ">$file") ;
98 my $a = sysread(F, $a,10) ;
5d3e98de 99
90133b69
RGS
100 lstat on filehandle %s [pp_lstat]
101
102 getc() on unopened filehandle [pp_getc]
103
104 getc() on closed filehandle [pp_getc]
599cee73
PM
105
106__END__
767a6a26 107# pp_sys.c [pp_untie]
4438c4b7 108use warnings 'untie' ;
599cee73
PM
109sub TIESCALAR { bless [] } ;
110$b = tie $a, 'main';
111untie $a ;
4438c4b7 112no warnings 'untie' ;
0453d815
PM
113$c = tie $d, 'main';
114untie $d ;
599cee73
PM
115EXPECT
116untie attempted while 1 inner references still exist at - line 5.
117########
767a6a26 118# pp_sys.c [pp_leavewrite]
4438c4b7 119use warnings 'io' ;
599cee73
PM
120format STDIN =
121.
122write STDIN;
4438c4b7 123no warnings 'io' ;
0453d815 124write STDIN;
599cee73 125EXPECT
43693395 126Filehandle STDIN opened only for input at - line 5.
599cee73 127########
767a6a26 128# pp_sys.c [pp_leavewrite]
4438c4b7 129use warnings 'closed' ;
599cee73
PM
130format STDIN =
131.
132close STDIN;
133write STDIN;
69282e91
GS
134opendir STDIN, ".";
135write STDIN;
136closedir STDIN;
4438c4b7 137no warnings 'closed' ;
0453d815 138write STDIN;
69282e91
GS
139opendir STDIN, ".";
140write STDIN;
599cee73 141EXPECT
43693395
GS
142write() on closed filehandle STDIN at - line 6.
143write() on closed filehandle STDIN at - line 8.
144 (Are you trying to call write() on dirhandle STDIN?)
599cee73 145########
767a6a26 146# pp_sys.c [pp_leavewrite]
4438c4b7 147use warnings 'io' ;
599cee73
PM
148format STDOUT_TOP =
149abc
150.
151format STDOUT =
152def
153ghi
154.
155$= = 1 ;
156$- =1 ;
3eeba6fb 157open STDOUT, ">".($^O eq 'VMS'? 'NL:' : '/dev/null') ;
599cee73 158write ;
4438c4b7 159no warnings 'io' ;
0453d815 160write ;
599cee73
PM
161EXPECT
162page overflow at - line 13.
163########
767a6a26 164# pp_sys.c [pp_prtf]
4438c4b7 165use warnings 'unopened' ;
599cee73 166$a = "abc";
0453d815 167printf $a "fred";
4438c4b7 168no warnings 'unopened' ;
0453d815 169printf $a "fred";
599cee73 170EXPECT
2dd78f96 171printf() on unopened filehandle abc at - line 4.
599cee73 172########
767a6a26 173# pp_sys.c [pp_prtf]
4438c4b7 174use warnings 'closed' ;
599cee73 175close STDIN ;
0453d815 176printf STDIN "fred";
69282e91
GS
177opendir STDIN, ".";
178printf STDIN "fred";
179closedir STDIN;
4438c4b7 180no warnings 'closed' ;
0453d815 181printf STDIN "fred";
69282e91
GS
182opendir STDIN, ".";
183printf STDIN "fred";
599cee73 184EXPECT
43693395
GS
185printf() on closed filehandle STDIN at - line 4.
186printf() on closed filehandle STDIN at - line 6.
187 (Are you trying to call printf() on dirhandle STDIN?)
599cee73 188########
767a6a26 189# pp_sys.c [pp_prtf]
4438c4b7 190use warnings 'io' ;
0453d815 191printf STDIN "fred";
4438c4b7 192no warnings 'io' ;
0453d815 193printf STDIN "fred";
599cee73 194EXPECT
43693395 195Filehandle STDIN opened only for input at - line 3.
599cee73 196########
767a6a26 197# pp_sys.c [pp_send]
4438c4b7 198use warnings 'closed' ;
599cee73
PM
199close STDIN;
200syswrite STDIN, "fred", 1;
69282e91
GS
201opendir STDIN, ".";
202syswrite STDIN, "fred", 1;
203closedir STDIN;
4438c4b7 204no warnings 'closed' ;
0453d815 205syswrite STDIN, "fred", 1;
69282e91
GS
206opendir STDIN, ".";
207syswrite STDIN, "fred", 1;
599cee73 208EXPECT
43693395
GS
209syswrite() on closed filehandle STDIN at - line 4.
210syswrite() on closed filehandle STDIN at - line 6.
211 (Are you trying to call syswrite() on dirhandle STDIN?)
69282e91
GS
212########
213# pp_sys.c [pp_flock]
f0963acb
GS
214use Config;
215BEGIN {
9bdf8ebc
JH
216 if ( !$Config{d_flock} &&
217 !$Config{d_fcntl_can_lock} &&
218 !$Config{d_lockf} ) {
f0963acb
GS
219 print <<EOM ;
220SKIPPED
221# flock not present
222EOM
223 exit ;
224 }
225}
bc37a18f 226use warnings qw(unopened closed);
69282e91
GS
227close STDIN;
228flock STDIN, 8;
229opendir STDIN, ".";
230flock STDIN, 8;
bc37a18f
RG
231flock FOO, 8;
232flock $a, 8;
233no warnings qw(unopened closed);
69282e91
GS
234flock STDIN, 8;
235opendir STDIN, ".";
236flock STDIN, 8;
bc37a18f
RG
237flock FOO, 8;
238flock $a, 8;
69282e91 239EXPECT
43693395 240flock() on closed filehandle STDIN at - line 16.
c934501c 241flock() on closed filehandle STDIN at - line 18.
43693395 242 (Are you trying to call flock() on dirhandle STDIN?)
c934501c
JH
243flock() on unopened filehandle FOO at - line 19.
244flock() on unopened filehandle at - line 20.
599cee73 245########
767a6a26 246# pp_sys.c [pp_prtf pp_send pp_bind pp_connect pp_listen pp_accept pp_shutdown pp_ssockopt ppp_getpeername]
4438c4b7 247use warnings 'io' ;
599cee73
PM
248use Config;
249BEGIN {
250 if ( $^O ne 'VMS' and ! $Config{d_socket}) {
251 print <<EOM ;
252SKIPPED
253# send not present
254# bind not present
255# connect not present
256# accept not present
257# shutdown not present
258# setsockopt not present
259# getsockopt not present
260# getsockname not present
261# getpeername not present
262EOM
263 exit ;
264 }
265}
266close STDIN;
267send STDIN, "fred", 1;
268bind STDIN, "fred" ;
269connect STDIN, "fred" ;
270listen STDIN, 2;
69282e91
GS
271accept "fred", STDIN;
272shutdown STDIN, 0;
273setsockopt STDIN, 1,2,3;
274getsockopt STDIN, 1,2;
275getsockname STDIN;
276getpeername STDIN;
277opendir STDIN, ".";
278send STDIN, "fred", 1;
279bind STDIN, "fred" ;
280connect STDIN, "fred" ;
281listen STDIN, 2;
282accept "fred", STDIN;
599cee73
PM
283shutdown STDIN, 0;
284setsockopt STDIN, 1,2,3;
285getsockopt STDIN, 1,2;
286getsockname STDIN;
287getpeername STDIN;
69282e91 288closedir STDIN;
4438c4b7 289no warnings 'io' ;
0453d815
PM
290send STDIN, "fred", 1;
291bind STDIN, "fred" ;
292connect STDIN, "fred" ;
293listen STDIN, 2;
294accept STDIN, "fred" ;
295shutdown STDIN, 0;
296setsockopt STDIN, 1,2,3;
297getsockopt STDIN, 1,2;
298getsockname STDIN;
299getpeername STDIN;
69282e91
GS
300opendir STDIN, ".";
301send STDIN, "fred", 1;
302bind STDIN, "fred" ;
303connect STDIN, "fred" ;
304listen STDIN, 2;
305accept "fred", STDIN;
306shutdown STDIN, 0;
307setsockopt STDIN, 1,2,3;
308getsockopt STDIN, 1,2;
309getsockname STDIN;
310getpeername STDIN;
599cee73 311EXPECT
43693395
GS
312send() on closed socket STDIN at - line 22.
313bind() on closed socket STDIN at - line 23.
314connect() on closed socket STDIN at - line 24.
315listen() on closed socket STDIN at - line 25.
316accept() on closed socket STDIN at - line 26.
317shutdown() on closed socket STDIN at - line 27.
318setsockopt() on closed socket STDIN at - line 28.
319getsockopt() on closed socket STDIN at - line 29.
320getsockname() on closed socket STDIN at - line 30.
321getpeername() on closed socket STDIN at - line 31.
322send() on closed socket STDIN at - line 33.
323 (Are you trying to call send() on dirhandle STDIN?)
324bind() on closed socket STDIN at - line 34.
325 (Are you trying to call bind() on dirhandle STDIN?)
326connect() on closed socket STDIN at - line 35.
327 (Are you trying to call connect() on dirhandle STDIN?)
328listen() on closed socket STDIN at - line 36.
329 (Are you trying to call listen() on dirhandle STDIN?)
330accept() on closed socket STDIN at - line 37.
331 (Are you trying to call accept() on dirhandle STDIN?)
332shutdown() on closed socket STDIN at - line 38.
333 (Are you trying to call shutdown() on dirhandle STDIN?)
334setsockopt() on closed socket STDIN at - line 39.
335 (Are you trying to call setsockopt() on dirhandle STDIN?)
336getsockopt() on closed socket STDIN at - line 40.
337 (Are you trying to call getsockopt() on dirhandle STDIN?)
338getsockname() on closed socket STDIN at - line 41.
339 (Are you trying to call getsockname() on dirhandle STDIN?)
340getpeername() on closed socket STDIN at - line 42.
341 (Are you trying to call getpeername() on dirhandle STDIN?)
599cee73 342########
767a6a26 343# pp_sys.c [pp_stat]
4438c4b7 344use warnings 'newline' ;
599cee73 345stat "abc\ndef";
4438c4b7 346no warnings 'newline' ;
0453d815 347stat "abc\ndef";
599cee73
PM
348EXPECT
349Unsuccessful stat on filename containing newline at - line 3.
350########
767a6a26 351# pp_sys.c [pp_fttext]
2dd78f96 352use warnings qw(unopened closed) ;
599cee73
PM
353close STDIN ;
354-T STDIN ;
9ddeeac9 355stat(STDIN) ;
2dd78f96
JH
356-T HOCUS;
357stat(POCUS);
358no warnings qw(unopened closed) ;
0453d815 359-T STDIN ;
9ddeeac9 360stat(STDIN);
2dd78f96
JH
361-T HOCUS;
362stat(POCUS);
599cee73 363EXPECT
2dd78f96
JH
364-T on closed filehandle STDIN at - line 4.
365stat() on closed filehandle STDIN at - line 5.
366-T on unopened filehandle HOCUS at - line 6.
367stat() on unopened filehandle POCUS at - line 7.
599cee73 368########
767a6a26 369# pp_sys.c [pp_fttext]
4438c4b7 370use warnings 'newline' ;
599cee73 371-T "abc\ndef" ;
4438c4b7 372no warnings 'newline' ;
0453d815 373-T "abc\ndef" ;
599cee73
PM
374EXPECT
375Unsuccessful open on filename containing newline at - line 3.
767a6a26
PM
376########
377# pp_sys.c [pp_sysread]
378use warnings 'io' ;
6bbf1b34 379if ($^O eq 'dos') {
380 print <<EOM ;
381SKIPPED
382# skipped on dos
383EOM
384 exit ;
385}
767a6a26
PM
386my $file = "./xcv" ;
387open(F, ">$file") ;
388my $a = sysread(F, $a,10) ;
389no warnings 'io' ;
390my $a = sysread(F, $a,10) ;
391close F ;
392unlink $file ;
393EXPECT
c6f2523f 394Filehandle F opened only for output at - line 12.
c289d2f7
JH
395########
396# pp_sys.c [pp_binmode]
397use warnings 'unopened' ;
398binmode(BLARG);
399$a = "BLERG";binmode($a);
400EXPECT
401binmode() on unopened filehandle BLARG at - line 3.
402binmode() on unopened filehandle at - line 4.
5d3e98de
RGS
403########
404# pp_sys.c [pp_lstat]
405use warnings 'io';
365c80fa
RGS
406open FH, "harness" or die "# $!";
407lstat FH;
5d3e98de
RGS
408open my $fh, $0 or die "# $!";
409lstat $fh;
410no warnings 'io';
365c80fa 411lstat FH;
5d3e98de 412lstat $fh;
365c80fa 413close FH;
5d3e98de
RGS
414close $fh;
415EXPECT
365c80fa
RGS
416lstat() on filehandle FH at - line 4.
417lstat() on filehandle $fh at - line 6.
90133b69
RGS
418########
419# pp_sys.c [pp_getc]
420use warnings qw(unopened closed) ;
421getc FOO;
422close STDIN;
423getc STDIN;
97e322ff
RGS
424# Create an empty file
425$file = 'getcwarn.tmp';
426open FH1, ">$file" or die "# $!"; close FH1;
427open FH2, $file or die "# $!";
428getc FH2; # Should not warn at EOF
429close FH2;
430getc FH2; # Warns, now
431unlink $file;
90133b69
RGS
432no warnings qw(unopened closed) ;
433getc FOO;
434getc STDIN;
97e322ff 435getc FH2;
90133b69
RGS
436EXPECT
437getc() on unopened filehandle FOO at - line 3.
438getc() on closed filehandle STDIN at - line 5.
97e322ff 439getc() on closed filehandle FH2 at - line 12.