4 if( $ENV{PERL_CORE} ) {
6 @INC = ('../lib', 'lib/');
9 unshift @INC, 't/lib/';
15 $Testfile = 'testfile.foo';
19 1 while unlink $Testfile, 'newfile';
20 # forcibly remove ecmddir/temp2, but don't import mkpath
22 File::Path::rmtree( 'ecmddir' );
26 use Test::More tests => 26;
31 # bad neighbor, but test_f() uses exit()
32 *CORE::GLOBAL::exit = ''; # quiet 'only once' warning.
33 *CORE::GLOBAL::exit = sub { return @_ };
34 use_ok( 'ExtUtils::Command' );
38 # concatenate this file with itself
39 # be extra careful the regex doesn't match itself
41 my $out = tie *STDOUT, 'TieOut';
44 my ($vol, $dirs, $file) = File::Spec->splitpath($self);
45 my @dirs = File::Spec->splitdir($dirs);
46 unshift(@dirs, File::Spec->updir);
47 $dirs = File::Spec->catdir(@dirs);
48 $self = File::Spec->catpath($vol, $dirs, $file);
50 @ARGV = ($self, $self);
53 is( scalar( $$out =~ s/use_ok\( 'ExtUtils::Command'//g), 2,
54 'concatenation worked' );
56 # the truth value here is reversed -- Perl true is C false
57 @ARGV = ( $Testfile );
58 ok( test_f(), 'testing non-existent file' );
60 @ARGV = ( $Testfile );
61 cmp_ok( ! test_f(), '==', (-f $Testfile), 'testing non-existent file' );
63 # these are destructive, have to keep setting @ARGV
64 @ARGV = ( $Testfile );
67 @ARGV = ( $Testfile );
68 ok( test_f(), 'now creating that file' );
70 @ARGV = ( $Testfile );
71 ok( -e $ARGV[0], 'created!' );
74 utime ($now, $now, $ARGV[0]);
77 # Just checking modify time stamp, access time stamp is set
78 # to the beginning of the day in Win95.
79 # There's a small chance of a 1 second flutter here.
80 my $stamp = (stat($ARGV[0]))[9];
81 cmp_ok( abs($now - $stamp), '<=', 1, 'checking modify time stamp' ) ||
82 diag "mtime == $stamp, should be $now";
87 my $new_stamp = (stat('newfile'))[9];
88 cmp_ok( abs($new_stamp - $stamp), '>=', 2, 'newer file created' );
90 @ARGV = ('newfile', $Testfile);
93 $stamp = (stat($Testfile))[9];
94 cmp_ok( abs($new_stamp - $stamp), '<=', 1, 'eqtime' );
96 # eqtime use to clear the contents of the file being equalized!
97 open(FILE, ">>$Testfile") || die $!;
101 @ARGV = ('newfile', $Testfile);
103 ok( -s $Testfile, "eqtime doesn't clear the file being equalized" );
106 if ($^O eq 'amigaos' || $^O eq 'os2' || $^O eq 'MSWin32' ||
107 $^O eq 'NetWare' || $^O eq 'dos' || $^O eq 'cygwin' ||
110 skip( "different file permission semantics on $^O", 3);
113 # change a file to execute-only
114 @ARGV = ( '0100', $Testfile );
115 ExtUtils::Command::chmod();
117 is( ((stat($Testfile))[2] & 07777) & 0700,
118 0100, 'change a file to execute-only' );
120 # change a file to read-only
121 @ARGV = ( '0400', $Testfile );
122 ExtUtils::Command::chmod();
124 is( ((stat($Testfile))[2] & 07777) & 0700,
125 ($^O eq 'vos' ? 0500 : 0400), 'change a file to read-only' );
127 # change a file to write-only
128 @ARGV = ( '0200', $Testfile );
129 ExtUtils::Command::chmod();
131 is( ((stat($Testfile))[2] & 07777) & 0700,
132 ($^O eq 'vos' ? 0700 : 0200), 'change a file to write-only' );
135 # change a file to read-write
136 @ARGV = ( '0600', $Testfile );
137 ExtUtils::Command::chmod();
139 is( ((stat($Testfile))[2] & 07777) & 0700,
140 ($^O eq 'vos' ? 0700 : 0600), 'change a file to read-write' );
143 @ARGV = ( File::Spec->join( 'ecmddir', 'temp2' ) );
144 ok( ! -e $ARGV[0], 'temp directory not there yet' );
147 ok( -e $ARGV[0], 'temp directory created' );
149 # copy a file to a nested subdirectory
150 unshift @ARGV, $Testfile;
153 ok( -e File::Spec->join( 'ecmddir', 'temp2', $Testfile ), 'copied okay' );
155 # cp should croak if destination isn't directory (not a great warning)
156 @ARGV = ( $Testfile ) x 3;
159 like( $@, qr/Too many arguments/, 'cp croaks on error' );
161 # move a file to a subdirectory
162 @ARGV = ( $Testfile, 'ecmddir' );
165 ok( ! -e $Testfile, 'moved file away' );
166 ok( -e File::Spec->join( 'ecmddir', $Testfile ), 'file in new location' );
168 # mv should also croak with the same wacky warning
169 @ARGV = ( $Testfile ) x 3;
172 like( $@, qr/Too many arguments/, 'mv croaks on error' );
174 # Test expand_wildcards()
176 my $file = $Testfile;
180 # % means 'match one character' on VMS. Everything else is ?
181 my $match_char = $^O eq 'VMS' ? '%' : '?';
182 ($ARGV[0] = $file) =~ s/.\z/$match_char/;
184 # this should find the file
185 ExtUtils::Command::expand_wildcards();
187 is_deeply( \@ARGV, [$file], 'expanded wildcard ? successfully' );
189 # try it with the asterisk now
190 ($ARGV[0] = $file) =~ s/.{3}\z/\*/;
191 ExtUtils::Command::expand_wildcards();
193 is_deeply( \@ARGV, [$file], 'expanded wildcard * successfully' );
195 chdir File::Spec->updir;
199 my @files = @ARGV = ( File::Spec->catfile( 'ecmddir', $Testfile ),
200 File::Spec->catfile( 'ecmddir', 'temp2', $Testfile ) );
203 ok( ! -e $_, "removed $_ successfully" ) for (@ARGV);
206 @ARGV = my $dir = File::Spec->catfile( 'ecmddir' );
208 ok( ! -e $dir, "removed $dir successfully" );
212 1 while unlink $Testfile, 'newfile';
213 File::Path::rmtree( 'ecmddir' );