1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#!/usr/bin/perl
# Test that File::Remove (with or without globbing) supports the use of
# spaces in the path to delete.
use strict;
use warnings;
BEGIN
{
$| = 1;
$^W = 1;
}
use Test::More qw(no_plan);
use File::Spec::Functions ':ALL';
use File::Copy ();
use File::Remove ();
#####################################################################
# Set up for the test
my $t = catdir( curdir(), 't' );
my $s = catdir( $t, 'spaced path' );
my $f1 = catfile( $s, 'foo1.txt' );
my $f2 = catfile( $s, 'foo2.txt' );
my $f3 = catfile( $s, 'bar.txt' );
sub create_directory
{
mkdir( $s, 0777 ) or die "Failed to create $s";
ok( -d $s, "Created $s ok" );
ok( -r $s, "Created $s -r" );
ok( -w $s, "Created $s -w" );
my $spew = sub {
my $fn = shift;
open( my $fh, ">", $fn ) or die "Failed to create $fn";
print {$fh} "Test\n";
close $fh;
return;
};
$spew->($f1);
$spew->($f2);
$spew->($f3);
}
sub clear_directory
{
if ( -e $f1 )
{
unlink($f1) or die "unlink: $f1 failed";
!-e $f1 or die "unlink didn't work";
}
if ( -e $f2 )
{
unlink($f2) or die "unlink: $f2 failed";
!-e $f2 or die "unlink didn't work";
}
if ( -e $f3 )
{
unlink($f3) or die "unlink: $f3 failed";
!-e $f3 or die "unlink didn't work";
}
if ( -e $s )
{
rmdir($s) or die "rmdir: $s failed";
!-e $s or die "rmdir didn't work";
}
}
# Make sure there is no directory from a previous run
clear_directory();
# Create the directory
create_directory();
# Schedule cleanup
END
{
clear_directory();
}
#####################################################################
# Main Testing
# Expand a glob that should match the foo files
my @match = File::Remove::expand('t/spaced path/foo*');
is( scalar(@match), 2, 'Found two results' );
ok( $match[0] =~ /foo1.txt/, 'Found foo1' );
ok( $match[1] =~ /foo2.txt/, 'Found foo2' );
|