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 current directory, replace last char with wildcard
38 opendir(DIR, File::Spec->curdir());
39 while ($file = readdir(DIR)) {
40 $file =~ s/\.\z// if $^O eq 'VMS';
41 last if $file =~ /^\w/;
47 # % means 'match one character' on VMS. Everything else is ?
48 my $match_char = $^O eq 'VMS' ? '%' : '?';
49 ($ARGV[0] = $file) =~ s/.\z/$match_char/;
51 # this should find the file
52 ExtUtils::Command::expand_wildcards();
54 is( scalar @ARGV, 1, 'found one file' );
55 like( $ARGV[0], qr/$file/, 'expanded wildcard ? successfully' );
57 # try it with the asterisk now
58 ($ARGV[0] = $file) =~ s/.{3}\z/\*/;
59 ExtUtils::Command::expand_wildcards();
61 ok( (grep { qr/$file/ } @ARGV), 'expanded wildcard * successfully' );
63 # concatenate this file with itself
64 # be extra careful the regex doesn't match itself
66 my $out = tie *STDOUT, 'TieOut';
69 my ($vol, $dirs, $file) = File::Spec->splitpath($self);
70 my @dirs = File::Spec->splitdir($dirs);
71 unshift(@dirs, File::Spec->updir);
72 $dirs = File::Spec->catdir(@dirs);
73 $self = File::Spec->catpath($vol, $dirs, $file);
75 @ARGV = ($self, $self);
78 is( scalar( $$out =~ s/use_ok\( 'ExtUtils::Command'//g), 2,
79 'concatenation worked' );
81 # the truth value here is reversed -- Perl true is C false
82 @ARGV = ( 'ecmdfile' );
83 ok( test_f(), 'testing non-existent file' );
85 @ARGV = ( 'ecmdfile' );
86 cmp_ok( ! test_f(), '==', (-f 'ecmdfile'), 'testing non-existent file' );
88 # these are destructive, have to keep setting @ARGV
89 @ARGV = ( 'ecmdfile' );
92 @ARGV = ( 'ecmdfile' );
93 ok( test_f(), 'now creating that file' );
95 @ARGV = ( 'ecmdfile' );
96 ok( -e $ARGV[0], 'created!' );
99 utime ($now, $now, $ARGV[0]);
102 # Just checking modify time stamp, access time stamp is set
103 # to the beginning of the day in Win95.
104 # There's a small chance of a 1 second flutter here.
105 my $stamp = (stat($ARGV[0]))[9];
106 cmp_ok( abs($now - $stamp), '<=', 1, 'checking modify time stamp' ) ||
107 diag "mtime == $stamp, should be $now";
112 my $new_stamp = (stat('newfile'))[9];
113 cmp_ok( abs($new_stamp - $stamp), '>=', 2, 'newer file created' );
115 @ARGV = qw(newfile ecmdfile);
118 $stamp = (stat('ecmdfile'))[9];
119 cmp_ok( abs($new_stamp - $stamp), '<=', 1, 'eqtime' );
121 # eqtime use to clear the contents of the file being equalized!
122 open(FILE, '>>ecmdfile') || die $!;
126 @ARGV = qw(newfile ecmdfile);
128 ok( -s 'ecmdfile', "eqtime doesn't clear the file being equalized" );
131 if ($^O eq 'amigaos' || $^O eq 'os2' || $^O eq 'MSWin32' ||
132 $^O eq 'NetWare' || $^O eq 'dos' || $^O eq 'cygwin' ||
135 skip( "different file permission semantics on $^O", 3);
138 # change a file to execute-only
139 @ARGV = ( '0100', 'ecmdfile' );
140 ExtUtils::Command::chmod();
142 is( ((stat('ecmdfile'))[2] & 07777) & 0700,
143 0100, 'change a file to execute-only' );
145 # change a file to read-only
146 @ARGV = ( '0400', 'ecmdfile' );
147 ExtUtils::Command::chmod();
149 is( ((stat('ecmdfile'))[2] & 07777) & 0700,
150 ($^O eq 'vos' ? 0500 : 0400), 'change a file to read-only' );
152 # change a file to write-only
153 @ARGV = ( '0200', 'ecmdfile' );
154 ExtUtils::Command::chmod();
156 is( ((stat('ecmdfile'))[2] & 07777) & 0700,
157 ($^O eq 'vos' ? 0700 : 0200), 'change a file to write-only' );
160 # change a file to read-write
161 @ARGV = ( '0600', 'ecmdfile' );
162 ExtUtils::Command::chmod();
164 is( ((stat('ecmdfile'))[2] & 07777) & 0700,
165 ($^O eq 'vos' ? 0700 : 0600), 'change a file to read-write' );
168 @ARGV = ( File::Spec->join( 'ecmddir', 'temp2' ) );
169 ok( ! -e $ARGV[0], 'temp directory not there yet' );
172 ok( -e $ARGV[0], 'temp directory created' );
174 # copy a file to a nested subdirectory
175 unshift @ARGV, 'ecmdfile';
178 ok( -e File::Spec->join( 'ecmddir', 'temp2', 'ecmdfile' ), 'copied okay' );
180 # cp should croak if destination isn't directory (not a great warning)
181 @ARGV = ( 'ecmdfile' ) x 3;
184 like( $@, qr/Too many arguments/, 'cp croaks on error' );
186 # move a file to a subdirectory
187 @ARGV = ( 'ecmdfile', 'ecmddir' );
190 ok( ! -e 'ecmdfile', 'moved file away' );
191 ok( -e File::Spec->join( 'ecmddir', 'ecmdfile' ), 'file in new location' );
193 # mv should also croak with the same wacky warning
194 @ARGV = ( 'ecmdfile' ) x 3;
197 like( $@, qr/Too many arguments/, 'mv croaks on error' );
200 my @files = @ARGV = ( File::Spec->catfile( 'ecmddir', 'ecmdfile' ),
201 File::Spec->catfile( 'ecmddir', 'temp2', 'ecmdfile' ) );
204 ok( ! -e $_, "removed $_ successfully" ) for (@ARGV);
207 @ARGV = my $dir = File::Spec->catfile( 'ecmddir' );
209 ok( ! -e $dir, "removed $dir successfully" );
213 1 while unlink 'ecmdfile', 'newfile';
214 File::Path::rmtree( 'ecmddir' );