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