Skip Menu |

This queue is for tickets about the Win32API-File CPAN distribution.

Report information
The Basics
Id: 28046
Status: resolved
Priority: 0/
Queue: Win32API-File

People
Owner: Nobody in particular
Requestors: RURBAN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.1001
Fixed in: 0.1001_02



Subject: merge #43285-Win32API-File-t patch from blead
Attached patch merges #43285-Win32API-File-t patch from blead to make the test language-inspecific. -- Reini Urban
Subject: Win32API-File-0.1001.patch
difforig Win32API-File-0.1001 2007-07-08 Reini Urban <rurban@x-ray.at> diff -ub Win32API-File-0.1001/t/file.t.orig --- Win32API-File-0.1001/t/file.t.orig 2006-06-30 13:47:43.000000000 +0000 +++ Win32API-File-0.1001/t/file.t 2007-07-08 10:30:07.352000000 +0000 @@ -4,8 +4,30 @@ ######################### We start with some black magic to print on failure. -BEGIN { $|= 1; print "1..267\n"; } +BEGIN { + $|= 1; + + # when building perl, skip this test if Win32API::File isn't being built + if ( $ENV{PERL_CORE} ) { + require Config; + if ( $Config::Config{extensions} !~ m:(?<!\S)Win32API/File(?!\S): ) { + print "1..0 # Skip Win32API::File extension not built\n"; + exit(); + } + } + + print "1..267\n"; +} END {print "not ok 1\n" unless $loaded;} + +# Win32API::File does an implicit "require Win32", but +# the ../lib directory in @INC will no longer work once +# we chdir() into the TEMP directory. + +use File::Spec; +use Carp; +use Carp::Heavy; + use Win32API::File qw(:ALL); $loaded = 1; print "ok 1\n"; @@ -16,19 +38,16 @@ use strict qw(subs); -$temp= $ENV{"TMP"}; -$temp= $ENV{"TEMP"} unless -d $temp; -$temp= "C:/Temp" unless -d $temp; -$temp= "." unless -d $temp; +$temp= File::Spec->tmpdir(); $dir= "W32ApiF.tmp"; $ENV{WINDIR} = $ENV{SYSTEMROOT} if not exists $ENV{WINDIR}; chdir( $temp ) or die "# Can't cd to temp directory, $temp: $!\n"; - +$tempdir = File::Spec->catdir($temp,$dir); if( -d $dir ) { - print "# deleting $temp\\$dir\\*\n" if glob "$dir/*"; + print "# deleting ",File::Spec->catdir($temp,$dir,'*'),"\n" if glob "$dir/*"; for (glob "$dir/*") { chmod 0777, $_; @@ -37,13 +56,12 @@ rmdir $dir or die "Could not rmdir $dir: $!"; } mkdir( $dir, 0777 ) - or die "# Can't create temp dir, $temp/$dir: $!\n"; -print "# chdir $temp\\$dir\n"; + or die "# Can't create temp dir, $tempdir: $!\n"; +print "# chdir $tempdir\n"; chdir( $dir ) - or die "# Can't cd to my dir, $temp/$dir: $!\n"; - + or die "# Can't cd to my dir, $tempdir: $!\n"; $h1= createFile( "ReadOnly.txt", "r", { Attributes=>"r" } ); -$ok= ! $h1 && fileLastError() =~ /not find the file?/i; +$ok= ! $h1 && Win32API::File::_fileLastError() == 2; # could not find the file $ok or print "# ","".fileLastError(),"\n"; print $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 2 if( ! $ok ) { CloseHandle($h1); unlink("ReadOnly.txt"); } @@ -57,13 +75,13 @@ print $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 4 $h2= createFile( "ReadOnly.txt", "rcn" ); -$ok= ! $h2 && fileLastError() =~ /file exists?/i; +$ok= ! $h2 && Win32API::File::_fileLastError() == 80; # file exists $ok or print "# ",fileLastError(),"\n"; print $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 5 if( ! $ok ) { CloseHandle($h2); } $h2= createFile( "ReadOnly.txt", "rwke" ); -$ok= ! $h2 && fileLastError() =~ /access is denied?/i; +$ok= ! $h2 && Win32API::File::_fileLastError() == 5; # access is denied $ok or print "# ",fileLastError(),"\n"; print $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 6 if( ! $ok ) { CloseHandle($h2); } @@ -100,7 +118,7 @@ print $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 12 $ok= ! ReadFile( $h2, $text, 80, $len, [] ) - && fileLastError() =~ /handle is invalid?/i; + && Win32API::File::_fileLastError() == 6; # handle is invalid $ok or print "# ",fileLastError(),"\n"; print $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 13 @@ -153,7 +171,7 @@ } else { unlink("CanWrite.txt"); - $ok= -e "CanWrite.txt" && $! =~ /permission denied/i; + $ok = -e "CanWrite.txt" && $! =~ /permission denied/i; $ok or print "# $!\n"; } print $ok ? "" : "not ", "ok ", ++$test, "$skip\n"; # ok 22 @@ -163,37 +181,37 @@ CloseHandle( $h1 ); $ok= ! DeleteFile( "ReadOnly.txt" ) - && fileLastError() =~ /access is denied?/i; + && Win32API::File::_fileLastError() == 5; # access is denied $ok or print "# ",fileLastError(),"\n"; print $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 23 $ok= ! CopyFile( "ReadOnly.txt", "CanWrite.txt", 1 ) - && fileLastError() =~ /file exists?/i; + && Win32API::File::_fileLastError() == 80; # file exists $ok or print "# ",fileLastError(),"\n"; print $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 24 $ok= ! CopyFile( "CanWrite.txt", "ReadOnly.txt", 0 ) - && fileLastError() =~ /access is denied?/i; + && Win32API::File::_fileLastError() == 5; # access is denied $ok or print "# ",fileLastError(),"\n"; print $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 25 $ok= ! MoveFile( "NoSuchFile", "NoSuchDest" ) - && fileLastError() =~ /not find the file/i; + && Win32API::File::_fileLastError() == 2; # not find the file $ok or print "# ",fileLastError(),"\n"; print $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 26 $ok= ! MoveFileEx( "NoSuchFile", "NoSuchDest", 0 ) - && fileLastError() =~ /not find the file/i; + && Win32API::File::_fileLastError() == 2; # not find the file $ok or print "# ",fileLastError(),"\n"; print $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 27 $ok= ! MoveFile( "ReadOnly.txt", "CanWrite.txt" ) - && fileLastError() =~ /file already exists?/i; + && Win32API::File::_fileLastError() == 183; # file already exists $ok or print "# ",fileLastError(),"\n"; print $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 28 $ok= ! MoveFileEx( "ReadOnly.txt", "CanWrite.txt", 0 ) - && fileLastError() =~ /file already exists?/i; + && Win32API::File::_fileLastError() == 183; # file already exists $ok or print "# ",fileLastError(),"\n"; print $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 29 @@ -203,7 +221,8 @@ print $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 30 $ok= ! MoveFileEx( "CanWrite.txt", "ReadOnly.cp", MOVEFILE_REPLACE_EXISTING ) - && fileLastError() =~ /access is denied?|cannot create/i; + && (Win32API::File::_fileLastError() == 5 # access is denied + || Win32API::File::_fileLastError() == 183); # already exists $ok or print "# ",fileLastError(),"\n"; print $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 31 @@ -223,11 +242,16 @@ print $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 34 $ok= ! DeleteFile( "Moved.cp" ) - && fileLastError() =~ /access is denied?/i; + && Win32API::File::_fileLastError() == 5; # access is denied $ok or print "# ",fileLastError(),"\n"; print $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 35 -system( "attrib -r Moved.cp" ); +if ($^O eq 'cygwin') { + chmod( 0200 | 07777 & (stat("Moved.cp"))[2], "Moved.cp" ); +} +else { + system( "attrib -r Moved.cp" ); +} $ok= DeleteFile( "Moved.cp" ); $ok or print "# ",fileLastError(),"\n";