xref: /openbsd-src/gnu/usr.bin/perl/t/lib/warnings/pp_sys (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
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  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
15  Filehandle %s opened only for input		[pp_leavewrite]
16    format STDIN =
17    .
18    write STDIN;
19
20  write() on closed filehandle %s		[pp_leavewrite]
21    format STDIN =
22    .
23    close STDIN;
24    write STDIN ;
25
26  page overflow	 				[pp_leavewrite]
27
28  printf() on unopened filehandle abc		[pp_prtf]
29    $a = "abc"; printf $a "fred"
30
31  Filehandle %s opened only for input		[pp_prtf]
32    $a = "abc";
33    printf $a "fred"
34
35  printf() on closed filehandle %s		[pp_prtf]
36    close STDIN ;
37    printf STDIN "fred"
38
39  syswrite() on closed filehandle %s		[pp_send]
40    close STDIN;
41    syswrite STDIN, "fred", 1;
42
43  send() on closed socket %s			[pp_send]
44    close STDIN;
45    send STDIN, "fred", 1
46
47  bind() on closed socket %s			[pp_bind]
48    close STDIN;
49    bind STDIN, "fred" ;
50
51
52  connect() on closed socket %s			[pp_connect]
53    close STDIN;
54    connect STDIN, "fred" ;
55
56  listen() on closed socket %s			[pp_listen]
57    close STDIN;
58    listen STDIN, 2;
59
60  accept() on closed socket %s			[pp_accept]
61    close STDIN;
62    accept "fred", STDIN ;
63
64  shutdown() on closed socket %s		[pp_shutdown]
65    close STDIN;
66    shutdown STDIN, 0;
67
68  setsockopt() on closed socket %s		[pp_ssockopt]
69  getsockopt() on closed socket	%s		[pp_ssockopt]
70    close STDIN;
71    setsockopt STDIN, 1,2,3;
72    getsockopt STDIN, 1,2;
73
74  getsockname() on closed socket %s		[pp_getpeername]
75  getpeername() on closed socket %s		[pp_getpeername]
76    close STDIN;
77    getsockname STDIN;
78    getpeername STDIN;
79
80  flock() on closed socket %s			[pp_flock]
81  flock() on closed socket			[pp_flock]
82    close STDIN;
83    flock STDIN, 8;
84    flock $a, 8;
85
86  warn(warn_nl, "stat");			[pp_stat]
87
88  -T on closed filehandle %s
89  stat() on closed filehandle %s
90	close STDIN ; -T STDIN ; stat(STDIN) ;
91
92  warn(warn_nl, "open");			[pp_fttext]
93    -T "abc\ndef" ;
94
95  Filehandle %s opened only for output		[pp_sysread]
96	my $file = "./xcv" ;
97	open(F, ">$file") ;
98	my $a = sysread(F, $a,10) ;
99
100  lstat on filehandle %s			[pp_lstat]
101
102  getc() on unopened filehandle			[pp_getc]
103
104  getc() on closed filehandle			[pp_getc]
105
106  Non-string passed as bitmask			[pp_sselect]
107
108__END__
109# pp_sys.c [pp_untie]
110use warnings 'untie' ;
111sub TIESCALAR { bless [] } ;
112$b = tie $a, 'main';
113untie $a ;
114no warnings 'untie' ;
115$c = tie $d, 'main';
116untie $d ;
117EXPECT
118untie attempted while 1 inner references still exist at - line 5.
119########
120# pp_sys.c [pp_leavewrite]
121use warnings 'io' ;
122format STDIN =
123.
124write STDIN;
125no warnings 'io' ;
126write STDIN;
127EXPECT
128Filehandle STDIN opened only for input at - line 5.
129########
130# pp_sys.c [pp_leavewrite]
131use warnings 'closed' ;
132format STDIN =
133.
134close STDIN;
135write STDIN;
136opendir STDIN, ".";
137write STDIN;
138closedir STDIN;
139no warnings 'closed' ;
140write STDIN;
141opendir STDIN, ".";
142write STDIN;
143EXPECT
144write() on closed filehandle STDIN at - line 6.
145write() on closed filehandle STDIN at - line 8.
146	(Are you trying to call write() on dirhandle STDIN?)
147########
148# pp_sys.c [pp_leavewrite]
149use warnings 'io' ;
150format STDOUT_TOP =
151abc
152.
153format STDOUT =
154def
155ghi
156.
157$= = 1 ;
158$- =1 ;
159open STDOUT, ">".($^O eq 'VMS'? 'NL:' : '/dev/null') ;
160write ;
161no warnings 'io' ;
162write ;
163EXPECT
164page overflow at - line 13.
165########
166# pp_sys.c [pp_prtf]
167use warnings 'unopened' ;
168$a = "abc";
169printf $a "fred";
170no warnings 'unopened' ;
171printf $a "fred";
172EXPECT
173printf() on unopened filehandle abc at - line 4.
174########
175# pp_sys.c [pp_prtf]
176use warnings 'closed' ;
177close STDIN ;
178printf STDIN "fred";
179opendir STDIN, ".";
180printf STDIN "fred";
181closedir STDIN;
182no warnings 'closed' ;
183printf STDIN "fred";
184opendir STDIN, ".";
185printf STDIN "fred";
186EXPECT
187printf() on closed filehandle STDIN at - line 4.
188printf() on closed filehandle STDIN at - line 6.
189	(Are you trying to call printf() on dirhandle STDIN?)
190########
191# pp_sys.c [pp_prtf]
192use warnings 'io' ;
193printf STDIN "fred";
194no warnings 'io' ;
195printf STDIN "fred";
196EXPECT
197Filehandle STDIN opened only for input at - line 3.
198########
199# pp_sys.c [pp_send]
200use warnings 'io' ;
201syswrite STDIN, "fred";
202no warnings 'io' ;
203syswrite STDIN, "fred";
204EXPECT
205Filehandle STDIN opened only for input at - line 3.
206########
207# pp_sys.c [pp_send]
208use warnings 'closed' ;
209close STDIN;
210syswrite STDIN, "fred", 1;
211opendir STDIN, ".";
212syswrite STDIN, "fred", 1;
213closedir STDIN;
214no warnings 'closed' ;
215syswrite STDIN, "fred", 1;
216opendir STDIN, ".";
217syswrite STDIN, "fred", 1;
218EXPECT
219syswrite() on closed filehandle STDIN at - line 4.
220syswrite() on closed filehandle STDIN at - line 6.
221	(Are you trying to call syswrite() on dirhandle STDIN?)
222########
223# pp_sys.c [pp_flock]
224use Config;
225BEGIN {
226  if ( !$Config{d_flock} &&
227       !$Config{d_fcntl_can_lock} &&
228       !$Config{d_lockf} ) {
229    print <<EOM ;
230SKIPPED
231# flock not present
232EOM
233    exit ;
234  }
235}
236use warnings qw(unopened closed);
237close STDIN;
238flock STDIN, 8;
239opendir STDIN, ".";
240flock STDIN, 8;
241flock FOO, 8;
242flock $a, 8;
243no warnings qw(unopened closed);
244flock STDIN, 8;
245opendir STDIN, ".";
246flock STDIN, 8;
247flock FOO, 8;
248flock $a, 8;
249EXPECT
250flock() on closed filehandle STDIN at - line 16.
251flock() on closed filehandle STDIN at - line 18.
252	(Are you trying to call flock() on dirhandle STDIN?)
253flock() on unopened filehandle FOO at - line 19.
254flock() on unopened filehandle at - line 20.
255########
256# pp_sys.c [pp_prtf pp_send pp_bind pp_connect pp_listen pp_accept pp_shutdown pp_ssockopt ppp_getpeername]
257use warnings 'io' ;
258use Config;
259BEGIN {
260  if ( $^O ne 'VMS' and ! $Config{d_socket}) {
261    print <<EOM ;
262SKIPPED
263# send not present
264# bind not present
265# connect not present
266# accept not present
267# shutdown not present
268# setsockopt not present
269# getsockopt not present
270# getsockname not present
271# getpeername not present
272EOM
273    exit ;
274  }
275}
276close STDIN;
277send STDIN, "fred", 1;
278bind STDIN, "fred" ;
279connect STDIN, "fred" ;
280listen STDIN, 2;
281accept "fred", STDIN;
282shutdown STDIN, 0;
283setsockopt STDIN, 1,2,3;
284getsockopt STDIN, 1,2;
285getsockname STDIN;
286getpeername STDIN;
287opendir STDIN, ".";
288send STDIN, "fred", 1;
289bind STDIN, "fred" ;
290connect STDIN, "fred" ;
291listen STDIN, 2;
292accept "fred", STDIN;
293shutdown STDIN, 0;
294setsockopt STDIN, 1,2,3;
295getsockopt STDIN, 1,2;
296getsockname STDIN;
297getpeername STDIN;
298closedir STDIN;
299no warnings 'io' ;
300send STDIN, "fred", 1;
301bind STDIN, "fred" ;
302connect STDIN, "fred" ;
303listen STDIN, 2;
304accept STDIN, "fred" ;
305shutdown STDIN, 0;
306setsockopt STDIN, 1,2,3;
307getsockopt STDIN, 1,2;
308getsockname STDIN;
309getpeername STDIN;
310opendir STDIN, ".";
311send STDIN, "fred", 1;
312bind STDIN, "fred" ;
313connect STDIN, "fred" ;
314listen STDIN, 2;
315accept "fred", STDIN;
316shutdown STDIN, 0;
317setsockopt STDIN, 1,2,3;
318getsockopt STDIN, 1,2;
319getsockname STDIN;
320getpeername STDIN;
321EXPECT
322send() on closed socket STDIN at - line 22.
323bind() on closed socket STDIN at - line 23.
324connect() on closed socket STDIN at - line 24.
325listen() on closed socket STDIN at - line 25.
326accept() on closed socket STDIN at - line 26.
327shutdown() on closed socket STDIN at - line 27.
328setsockopt() on closed socket STDIN at - line 28.
329getsockopt() on closed socket STDIN at - line 29.
330getsockname() on closed socket STDIN at - line 30.
331getpeername() on closed socket STDIN at - line 31.
332send() on closed socket STDIN at - line 33.
333	(Are you trying to call send() on dirhandle STDIN?)
334bind() on closed socket STDIN at - line 34.
335	(Are you trying to call bind() on dirhandle STDIN?)
336connect() on closed socket STDIN at - line 35.
337	(Are you trying to call connect() on dirhandle STDIN?)
338listen() on closed socket STDIN at - line 36.
339	(Are you trying to call listen() on dirhandle STDIN?)
340accept() on closed socket STDIN at - line 37.
341	(Are you trying to call accept() on dirhandle STDIN?)
342shutdown() on closed socket STDIN at - line 38.
343	(Are you trying to call shutdown() on dirhandle STDIN?)
344setsockopt() on closed socket STDIN at - line 39.
345	(Are you trying to call setsockopt() on dirhandle STDIN?)
346getsockopt() on closed socket STDIN at - line 40.
347	(Are you trying to call getsockopt() on dirhandle STDIN?)
348getsockname() on closed socket STDIN at - line 41.
349	(Are you trying to call getsockname() on dirhandle STDIN?)
350getpeername() on closed socket STDIN at - line 42.
351	(Are you trying to call getpeername() on dirhandle STDIN?)
352########
353# pp_sys.c [pp_stat]
354use warnings 'newline' ;
355stat "abc\ndef";
356no warnings 'newline' ;
357stat "abc\ndef";
358EXPECT
359Unsuccessful stat on filename containing newline at - line 3.
360########
361# pp_sys.c [pp_fttext]
362use warnings qw(unopened closed) ;
363close STDIN ;
364-T STDIN ;
365stat(STDIN) ;
366-T HOCUS;
367stat(POCUS);
368no warnings qw(unopened closed) ;
369-T STDIN ;
370stat(STDIN);
371-T HOCUS;
372stat(POCUS);
373EXPECT
374-T on closed filehandle STDIN at - line 4.
375stat() on closed filehandle STDIN at - line 5.
376-T on unopened filehandle HOCUS at - line 6.
377stat() on unopened filehandle POCUS at - line 7.
378########
379# pp_sys.c [pp_fttext]
380use warnings 'newline' ;
381-T "abc\ndef" ;
382no warnings 'newline' ;
383-T "abc\ndef" ;
384EXPECT
385Unsuccessful open on filename containing newline at - line 3.
386########
387# pp_sys.c [pp_sysread]
388use warnings 'io' ;
389if ($^O eq 'dos') {
390    print <<EOM ;
391SKIPPED
392# skipped on dos
393EOM
394    exit ;
395}
396my $file = "./xcv" ;
397open(F, ">$file") ;
398my $a = sysread(F, $a,10) ;
399no warnings 'io' ;
400my $a = sysread(F, $a,10) ;
401close F ;
402use warnings 'io' ;
403sysread(F, $a, 10);
404read(F, $a, 10);
405sysread(NONEXISTENT, $a, 10);
406read(NONEXISTENT, $a, 10);
407unlink $file ;
408EXPECT
409Filehandle F opened only for output at - line 12.
410sysread() on closed filehandle F at - line 17.
411read() on closed filehandle F at - line 18.
412sysread() on unopened filehandle NONEXISTENT at - line 19.
413read() on unopened filehandle NONEXISTENT at - line 20.
414########
415# pp_sys.c [pp_binmode]
416use warnings 'unopened' ;
417binmode(BLARG);
418$a = "BLERG";binmode($a);
419EXPECT
420binmode() on unopened filehandle BLARG at - line 3.
421binmode() on unopened filehandle at - line 4.
422########
423# pp_sys.c [pp_lstat]
424use warnings 'io';
425open FH, "harness" or die "# $!";
426lstat FH;
427open my $fh, $0 or die "# $!";
428lstat $fh;
429no warnings 'io';
430lstat FH;
431lstat $fh;
432close FH;
433close $fh;
434EXPECT
435lstat() on filehandle FH at - line 4.
436lstat() on filehandle $fh at - line 6.
437########
438# pp_sys.c [pp_getc]
439use warnings qw(unopened closed) ;
440getc FOO;
441close STDIN;
442getc STDIN;
443# Create an empty file
444$file = 'getcwarn.tmp';
445open FH1, ">$file" or die "# $!"; close FH1;
446open FH2, $file    or die "# $!";
447getc FH2; # Should not warn at EOF
448close FH2;
449getc FH2; # Warns, now
450unlink $file;
451no warnings qw(unopened closed) ;
452getc FOO;
453getc STDIN;
454getc FH2;
455EXPECT
456getc() on unopened filehandle FOO at - line 3.
457getc() on closed filehandle STDIN at - line 5.
458getc() on closed filehandle FH2 at - line 12.
459########
460# pp_sys.c [pp_sselect]
461use warnings 'misc';
462$x = 1;
463select $x, undef, undef, 1;
464no warnings 'misc';
465select $x, undef, undef, 1;
466EXPECT
467Non-string passed as bitmask at - line 4.
468########
469use Config;
470BEGIN {
471    if (!$Config{d_fchdir}) {
472	print <<EOM;
473SKIPPED
474# fchdir not present
475EOM
476	exit;
477    }
478}
479opendir FOO, '.'; closedir FOO;
480open BAR, '.'; close BAR;
481opendir $dh, '.'; closedir $dh;
482open $fh, '.'; close $fh;
483chdir FOO;
484chdir BAR;
485chdir $dh;
486chdir $fh;
487use warnings qw(unopened closed) ;
488chdir FOO;
489chdir BAR;
490chdir $dh;
491chdir $fh;
492EXPECT
493chdir() on unopened filehandle FOO at - line 20.
494chdir() on closed filehandle BAR at - line 21.
495chdir() on unopened filehandle $dh at - line 22.
496chdir() on closed filehandle $fh at - line 23.
497########
498# pp_sys.c [pp_open]
499use warnings;
500opendir FOO, ".";
501opendir my $foo, ".";
502open FOO, "TEST";
503open $foo, "TEST";
504no warnings qw(io deprecated);
505open FOO, "TEST";
506open $foo, "TEST";
507EXPECT
508Opening dirhandle FOO also as a file at - line 5.
509Opening dirhandle $foo also as a file at - line 6.
510########
511# pp_sys.c [pp_open_dir]
512use warnings;
513open FOO, "TEST";
514open my $foo, "TEST";
515opendir FOO, ".";
516opendir $foo, ".";
517no warnings qw(io deprecated);
518opendir FOO, ".";
519opendir $foo, ".";
520EXPECT
521Opening filehandle FOO also as a directory at - line 5.
522Opening filehandle $foo also as a directory at - line 6.
523