xref: /openbsd/gnu/usr.bin/perl/t/lib/warnings/doio (revision cecf84d4)
1  doio.c
2
3  Can't open bidirectional pipe		[Perl_do_open9]
4    open(F, "| true |");
5
6  Missing command in piped open		[Perl_do_open9]
7    open(F, "| ");
8
9  Missing command in piped open		[Perl_do_open9]
10    open(F, " |");
11
12  warn(warn_nl, "open");		[Perl_do_open9]
13    open(F, "true\ncd")
14
15  close() on unopened filehandle %s	[Perl_do_close]
16    $a = "fred";close("$a")
17
18  tell() on closed filehandle		[Perl_do_tell]
19    $a = "fred";$a = tell($a)
20
21  seek() on closed filehandle		[Perl_do_seek]
22    $a = "fred";$a = seek($a,1,1)
23
24  sysseek() on closed filehandle	[Perl_do_sysseek]
25    $a = "fred";$a = seek($a,1,1)
26
27  warn(warn_uninit);			[Perl_do_print]
28    print $a ;
29
30  -x on closed filehandle %s 		[Perl_my_stat]
31    close STDIN ; -x STDIN ;
32
33  warn(warn_nl, "stat");		[Perl_my_stat]
34    stat "ab\ncd"
35
36  warn(warn_nl, "lstat");		[Perl_my_lstat]
37    lstat "ab\ncd"
38
39  Use of -l on filehandle %s		[Perl_my_lstat]
40
41  Can't exec \"%s\": %s 		[Perl_do_aexec5]
42
43  Can't exec \"%s\": %s 		[Perl_do_exec3]
44
45  Filehandle %s opened only for output	[Perl_do_eof]
46	my $a = eof STDOUT
47
48  Mandatory Warnings ALL TODO
49  ------------------
50  Can't do inplace edit: %s is not a regular file	[Perl_nextargv]
51     edit a directory
52
53  Can't do inplace edit: %s would not be unique		[Perl_nextargv]
54  Can't rename %s to %s: %s, skipping file		[Perl_nextargv]
55  Can't rename %s to %s: %s, skipping file		[Perl_nextargv]
56  Can't remove %s: %s, skipping file			[Perl_nextargv]
57  Can't do inplace edit on %s: %s			[Perl_nextargv]
58
59
60__END__
61# doio.c [Perl_do_open9]
62use warnings 'io' ;
63open(F, '|'."$^X -e 1|");
64close(F);
65no warnings 'io' ;
66open(G, '|'."$^X -e 1|");
67close(G);
68EXPECT
69Can't open bidirectional pipe at - line 3.
70########
71# doio.c [Perl_do_open9]
72use warnings 'io' ;
73open(F, "|      ");
74no warnings 'io' ;
75open(G, "|      ");
76EXPECT
77Missing command in piped open at - line 3.
78########
79# doio.c [Perl_do_open9]
80use warnings 'io' ;
81open(F, "      |");
82no warnings 'io' ;
83open(G, "      |");
84EXPECT
85Missing command in piped open at - line 3.
86########
87# doio.c [Perl_do_open9]
88use warnings 'io' ;
89open(F, "<true\ncd");
90no warnings 'io' ;
91open(G, "<true\ncd");
92EXPECT
93Unsuccessful open on filename containing newline at - line 3.
94########
95# doio.c [Perl_do_close] <<TODO
96use warnings 'unopened' ;
97close "fred" ;
98no warnings 'unopened' ;
99close "joe" ;
100EXPECT
101close() on unopened filehandle fred at - line 3.
102########
103# doio.c [Perl_do_tell Perl_do_seek Perl_do_sysseek Perl_my_stat]
104use warnings 'io' ;
105close STDIN ;
106tell(STDIN);
107$a = seek(STDIN,1,1);
108$a = sysseek(STDIN,1,1);
109-x STDIN ;
110stat(STDIN) ;
111$a = "fred";
112tell($a);
113seek($a,1,1);
114sysseek($a,1,1);
115-x $a; # ok
116stat($a); # ok
117no warnings 'io' ;
118close STDIN ;
119tell(STDIN);
120$a = seek(STDIN,1,1);
121$a = sysseek(STDIN,1,1);
122-x STDIN ;
123stat(STDIN) ;
124$a = "fred";
125tell($a);
126seek($a,1,1);
127sysseek($a,1,1);
128-x $a;
129stat($a);
130EXPECT
131tell() on closed filehandle STDIN at - line 4.
132seek() on closed filehandle STDIN at - line 5.
133sysseek() on closed filehandle STDIN at - line 6.
134-x on closed filehandle STDIN at - line 7.
135stat() on closed filehandle STDIN at - line 8.
136tell() on unopened filehandle at - line 10.
137seek() on unopened filehandle at - line 11.
138sysseek() on unopened filehandle at - line 12.
139########
140# doio.c [Perl_do_print]
141use warnings 'uninitialized' ;
142print $a ;
143no warnings 'uninitialized' ;
144print $b ;
145EXPECT
146Use of uninitialized value $a in print at - line 3.
147########
148# doio.c [Perl_my_stat Perl_my_lstat]
149use warnings 'io' ;
150stat "ab\ncd";
151lstat "ab\ncd";
152no warnings 'io' ;
153stat "ab\ncd";
154lstat "ab\ncd";
155EXPECT
156Unsuccessful stat on filename containing newline at - line 3.
157Unsuccessful stat on filename containing newline at - line 4.
158########
159# doio.c [Perl_my_stat]
160use warnings 'io';
161-l STDIN;
162-l $fh;
163open $fh, $0 or die "# $!";
164-l $fh;
165no warnings 'io';
166-l STDIN;
167-l $fh;
168close $fh;
169EXPECT
170Use of -l on filehandle STDIN at - line 3.
171Use of -l on filehandle $fh at - line 6.
172########
173# doio.c [Perl_my_stat]
174use utf8;
175use open qw( :utf8 :std );
176use warnings 'io';
177-l ᶠᚻ;
178no warnings 'io';
179-l ᶠᚻ;
180EXPECT
181Use of -l on filehandle ᶠᚻ at - line 5.
182########
183# doio.c [Perl_do_aexec5]
184use warnings 'io' ;
185exec "lskdjfalksdjfdjfkls","" ;
186no warnings 'io' ;
187exec "lskdjfalksdjfdjfkls","" ;
188EXPECT
189OPTION regex
190Statement unlikely to be reached at - line .+
191	\(Maybe you meant system\(\) when you said exec\(\)\?\)
192Can't exec "lskdjfalksdjfdjfkls": .+
193########
194# doio.c [Perl_do_exec3]
195use warnings 'io' ;
196exec "lskdjfalksdjfdjfkls", "abc" ;
197no warnings 'io' ;
198exec "lskdjfalksdjfdjfkls", "abc" ;
199EXPECT
200OPTION regex
201Statement unlikely to be reached at - line .+
202	\(Maybe you meant system\(\) when you said exec\(\)\?\)
203Can't exec "lskdjfalksdjfdjfkls(:? abc)?": .+
204########
205# doio.c [win32_execvp]
206use warnings 'exec' ;
207exec $^X, "-e0" ;
208EXPECT
209########
210# doio.c [Perl_nextargv]
211$^W = 0 ;
212# These happen to warn at different points within doio.c
213# This will open read only, and then be caught by an explicit check:
214my $filename = "./temp.dir" ;
215# Whereas these two will fail to open:
216my $dir0 = "./zero.dir" ;
217# but files and directories have a different error message if they don't open:
218my $file3 = "date|" ;
219mkdir $filename, 0777
220  or die "Cannot create directory $filename: $!\n" ;
221mkdir $dir0, 0
222  or die "Cannot create directory dir0: $!\n" ;
223{
224    local (@ARGV) = ($filename, $dir0, $file3) ;
225    local ($^I) = "" ;
226    my $x = <> ;
227}
228{
229    no warnings 'inplace' ;
230    local (@ARGV) = ($filename, $dir0, $file3) ;
231    local ($^I) = "" ;
232    my $x = <> ;
233}
234{
235    use warnings 'inplace' ;
236    local (@ARGV) = ($filename, $dir0, $file3) ;
237    local ($^I) = "" ;
238    my $x = <> ;
239}
240rmdir $filename ;
241chmod 0777, $dir0 ;
242rmdir $dir0 ;
243EXPECT
244OPTION regex
245Can't do inplace edit: \./temp\.dir is not a regular file at - line 17\.
246Can't do inplace edit: \./zero\.dir is not a regular file at - line 17\.
247Can't open date\|: .*? at - line 17\.
248Can't do inplace edit: \./temp\.dir is not a regular file at - line 29\.
249Can't do inplace edit: \./zero\.dir is not a regular file at - line 29\.
250Can't open date\|: .*? at - line 29\.
251########
252# doio.c [Perl_do_eof]
253use warnings 'io' ;
254my $a = eof STDOUT ;
255no warnings 'io' ;
256$a = eof STDOUT ;
257EXPECT
258Filehandle STDOUT opened only for output at - line 3.
259########
260# doio.c [Perl_do_openn]
261use Config;
262BEGIN {
263    if ($Config{useperlio}) {
264	print <<EOM;
265SKIPPED
266# warns only without perlio
267EOM
268	exit;
269    }
270}
271use warnings 'io';
272my $x = "foo";
273open FOO, '>', \$x;
274open BAR, '>&', \*STDOUT; # should not warn
275no warnings 'io';
276open FOO, '>', \$x;
277EXPECT
278Can't open a reference at - line 14.
279########
280# doio.c [Perl_do_openn]
281use Config;
282BEGIN {
283    if (!$Config{useperlio}) {
284	print <<EOM;
285SKIPPED
286# warns only with perlio
287EOM
288	exit;
289    }
290}
291use warnings 'io' ;
292close STDOUT;
293open FH1, "../harness"; close FH1;
294no warnings 'io' ;
295open FH2, "../harness"; close FH2;
296EXPECT
297Filehandle STDOUT reopened as FH1 only for input at - line 14.
298########
299# doio.c [Perl_do_openn]
300use Config;
301use utf8;
302use open qw( :utf8 :std );
303BEGIN {
304    if (!$Config{useperlio}) {
305	print <<EOM;
306SKIPPED
307# warns only with perlio
308EOM
309	exit;
310    }
311}
312use warnings 'io' ;
313close STDOUT;
314open ᶠᚻ1, "../harness"; close ᶠᚻ1;
315no warnings 'io' ;
316open ᶠᚻ2, "../harness"; close ᶠᚻ2;
317EXPECT
318Filehandle STDOUT reopened as ᶠᚻ1 only for input at - line 16.
319########
320# doio.c [Perl_do_openn]
321use Config;
322BEGIN {
323    if (!$Config{useperlio}) {
324	print <<EOM;
325SKIPPED
326# warns only with perlio
327EOM
328	exit;
329    }
330}
331use warnings 'io' ;
332close STDIN;
333open my $fh1, ">doiowarn.tmp"; close $fh1;
334no warnings 'io' ;
335open my $fh2, ">doiowarn.tmp"; close $fh2;
336unlink "doiowarn.tmp";
337EXPECT
338Filehandle STDIN reopened as $fh1 only for output at - line 14.
339########
340# doio.c [Perl_do_openn]
341use Config;
342use utf8;
343use open qw( :utf8 :std );
344BEGIN {
345    if (!$Config{useperlio}) {
346	print <<EOM;
347SKIPPED
348# warns only with perlio
349EOM
350	exit;
351    }
352}
353use warnings 'io' ;
354close STDIN;
355open my $ᶠᚻ1, ">doiowarn.tmp"; close $ᶠᚻ1;
356no warnings 'io' ;
357open my $ᶠᚻ2, ">doiowarn.tmp"; close $ᶠᚻ2;
358unlink "doiowarn.tmp";
359EXPECT
360Filehandle STDIN reopened as $ᶠᚻ1 only for output at - line 16.
361########
362# doio.c [Perl_do_openn]
363use Config;
364use utf8;
365use open qw( :utf8 :std );
366BEGIN {
367    if (!$Config{useperlio}) {
368	print <<EOM;
369SKIPPED
370# warns only with perlio
371EOM
372	exit;
373    }
374}
375use warnings 'io' ;
376close STDIN;
377open ᶠᚻ1, ">doiowarn.tmp"; close ᶠᚻ1;
378no warnings 'io' ;
379open ᶠᚻ2, ">doiowarn.tmp"; close ᶠᚻ2;
380unlink "doiowarn.tmp";
381EXPECT
382Filehandle STDIN reopened as ᶠᚻ1 only for output at - line 16.
383########
384open(my $i, "foo\0bar");
385use warnings 'io';
386open(my $i, "foo\0bar");
387EXPECT
388Invalid \0 character in pathname for open: foo\0bar at - line 3.
389########
390chmod(0, "foo\0bar");
391use warnings 'io';
392chmod(0, "foo\0bar");
393EXPECT
394Invalid \0 character in pathname for chmod: foo\0bar at - line 3.
395########
396unlink("foo\0bar", "foo\0bar2");
397use warnings 'io';
398unlink("foo\0bar", "foo\0bar2");
399EXPECT
400Invalid \0 character in pathname for unlink: foo\0bar at - line 3.
401Invalid \0 character in pathname for unlink: foo\0bar2 at - line 3.
402########
403utime(-1, -1, "foo\0bar", "foo\0bar2");
404use warnings 'io';
405utime(-1, -1, "foo\0bar", "foo\0bar2");
406EXPECT
407Invalid \0 character in pathname for utime: foo\0bar at - line 3.
408Invalid \0 character in pathname for utime: foo\0bar2 at - line 3.
409########
410my @foo = glob "foo\0bar";
411use warnings 'io';
412my @bar = glob "foo\0bar";
413EXPECT
414Invalid \0 character in pattern for glob: foo\0bar at - line 3.
415