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 => 22;
16 skip( 'ExtUtils::Command is a Win32 module', 22 ) unless $^O =~ /Win32/;
18 use vars qw( *CORE::GLOBAL::exit );
20 # bad neighbor, but test_f() uses exit()
21 *CORE::GLOBAL::exit = sub { return @_ };
23 use_ok( 'ExtUtils::Command' );
25 # get a file in the current directory, replace last char with wildcard
29 opendir(DIR, File::Spec->curdir());
30 while ($file = readdir(DIR)) {
31 last if $file =~ /^\w/;
35 # this should find the file
36 ($ARGV[0] = $file) =~ s/.\z/\?/;
37 ExtUtils::Command::expand_wildcards();
39 is( scalar @ARGV, 1, 'found one file' );
40 like( $ARGV[0], qr/$file/, 'expanded wildcard ? successfully' );
42 # try it with the asterisk now
43 ($ARGV[0] = $file) =~ s/.{3}\z/\*/;
44 ExtUtils::Command::expand_wildcards();
46 ok( (grep { qr/$file/ } @ARGV), 'expanded wildcard * successfully' );
48 # concatenate this file with itself
49 # be extra careful the regex doesn't match itself
50 my $out = tie *STDOUT, 'TieOut';
54 is( scalar( $$out =~ s/use_ok\( 'ExtUtils::Command'//g), 2,
55 'concatenation worked' );
57 # the truth value here is reversed -- Perl true is C false
58 @ARGV = ( 'ecmdfile' );
59 ok( test_f(), 'testing non-existent file' );
61 @ARGV = ( 'ecmdfile' );
62 is( ! test_f(), (-f 'ecmdfile'), 'testing non-existent file' );
64 # these are destructive, have to keep setting @ARGV
65 @ARGV = ( 'ecmdfile' );
68 @ARGV = ( 'ecmdfile' );
69 ok( test_f(), 'now creating that file' );
71 @ARGV = ( 'ecmdfile' );
72 ok( -e $ARGV[0], 'created!' );
74 # use utime to set the timestamps
75 $ARGV[1] = (my $now = time);
78 is( (stat($ARGV[0]))[8], $now, 'checking access time stamp' );
79 is( (stat($ARGV[0]))[9], $now, 'checking modify time stamp' );
81 # change a file to read-only
82 @ARGV = ( 0600, 'ecmdfile' );
83 ExtUtils::Command::chmod();
85 is( (stat('ecmdfile'))[2] & 07777, 0600, 'removed non-owner permissions' );
88 @ARGV = ( File::Spec->join( 'ecmddir', 'temp2' ) );
89 ok( ! -e $ARGV[0], 'temp directory not there yet' );
92 ok( -e $ARGV[0], 'temp directory created' );
94 # copy a file to a nested subdirectory
95 unshift @ARGV, 'ecmdfile';
98 ok( -e File::Spec->join( 'ecmddir', 'temp2', 'ecmdfile' ), 'copied okay' );
100 # cp should croak if destination isn't directory (not a great warning)
101 @ARGV = ( 'ecmdfile' ) x 3;
104 like( $@, qr/Too many arguments/, 'cp croaks on error' );
106 # move a file to a subdirectory
107 @ARGV = ( 'ecmdfile', 'ecmddir' );
110 ok( ! -e 'ecmdfile', 'moved file away' );
111 ok( -e File::Spec->join( 'ecmddir', 'ecmdfile' ), 'file in new location' );
113 # mv should also croak with the same wacky warning
114 @ARGV = ( 'ecmdfile' ) x 3;
117 like( $@, qr/Too many arguments/, 'mv croaks on error' );
120 my @files = @ARGV = ( File::Spec->catfile( 'ecmddir', 'ecmdfile' ),
121 File::Spec->catfile( 'ecmddir', 'temp2', 'ecmdfile' ) );
124 ok( ! -e $_, "removed $_ successfully" ) for (@ARGV);
127 @ARGV = my $dir = File::Spec->catfile( 'ecmddir' );
129 ok( ! -e $dir, "removed $dir successfully" );
133 1 while unlink 'ecmdfile';
134 File::Path::rmtree( 'ecmddir' );
140 bless( \(my $text), $_[0] );
144 ${ $_[0] } .= join($/, @_);