6 1 while unlink 'ecmdfile';
7 # forcibly remove ecmddir/temp2, but don't import mkpath
9 File::Path::rmtree( 'ecmddir' );
12 use Test::More tests => 21;
16 skip( 'ExtUtils::Command is a Win32 module', 21 )
17 unless $^O =~ /Win32/;
19 use vars qw( *CORE::GLOBAL::exit );
21 # bad neighbor, but test_f() uses exit()
22 *CORE::GLOBAL::exit = sub { return @_ };
24 use_ok( 'ExtUtils::Command' );
26 # get a file in the current directory, replace last char with wildcard
30 opendir(DIR, File::Spec->curdir());
31 while ($file = readdir(DIR)) {
32 last if $file =~ /^\w/;
36 # this should find the file
37 ($ARGV[0] = $file) =~ s/.\z/\?/;
38 ExtUtils::Command::expand_wildcards();
40 is( scalar @ARGV, 1, 'found one file' );
41 like( $ARGV[0], qr/$file/, 'expanded wildcard ? successfully' );
43 # try it with the asterisk now
44 ($ARGV[0] = $file) =~ s/.{3}\z/\*/;
45 ExtUtils::Command::expand_wildcards();
47 ok( (grep { qr/$file/ } @ARGV), 'expanded wildcard * successfully' );
49 # concatenate this file with itself
50 # be extra careful the regex doesn't match itself
51 my $out = tie *STDOUT, 'TieOut';
55 is( scalar( $$out =~ s/use_ok\( 'ExtUtils::Command'//g), 2,
56 'concatenation worked' );
58 # the truth value here is reversed -- Perl true is C false
59 @ARGV = ( 'ecmdfile' );
60 ok( test_f(), 'testing non-existent file' );
62 @ARGV = ( 'ecmdfile' );
63 is( ! test_f(), (-f 'ecmdfile'), 'testing non-existent file' );
65 # these are destructive, have to keep setting @ARGV
66 @ARGV = ( 'ecmdfile' );
69 @ARGV = ( 'ecmdfile' );
70 ok( test_f(), 'now creating that file' );
72 @ARGV = ( 'ecmdfile' );
73 ok( -e $ARGV[0], 'created!' );
76 utime ($now, $now, $ARGV[0]);
78 # Just checking modify time stamp, access time stamp is set
79 # to the beginning of the day in Win95
80 is( (stat($ARGV[0]))[9], $now, 'checking modify time stamp' );
82 # change a file to read-only
83 @ARGV = ( 0600, 'ecmdfile' );
84 ExtUtils::Command::chmod();
86 is( (stat('ecmdfile'))[2] & 07777, 0600, 'removed non-owner permissions' );
89 @ARGV = ( File::Spec->join( 'ecmddir', 'temp2' ) );
90 ok( ! -e $ARGV[0], 'temp directory not there yet' );
93 ok( -e $ARGV[0], 'temp directory created' );
95 # copy a file to a nested subdirectory
96 unshift @ARGV, 'ecmdfile';
99 ok( -e File::Spec->join( 'ecmddir', 'temp2', 'ecmdfile' ), 'copied okay' );
101 # cp should croak if destination isn't directory (not a great warning)
102 @ARGV = ( 'ecmdfile' ) x 3;
105 like( $@, qr/Too many arguments/, 'cp croaks on error' );
107 # move a file to a subdirectory
108 @ARGV = ( 'ecmdfile', 'ecmddir' );
111 ok( ! -e 'ecmdfile', 'moved file away' );
112 ok( -e File::Spec->join( 'ecmddir', 'ecmdfile' ), 'file in new location' );
114 # mv should also croak with the same wacky warning
115 @ARGV = ( 'ecmdfile' ) x 3;
118 like( $@, qr/Too many arguments/, 'mv croaks on error' );
121 my @files = @ARGV = ( File::Spec->catfile( 'ecmddir', 'ecmdfile' ),
122 File::Spec->catfile( 'ecmddir', 'temp2', 'ecmdfile' ) );
125 ok( ! -e $_, "removed $_ successfully" ) for (@ARGV);
128 @ARGV = my $dir = File::Spec->catfile( 'ecmddir' );
130 ok( ! -e $dir, "removed $dir successfully" );
134 1 while unlink 'ecmdfile';
135 File::Path::rmtree( 'ecmddir' );
141 bless( \(my $text), $_[0] );
145 ${ $_[0] } .= join($/, @_);