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