4 if( $ENV{PERL_CORE} ) {
6 @INC = ('../lib', 'lib/');
9 unshift @INC, 't/lib/';
15 1 while unlink 'ecmdfile';
16 # forcibly remove ecmddir/temp2, but don't import mkpath
18 File::Path::rmtree( 'ecmddir' );
22 use Test::More tests => 21;
27 # bad neighbor, but test_f() uses exit()
28 *CORE::GLOBAL::exit = ''; # quiet 'only once' warning.
29 *CORE::GLOBAL::exit = sub { return @_ };
31 use_ok( 'ExtUtils::Command' );
33 # get a file in the current directory, replace last char with wildcard
37 opendir(DIR, File::Spec->curdir());
38 while ($file = readdir(DIR)) {
39 $file =~ s/\.\z// if $^O eq 'VMS';
40 last if $file =~ /^\w/;
44 # this should find the file
45 ($ARGV[0] = $file) =~ s/.\z/\?/;
46 ExtUtils::Command::expand_wildcards();
48 is( scalar @ARGV, 1, 'found one file' );
49 like( $ARGV[0], qr/$file/, 'expanded wildcard ? successfully' );
51 # try it with the asterisk now
52 ($ARGV[0] = $file) =~ s/.{3}\z/\*/;
53 ExtUtils::Command::expand_wildcards();
55 ok( (grep { qr/$file/ } @ARGV), 'expanded wildcard * successfully' );
57 # concatenate this file with itself
58 # be extra careful the regex doesn't match itself
60 my $out = tie *STDOUT, 'TieOut';
63 my ($vol, $dirs, $file) = File::Spec->splitpath($self);
64 my @dirs = File::Spec->splitdir($dirs);
65 unshift(@dirs, File::Spec->updir);
66 $dirs = File::Spec->catdir(@dirs);
67 $self = File::Spec->catpath($vol, $dirs, $file);
69 @ARGV = ($self, $self);
72 is( scalar( $$out =~ s/use_ok\( 'ExtUtils::Command'//g), 2,
73 'concatenation worked' );
75 # the truth value here is reversed -- Perl true is C false
76 @ARGV = ( 'ecmdfile' );
77 ok( test_f(), 'testing non-existent file' );
79 @ARGV = ( 'ecmdfile' );
80 cmp_ok( ! test_f(), '==', (-f 'ecmdfile'), 'testing non-existent file' );
82 # these are destructive, have to keep setting @ARGV
83 @ARGV = ( 'ecmdfile' );
86 @ARGV = ( 'ecmdfile' );
87 ok( test_f(), 'now creating that file' );
89 @ARGV = ( 'ecmdfile' );
90 ok( -e $ARGV[0], 'created!' );
93 utime ($now, $now, $ARGV[0]);
96 # Just checking modify time stamp, access time stamp is set
97 # to the beginning of the day in Win95.
98 # There's a small chance of a 1 second flutter here.
99 my $stamp = (stat($ARGV[0]))[9];
100 ok( abs($now - $stamp) <= 1, 'checking modify time stamp' ) ||
101 print "# mtime == $stamp, should be $now\n";
103 # change a file to read-only
104 @ARGV = ( 0600, 'ecmdfile' );
105 ExtUtils::Command::chmod();
107 is( ((stat('ecmdfile'))[2] & 07777) & 0700, 0600, 'change a file to read-only' );
110 @ARGV = ( File::Spec->join( 'ecmddir', 'temp2' ) );
111 ok( ! -e $ARGV[0], 'temp directory not there yet' );
114 ok( -e $ARGV[0], 'temp directory created' );
116 # copy a file to a nested subdirectory
117 unshift @ARGV, 'ecmdfile';
120 ok( -e File::Spec->join( 'ecmddir', 'temp2', 'ecmdfile' ), 'copied okay' );
122 # cp should croak if destination isn't directory (not a great warning)
123 @ARGV = ( 'ecmdfile' ) x 3;
126 like( $@, qr/Too many arguments/, 'cp croaks on error' );
128 # move a file to a subdirectory
129 @ARGV = ( 'ecmdfile', 'ecmddir' );
132 ok( ! -e 'ecmdfile', 'moved file away' );
133 ok( -e File::Spec->join( 'ecmddir', 'ecmdfile' ), 'file in new location' );
135 # mv should also croak with the same wacky warning
136 @ARGV = ( 'ecmdfile' ) x 3;
139 like( $@, qr/Too many arguments/, 'mv croaks on error' );
142 my @files = @ARGV = ( File::Spec->catfile( 'ecmddir', 'ecmdfile' ),
143 File::Spec->catfile( 'ecmddir', 'temp2', 'ecmdfile' ) );
146 ok( ! -e $_, "removed $_ successfully" ) for (@ARGV);
149 @ARGV = my $dir = File::Spec->catfile( 'ecmddir' );
151 ok( ! -e $dir, "removed $dir successfully" );
155 1 while unlink 'ecmdfile';
156 File::Path::rmtree( 'ecmddir' );