This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Convert a pp_sys test to use warnings 'closed', instead of the broader 'io'.
[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 105
4ef2275c
GA
106 Non-string passed as bitmask [pp_sselect]
107
599cee73 108__END__
767a6a26 109# pp_sys.c [pp_untie]
4438c4b7 110use warnings 'untie' ;
599cee73
PM
111sub TIESCALAR { bless [] } ;
112$b = tie $a, 'main';
113untie $a ;
4438c4b7 114no warnings 'untie' ;
0453d815
PM
115$c = tie $d, 'main';
116untie $d ;
599cee73
PM
117EXPECT
118untie attempted while 1 inner references still exist at - line 5.
119########
767a6a26 120# pp_sys.c [pp_leavewrite]
4438c4b7 121use warnings 'io' ;
599cee73
PM
122format STDIN =
123.
124write STDIN;
4438c4b7 125no warnings 'io' ;
0453d815 126write STDIN;
599cee73 127EXPECT
43693395 128Filehandle STDIN opened only for input at - line 5.
599cee73 129########
767a6a26 130# pp_sys.c [pp_leavewrite]
4438c4b7 131use warnings 'closed' ;
599cee73
PM
132format STDIN =
133.
c521cf7c
NC
134format FOO =
135.
599cee73
PM
136close STDIN;
137write STDIN;
c521cf7c 138write FOO;
69282e91
GS
139opendir STDIN, ".";
140write STDIN;
141closedir STDIN;
c521cf7c
NC
142opendir FOO, ".";
143write FOO;
144closedir FOO;
4438c4b7 145no warnings 'closed' ;
0453d815 146write STDIN;
c521cf7c 147write FOO;
69282e91 148opendir STDIN, ".";
c521cf7c 149opendir FOO, ".";
69282e91 150write STDIN;
c521cf7c 151write FOO;
599cee73 152EXPECT
43693395 153write() on closed filehandle STDIN at - line 8.
c521cf7c 154write() on closed filehandle STDIN at - line 11.
43693395 155 (Are you trying to call write() on dirhandle STDIN?)
599cee73 156########
c521cf7c
NC
157########
158# pp_sys.c [pp_leavewrite]
159use warnings 'unopened';
160format STDIN =
161.
162format FOO =
163.
164close STDIN;
165write STDIN;
166write FOO;
167opendir STDIN, ".";
168write STDIN;
169closedir STDIN;
170opendir FOO, ".";
171write FOO;
172closedir FOO;
173no warnings 'unopened';
174write STDIN;
175write FOO;
176opendir STDIN, ".";
177opendir FOO, ".";
178write STDIN;
179write FOO;
180EXPECT
181write() on unopened filehandle FOO at - line 10.
182write() on unopened filehandle FOO at - line 15.
183 (Are you trying to call write() on dirhandle FOO?)
184########
767a6a26 185# pp_sys.c [pp_leavewrite]
4438c4b7 186use warnings 'io' ;
599cee73
PM
187format STDOUT_TOP =
188abc
189.
190format STDOUT =
191def
192ghi
193.
194$= = 1 ;
195$- =1 ;
3eeba6fb 196open STDOUT, ">".($^O eq 'VMS'? 'NL:' : '/dev/null') ;
599cee73 197write ;
4438c4b7 198no warnings 'io' ;
0453d815 199write ;
599cee73
PM
200EXPECT
201page overflow at - line 13.
202########
767a6a26 203# pp_sys.c [pp_prtf]
4438c4b7 204use warnings 'unopened' ;
599cee73 205$a = "abc";
0453d815 206printf $a "fred";
4438c4b7 207no warnings 'unopened' ;
0453d815 208printf $a "fred";
599cee73 209EXPECT
2dd78f96 210printf() on unopened filehandle abc at - line 4.
599cee73 211########
767a6a26 212# pp_sys.c [pp_prtf]
4438c4b7 213use warnings 'closed' ;
599cee73 214close STDIN ;
0453d815 215printf STDIN "fred";
69282e91
GS
216opendir STDIN, ".";
217printf STDIN "fred";
218closedir STDIN;
4438c4b7 219no warnings 'closed' ;
0453d815 220printf STDIN "fred";
69282e91
GS
221opendir STDIN, ".";
222printf STDIN "fred";
599cee73 223EXPECT
43693395
GS
224printf() on closed filehandle STDIN at - line 4.
225printf() on closed filehandle STDIN at - line 6.
226 (Are you trying to call printf() on dirhandle STDIN?)
599cee73 227########
767a6a26 228# pp_sys.c [pp_prtf]
4438c4b7 229use warnings 'io' ;
0453d815 230printf STDIN "fred";
4438c4b7 231no warnings 'io' ;
0453d815 232printf STDIN "fred";
599cee73 233EXPECT
43693395 234Filehandle STDIN opened only for input at - line 3.
599cee73 235########
767a6a26 236# pp_sys.c [pp_send]
cf167416
RGS
237use warnings 'io' ;
238syswrite STDIN, "fred";
239no warnings 'io' ;
240syswrite STDIN, "fred";
241EXPECT
242Filehandle STDIN opened only for input at - line 3.
243########
244# pp_sys.c [pp_send]
4438c4b7 245use warnings 'closed' ;
599cee73
PM
246close STDIN;
247syswrite STDIN, "fred", 1;
69282e91
GS
248opendir STDIN, ".";
249syswrite STDIN, "fred", 1;
250closedir STDIN;
4438c4b7 251no warnings 'closed' ;
0453d815 252syswrite STDIN, "fred", 1;
69282e91
GS
253opendir STDIN, ".";
254syswrite STDIN, "fred", 1;
599cee73 255EXPECT
43693395
GS
256syswrite() on closed filehandle STDIN at - line 4.
257syswrite() on closed filehandle STDIN at - line 6.
258 (Are you trying to call syswrite() on dirhandle STDIN?)
69282e91
GS
259########
260# pp_sys.c [pp_flock]
f0963acb
GS
261use Config;
262BEGIN {
9bdf8ebc
JH
263 if ( !$Config{d_flock} &&
264 !$Config{d_fcntl_can_lock} &&
265 !$Config{d_lockf} ) {
f0963acb
GS
266 print <<EOM ;
267SKIPPED
268# flock not present
269EOM
270 exit ;
271 }
272}
bc37a18f 273use warnings qw(unopened closed);
69282e91
GS
274close STDIN;
275flock STDIN, 8;
276opendir STDIN, ".";
277flock STDIN, 8;
bc37a18f
RG
278flock FOO, 8;
279flock $a, 8;
280no warnings qw(unopened closed);
69282e91
GS
281flock STDIN, 8;
282opendir STDIN, ".";
283flock STDIN, 8;
bc37a18f
RG
284flock FOO, 8;
285flock $a, 8;
69282e91 286EXPECT
43693395 287flock() on closed filehandle STDIN at - line 16.
c934501c 288flock() on closed filehandle STDIN at - line 18.
43693395 289 (Are you trying to call flock() on dirhandle STDIN?)
c934501c
JH
290flock() on unopened filehandle FOO at - line 19.
291flock() on unopened filehandle at - line 20.
599cee73 292########
767a6a26 293# pp_sys.c [pp_prtf pp_send pp_bind pp_connect pp_listen pp_accept pp_shutdown pp_ssockopt ppp_getpeername]
dc8c4646 294use warnings 'closed';
599cee73
PM
295use Config;
296BEGIN {
297 if ( $^O ne 'VMS' and ! $Config{d_socket}) {
298 print <<EOM ;
299SKIPPED
300# send not present
301# bind not present
302# connect not present
303# accept not present
304# shutdown not present
305# setsockopt not present
306# getsockopt not present
307# getsockname not present
308# getpeername not present
309EOM
310 exit ;
311 }
312}
313close STDIN;
314send STDIN, "fred", 1;
315bind STDIN, "fred" ;
316connect STDIN, "fred" ;
317listen STDIN, 2;
69282e91
GS
318accept "fred", STDIN;
319shutdown STDIN, 0;
320setsockopt STDIN, 1,2,3;
321getsockopt STDIN, 1,2;
322getsockname STDIN;
323getpeername STDIN;
324opendir STDIN, ".";
325send STDIN, "fred", 1;
326bind STDIN, "fred" ;
327connect STDIN, "fred" ;
328listen STDIN, 2;
329accept "fred", STDIN;
599cee73
PM
330shutdown STDIN, 0;
331setsockopt STDIN, 1,2,3;
332getsockopt STDIN, 1,2;
333getsockname STDIN;
334getpeername STDIN;
69282e91 335closedir STDIN;
dc8c4646 336no warnings 'closed';
0453d815
PM
337send STDIN, "fred", 1;
338bind STDIN, "fred" ;
339connect STDIN, "fred" ;
340listen STDIN, 2;
341accept STDIN, "fred" ;
342shutdown STDIN, 0;
343setsockopt STDIN, 1,2,3;
344getsockopt STDIN, 1,2;
345getsockname STDIN;
346getpeername STDIN;
69282e91
GS
347opendir STDIN, ".";
348send STDIN, "fred", 1;
349bind STDIN, "fred" ;
350connect STDIN, "fred" ;
351listen STDIN, 2;
352accept "fred", STDIN;
353shutdown STDIN, 0;
354setsockopt STDIN, 1,2,3;
355getsockopt STDIN, 1,2;
356getsockname STDIN;
357getpeername STDIN;
599cee73 358EXPECT
43693395
GS
359send() on closed socket STDIN at - line 22.
360bind() on closed socket STDIN at - line 23.
361connect() on closed socket STDIN at - line 24.
362listen() on closed socket STDIN at - line 25.
363accept() on closed socket STDIN at - line 26.
364shutdown() on closed socket STDIN at - line 27.
365setsockopt() on closed socket STDIN at - line 28.
366getsockopt() on closed socket STDIN at - line 29.
367getsockname() on closed socket STDIN at - line 30.
368getpeername() on closed socket STDIN at - line 31.
369send() on closed socket STDIN at - line 33.
370 (Are you trying to call send() on dirhandle STDIN?)
371bind() on closed socket STDIN at - line 34.
372 (Are you trying to call bind() on dirhandle STDIN?)
373connect() on closed socket STDIN at - line 35.
374 (Are you trying to call connect() on dirhandle STDIN?)
375listen() on closed socket STDIN at - line 36.
376 (Are you trying to call listen() on dirhandle STDIN?)
377accept() on closed socket STDIN at - line 37.
378 (Are you trying to call accept() on dirhandle STDIN?)
379shutdown() on closed socket STDIN at - line 38.
380 (Are you trying to call shutdown() on dirhandle STDIN?)
381setsockopt() on closed socket STDIN at - line 39.
382 (Are you trying to call setsockopt() on dirhandle STDIN?)
383getsockopt() on closed socket STDIN at - line 40.
384 (Are you trying to call getsockopt() on dirhandle STDIN?)
385getsockname() on closed socket STDIN at - line 41.
386 (Are you trying to call getsockname() on dirhandle STDIN?)
387getpeername() on closed socket STDIN at - line 42.
388 (Are you trying to call getpeername() on dirhandle STDIN?)
599cee73 389########
767a6a26 390# pp_sys.c [pp_stat]
4438c4b7 391use warnings 'newline' ;
599cee73 392stat "abc\ndef";
4438c4b7 393no warnings 'newline' ;
0453d815 394stat "abc\ndef";
599cee73
PM
395EXPECT
396Unsuccessful stat on filename containing newline at - line 3.
397########
767a6a26 398# pp_sys.c [pp_fttext]
2dd78f96 399use warnings qw(unopened closed) ;
599cee73
PM
400close STDIN ;
401-T STDIN ;
9ddeeac9 402stat(STDIN) ;
2dd78f96
JH
403-T HOCUS;
404stat(POCUS);
405no warnings qw(unopened closed) ;
0453d815 406-T STDIN ;
9ddeeac9 407stat(STDIN);
2dd78f96
JH
408-T HOCUS;
409stat(POCUS);
599cee73 410EXPECT
2dd78f96
JH
411-T on closed filehandle STDIN at - line 4.
412stat() on closed filehandle STDIN at - line 5.
413-T on unopened filehandle HOCUS at - line 6.
414stat() on unopened filehandle POCUS at - line 7.
599cee73 415########
767a6a26 416# pp_sys.c [pp_fttext]
4438c4b7 417use warnings 'newline' ;
599cee73 418-T "abc\ndef" ;
4438c4b7 419no warnings 'newline' ;
0453d815 420-T "abc\ndef" ;
599cee73
PM
421EXPECT
422Unsuccessful open on filename containing newline at - line 3.
767a6a26
PM
423########
424# pp_sys.c [pp_sysread]
425use warnings 'io' ;
6bbf1b34
LM
426if ($^O eq 'dos') {
427 print <<EOM ;
428SKIPPED
429# skipped on dos
430EOM
431 exit ;
432}
767a6a26
PM
433my $file = "./xcv" ;
434open(F, ">$file") ;
435my $a = sysread(F, $a,10) ;
436no warnings 'io' ;
437my $a = sysread(F, $a,10) ;
438close F ;
b5fe5ca2
SR
439use warnings 'io' ;
440sysread(F, $a, 10);
441read(F, $a, 10);
442sysread(NONEXISTENT, $a, 10);
443read(NONEXISTENT, $a, 10);
767a6a26
PM
444unlink $file ;
445EXPECT
c6f2523f 446Filehandle F opened only for output at - line 12.
b5fe5ca2
SR
447sysread() on closed filehandle F at - line 17.
448read() on closed filehandle F at - line 18.
449sysread() on unopened filehandle NONEXISTENT at - line 19.
450read() on unopened filehandle NONEXISTENT at - line 20.
c289d2f7
JH
451########
452# pp_sys.c [pp_binmode]
453use warnings 'unopened' ;
454binmode(BLARG);
455$a = "BLERG";binmode($a);
456EXPECT
457binmode() on unopened filehandle BLARG at - line 3.
458binmode() on unopened filehandle at - line 4.
5d3e98de
RGS
459########
460# pp_sys.c [pp_lstat]
461use warnings 'io';
463cf062 462open FH, "../harness" or die "# $!";
365c80fa 463lstat FH;
5d3e98de
RGS
464open my $fh, $0 or die "# $!";
465lstat $fh;
466no warnings 'io';
365c80fa 467lstat FH;
5d3e98de 468lstat $fh;
365c80fa 469close FH;
5d3e98de
RGS
470close $fh;
471EXPECT
365c80fa
RGS
472lstat() on filehandle FH at - line 4.
473lstat() on filehandle $fh at - line 6.
90133b69
RGS
474########
475# pp_sys.c [pp_getc]
476use warnings qw(unopened closed) ;
477getc FOO;
478close STDIN;
479getc STDIN;
97e322ff
RGS
480# Create an empty file
481$file = 'getcwarn.tmp';
482open FH1, ">$file" or die "# $!"; close FH1;
483open FH2, $file or die "# $!";
484getc FH2; # Should not warn at EOF
485close FH2;
486getc FH2; # Warns, now
487unlink $file;
90133b69
RGS
488no warnings qw(unopened closed) ;
489getc FOO;
490getc STDIN;
97e322ff 491getc FH2;
90133b69
RGS
492EXPECT
493getc() on unopened filehandle FOO at - line 3.
494getc() on closed filehandle STDIN at - line 5.
97e322ff 495getc() on closed filehandle FH2 at - line 12.
4ef2275c
GA
496########
497# pp_sys.c [pp_sselect]
498use warnings 'misc';
499$x = 1;
ce712ebb 500select $x, undef, undef, 1;
4ef2275c 501no warnings 'misc';
ce712ebb 502select $x, undef, undef, 1;
4ef2275c
GA
503EXPECT
504Non-string passed as bitmask at - line 4.
4dc171f0 505########
8aee01e7
RGS
506use Config;
507BEGIN {
508 if (!$Config{d_fchdir}) {
509 print <<EOM;
510SKIPPED
511# fchdir not present
512EOM
513 exit;
514 }
515}
4dc171f0
PD
516opendir FOO, '.'; closedir FOO;
517open BAR, '.'; close BAR;
518opendir $dh, '.'; closedir $dh;
519open $fh, '.'; close $fh;
520chdir FOO;
521chdir BAR;
522chdir $dh;
523chdir $fh;
524use warnings qw(unopened closed) ;
525chdir FOO;
526chdir BAR;
527chdir $dh;
528chdir $fh;
529EXPECT
8aee01e7
RGS
530chdir() on unopened filehandle FOO at - line 20.
531chdir() on closed filehandle BAR at - line 21.
532chdir() on unopened filehandle $dh at - line 22.
533chdir() on closed filehandle $fh at - line 23.
abc718f2
RGS
534########
535# pp_sys.c [pp_open]
536use warnings;
537opendir FOO, ".";
538opendir my $foo, ".";
463cf062
NC
539open FOO, "../harness";
540open $foo, "../harness";
abc718f2 541no warnings qw(io deprecated);
463cf062
NC
542open FOO, "../harness";
543open $foo, "../harness";
abc718f2
RGS
544EXPECT
545Opening dirhandle FOO also as a file at - line 5.
546Opening dirhandle $foo also as a file at - line 6.
547########
548# pp_sys.c [pp_open_dir]
549use warnings;
463cf062
NC
550open FOO, "../harness";
551open my $foo, "../harness";
abc718f2
RGS
552opendir FOO, ".";
553opendir $foo, ".";
554no warnings qw(io deprecated);
555opendir FOO, ".";
556opendir $foo, ".";
557EXPECT
558Opening filehandle FOO also as a directory at - line 5.
559Opening filehandle $foo also as a directory at - line 6.