4 if( $ENV{PERL_CORE} ) {
6 @INC = ('../lib', 'lib/');
9 unshift @INC, 't/lib/';
15 1 while unlink 'ecmdfile', 'newfile';
16 # forcibly remove ecmddir/temp2, but don't import mkpath
18 File::Path::rmtree( 'ecmddir' );
22 use Test::More tests => 27;
27 # bad neighbor, but test_f() uses exit()
28 *CORE::GLOBAL::exit = ''; # quiet 'only once' warning.
29 *CORE::GLOBAL::exit = sub { return @_ };
30 use_ok( 'ExtUtils::Command' );
34 # get a file in the MM test directory, replace last char with wildcard
38 my $mmtestdir = $ENV{PERL_CORE}
39 ? File::Spec->catdir(File::Spec->updir, 'lib', 'ExtUtils', 't')
41 opendir(DIR, $mmtestdir);
42 while ($file = readdir(DIR)) {
43 $file =~ s/\.\z// if $^O eq 'VMS';
44 last if $file =~ /^\w/;
50 # % means 'match one character' on VMS. Everything else is ?
51 my $match_char = $^O eq 'VMS' ? '%' : '?';
52 ($ARGV[0] = $file) =~ s/.\z/$match_char/;
54 # this should find the file
55 ExtUtils::Command::expand_wildcards();
57 is( scalar @ARGV, 1, 'found one file' );
58 like( $ARGV[0], qr/$file/, 'expanded wildcard ? successfully' );
60 # try it with the asterisk now
61 ($ARGV[0] = $file) =~ s/.{3}\z/\*/;
62 ExtUtils::Command::expand_wildcards();
64 ok( (grep { qr/$file/ } @ARGV), 'expanded wildcard * successfully' );
66 # concatenate this file with itself
67 # be extra careful the regex doesn't match itself
69 my $out = tie *STDOUT, 'TieOut';
72 my ($vol, $dirs, $file) = File::Spec->splitpath($self);
73 my @dirs = File::Spec->splitdir($dirs);
74 unshift(@dirs, File::Spec->updir);
75 $dirs = File::Spec->catdir(@dirs);
76 $self = File::Spec->catpath($vol, $dirs, $file);
78 @ARGV = ($self, $self);
81 is( scalar( $$out =~ s/use_ok\( 'ExtUtils::Command'//g), 2,
82 'concatenation worked' );
84 # the truth value here is reversed -- Perl true is C false
85 @ARGV = ( 'ecmdfile' );
86 ok( test_f(), 'testing non-existent file' );
88 @ARGV = ( 'ecmdfile' );
89 cmp_ok( ! test_f(), '==', (-f 'ecmdfile'), 'testing non-existent file' );
91 # these are destructive, have to keep setting @ARGV
92 @ARGV = ( 'ecmdfile' );
95 @ARGV = ( 'ecmdfile' );
96 ok( test_f(), 'now creating that file' );
98 @ARGV = ( 'ecmdfile' );
99 ok( -e $ARGV[0], 'created!' );
102 utime ($now, $now, $ARGV[0]);
105 # Just checking modify time stamp, access time stamp is set
106 # to the beginning of the day in Win95.
107 # There's a small chance of a 1 second flutter here.
108 my $stamp = (stat($ARGV[0]))[9];
109 cmp_ok( abs($now - $stamp), '<=', 1, 'checking modify time stamp' ) ||
110 diag "mtime == $stamp, should be $now";
115 my $new_stamp = (stat('newfile'))[9];
116 cmp_ok( abs($new_stamp - $stamp), '>=', 2, 'newer file created' );
118 @ARGV = qw(newfile ecmdfile);
121 $stamp = (stat('ecmdfile'))[9];
122 cmp_ok( abs($new_stamp - $stamp), '<=', 1, 'eqtime' );
124 # eqtime use to clear the contents of the file being equalized!
125 open(FILE, '>>ecmdfile') || die $!;
129 @ARGV = qw(newfile ecmdfile);
131 ok( -s 'ecmdfile', "eqtime doesn't clear the file being equalized" );
134 if ($^O eq 'amigaos' || $^O eq 'os2' || $^O eq 'MSWin32' ||
135 $^O eq 'NetWare' || $^O eq 'dos' || $^O eq 'cygwin' ||
138 skip( "different file permission semantics on $^O", 3);
141 # change a file to execute-only
142 @ARGV = ( '0100', 'ecmdfile' );
143 ExtUtils::Command::chmod();
145 is( ((stat('ecmdfile'))[2] & 07777) & 0700,
146 0100, 'change a file to execute-only' );
148 # change a file to read-only
149 @ARGV = ( '0400', 'ecmdfile' );
150 ExtUtils::Command::chmod();
152 is( ((stat('ecmdfile'))[2] & 07777) & 0700,
153 ($^O eq 'vos' ? 0500 : 0400), 'change a file to read-only' );
155 # change a file to write-only
156 @ARGV = ( '0200', 'ecmdfile' );
157 ExtUtils::Command::chmod();
159 is( ((stat('ecmdfile'))[2] & 07777) & 0700,
160 ($^O eq 'vos' ? 0700 : 0200), 'change a file to write-only' );
163 # change a file to read-write
164 @ARGV = ( '0600', 'ecmdfile' );
165 ExtUtils::Command::chmod();
167 is( ((stat('ecmdfile'))[2] & 07777) & 0700,
168 ($^O eq 'vos' ? 0700 : 0600), 'change a file to read-write' );
171 @ARGV = ( File::Spec->join( 'ecmddir', 'temp2' ) );
172 ok( ! -e $ARGV[0], 'temp directory not there yet' );
175 ok( -e $ARGV[0], 'temp directory created' );
177 # copy a file to a nested subdirectory
178 unshift @ARGV, 'ecmdfile';
181 ok( -e File::Spec->join( 'ecmddir', 'temp2', 'ecmdfile' ), 'copied okay' );
183 # cp should croak if destination isn't directory (not a great warning)
184 @ARGV = ( 'ecmdfile' ) x 3;
187 like( $@, qr/Too many arguments/, 'cp croaks on error' );
189 # move a file to a subdirectory
190 @ARGV = ( 'ecmdfile', 'ecmddir' );
193 ok( ! -e 'ecmdfile', 'moved file away' );
194 ok( -e File::Spec->join( 'ecmddir', 'ecmdfile' ), 'file in new location' );
196 # mv should also croak with the same wacky warning
197 @ARGV = ( 'ecmdfile' ) x 3;
200 like( $@, qr/Too many arguments/, 'mv croaks on error' );
203 my @files = @ARGV = ( File::Spec->catfile( 'ecmddir', 'ecmdfile' ),
204 File::Spec->catfile( 'ecmddir', 'temp2', 'ecmdfile' ) );
207 ok( ! -e $_, "removed $_ successfully" ) for (@ARGV);
210 @ARGV = my $dir = File::Spec->catfile( 'ecmddir' );
212 ok( ! -e $dir, "removed $dir successfully" );
216 1 while unlink 'ecmdfile', 'newfile';
217 File::Path::rmtree( 'ecmddir' );