This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: [perl #126310] single quote UTF-8 malformation detection
[perl5.git] / t / lib / warnings / doio
index 338fc02..baa6b97 100644 (file)
@@ -87,10 +87,15 @@ Missing command in piped open at - line 3.
 # doio.c [Perl_do_open9]
 use warnings 'io' ;
 open(F, "<true\ncd");
+open(G, "<truecd\n");
+open(H, "<truecd\n\0");
 no warnings 'io' ;
-open(G, "<true\ncd");
+open(H, "<true\ncd");
+open(I, "<truecd\n");
+open(I, "<truecd\n\0");
 EXPECT
-Unsuccessful open on filename containing newline at - line 3.
+Unsuccessful open on filename containing newline at - line 4.
+Unsuccessful open on filename containing newline at - line 5.
 ########
 # doio.c [Perl_do_close] <<TODO
 use warnings 'unopened' ;
@@ -149,33 +154,46 @@ Use of uninitialized value $a in print at - line 3.
 use warnings 'io' ;
 stat "ab\ncd";
 lstat "ab\ncd";
+stat "abcd\n";
+lstat "abcd\n";
+stat "abcd\n\0";
+lstat "abcd\n\0";
 no warnings 'io' ;
 stat "ab\ncd";
 lstat "ab\ncd";
+stat "abcd\n";
+lstat "abcd\n";
+stat "abcd\n\0";
+lstat "abcd\n\0";
 EXPECT
-Unsuccessful stat on filename containing newline at - line 3.
-Unsuccessful stat on filename containing newline at - line 4.
+Unsuccessful stat on filename containing newline at - line 5.
+Unsuccessful stat on filename containing newline at - line 6.
+Unsuccessful stat on filename containing newline at - line 7.
+Unsuccessful stat on filename containing newline at - line 8.
 ########
 # doio.c [Perl_my_stat]
 use warnings 'io';
 -l STDIN;
+-l $fh;
+open $fh, $0 or die "# $!";
+-l $fh;
 no warnings 'io';
 -l STDIN;
+-l $fh;
+close $fh;
 EXPECT
 Use of -l on filehandle STDIN at - line 3.
+Use of -l on filehandle $fh at - line 6.
 ########
 # doio.c [Perl_my_stat]
 use utf8;
 use open qw( :utf8 :std );
 use warnings 'io';
--l $ᶠᚻ;
-open $ᶠᚻ, $0 or die "# $!";
--l $ᶠᚻ;
+-l ᶠᚻ;
 no warnings 'io';
--l $ᶠᚻ;
-close $ᶠᚻ;
+-l ᶠᚻ;
 EXPECT
-Use of -l on filehandle $ᶠᚻ at - line 7.
+Use of -l on filehandle ᶠᚻ at - line 5.
 ########
 # doio.c [Perl_do_aexec5]
 use warnings 'io' ;
@@ -184,6 +202,8 @@ no warnings 'io' ;
 exec "lskdjfalksdjfdjfkls","" ;
 EXPECT
 OPTION regex
+Statement unlikely to be reached at - line .+
+       \(Maybe you meant system\(\) when you said exec\(\)\?\)
 Can't exec "lskdjfalksdjfdjfkls": .+
 ########
 # doio.c [Perl_do_exec3]
@@ -193,6 +213,8 @@ no warnings 'io' ;
 exec "lskdjfalksdjfdjfkls", "abc" ;
 EXPECT
 OPTION regex
+Statement unlikely to be reached at - line .+
+       \(Maybe you meant system\(\) when you said exec\(\)\?\)
 Can't exec "lskdjfalksdjfdjfkls(:? abc)?": .+
 ########
 # doio.c [win32_execvp]
@@ -202,31 +224,45 @@ EXPECT
 ########
 # doio.c [Perl_nextargv]
 $^W = 0 ;
+# These happen to warn at different points within doio.c
+# This will open read only, and then be caught by an explicit check:
 my $filename = "./temp.dir" ;
+# Whereas these two will fail to open:
+my $dir0 = "./zero.dir" ;
+# but files and directories have a different error message if they don't open:
+my $file3 = "date|" ;
 mkdir $filename, 0777 
   or die "Cannot create directory $filename: $!\n" ;
+mkdir $dir0, 0
+  or die "Cannot create directory dir0: $!\n" ;
 {
-    local (@ARGV) = ($filename) ;
+    local (@ARGV) = ($filename, $dir0, $file3) ;
     local ($^I) = "" ;
     my $x = <> ;
 }
 {
     no warnings 'inplace' ;
-    local (@ARGV) = ($filename) ;
+    local (@ARGV) = ($filename, $dir0, $file3) ;
     local ($^I) = "" ;
     my $x = <> ;
 }
 {
     use warnings 'inplace' ;
-    local (@ARGV) = ($filename) ;
+    local (@ARGV) = ($filename, $dir0, $file3) ;
     local ($^I) = "" ;
     my $x = <> ;
 }
 rmdir $filename ;
+chmod 0777, $dir0 ;
+rmdir $dir0 ;
 EXPECT
-Can't do inplace edit: ./temp.dir is not a regular file at - line 9.
-Can't do inplace edit: ./temp.dir is not a regular file at - line 21.
-
+OPTION regex
+Can't do inplace edit: \./temp\.dir is not a regular file at - line 17\.
+Can't do inplace edit: \./zero\.dir is not a regular file at - line 17\.
+Can't open date\|: .*? at - line 17\.
+Can't do inplace edit: \./temp\.dir is not a regular file at - line 29\.
+Can't do inplace edit: \./zero\.dir is not a regular file at - line 29\.
+Can't open date\|: .*? at - line 29\.
 ########
 # doio.c [Perl_do_eof]
 use warnings 'io' ;
@@ -359,3 +395,35 @@ open ᶠᚻ2, ">doiowarn.tmp"; close ᶠᚻ2;
 unlink "doiowarn.tmp";
 EXPECT
 Filehandle STDIN reopened as ᶠᚻ1 only for output at - line 16.
+########
+open(my $i, "foo\0bar");
+use warnings 'io';
+open(my $i, "foo\0bar");
+EXPECT
+Invalid \0 character in pathname for open: foo\0bar at - line 3.
+########
+chmod(0, "foo\0bar");
+use warnings 'io';
+chmod(0, "foo\0bar");
+EXPECT
+Invalid \0 character in pathname for chmod: foo\0bar at - line 3.
+########
+unlink("foo\0bar", "foo\0bar2");
+use warnings 'io';
+unlink("foo\0bar", "foo\0bar2");
+EXPECT
+Invalid \0 character in pathname for unlink: foo\0bar at - line 3.
+Invalid \0 character in pathname for unlink: foo\0bar2 at - line 3.
+########
+utime(-1, -1, "foo\0bar", "foo\0bar2");
+use warnings 'io';
+utime(-1, -1, "foo\0bar", "foo\0bar2");
+EXPECT
+Invalid \0 character in pathname for utime: foo\0bar at - line 3.
+Invalid \0 character in pathname for utime: foo\0bar2 at - line 3.
+########
+my @foo = glob "foo\0bar";
+use warnings 'io';
+my @bar = glob "foo\0bar";
+EXPECT
+Invalid \0 character in pattern for glob: foo\0bar at - line 3.