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 => 24;
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/;
45 # % means 'match one character' on VMS. Everything else is ?
46 my $match_char = $^O eq 'VMS' ? '%' : '?';
47 ($ARGV[0] = $file) =~ s/.\z/$match_char/;
49 # this should find the file
50 ExtUtils::Command::expand_wildcards();
52 is( scalar @ARGV, 1, 'found one file' );
53 like( $ARGV[0], qr/$file/, 'expanded wildcard ? successfully' );
55 # try it with the asterisk now
56 ($ARGV[0] = $file) =~ s/.{3}\z/\*/;
57 ExtUtils::Command::expand_wildcards();
59 ok( (grep { qr/$file/ } @ARGV), 'expanded wildcard * successfully' );
61 # concatenate this file with itself
62 # be extra careful the regex doesn't match itself
64 my $out = tie *STDOUT, 'TieOut';
67 my ($vol, $dirs, $file) = File::Spec->splitpath($self);
68 my @dirs = File::Spec->splitdir($dirs);
69 unshift(@dirs, File::Spec->updir);
70 $dirs = File::Spec->catdir(@dirs);
71 $self = File::Spec->catpath($vol, $dirs, $file);
73 @ARGV = ($self, $self);
76 is( scalar( $$out =~ s/use_ok\( 'ExtUtils::Command'//g), 2,
77 'concatenation worked' );
79 # the truth value here is reversed -- Perl true is C false
80 @ARGV = ( 'ecmdfile' );
81 ok( test_f(), 'testing non-existent file' );
83 @ARGV = ( 'ecmdfile' );
84 cmp_ok( ! test_f(), '==', (-f 'ecmdfile'), 'testing non-existent file' );
86 # these are destructive, have to keep setting @ARGV
87 @ARGV = ( 'ecmdfile' );
90 @ARGV = ( 'ecmdfile' );
91 ok( test_f(), 'now creating that file' );
93 @ARGV = ( 'ecmdfile' );
94 ok( -e $ARGV[0], 'created!' );
97 utime ($now, $now, $ARGV[0]);
100 # Just checking modify time stamp, access time stamp is set
101 # to the beginning of the day in Win95.
102 # There's a small chance of a 1 second flutter here.
103 my $stamp = (stat($ARGV[0]))[9];
104 cmp_ok( abs($now - $stamp), '<=', 1, 'checking modify time stamp' ) ||
105 diag "mtime == $stamp, should be $now";
108 if ($^O eq 'amigaos' || $^O eq 'os2' || $^O eq 'MSWin32' ||
109 $^O eq 'NetWare' || $^O eq 'dos' || $^O eq 'cygwin' ||
111 skip( "different file permission semantics on $^O", 3);
114 # change a file to execute-only
115 @ARGV = ( 0100, 'ecmdfile' );
116 ExtUtils::Command::chmod();
118 is( ((stat('ecmdfile'))[2] & 07777) & 0700,
119 0100, 'change a file to execute-only' );
121 # change a file to read-only
122 @ARGV = ( 0400, 'ecmdfile' );
123 ExtUtils::Command::chmod();
125 is( ((stat('ecmdfile'))[2] & 07777) & 0700,
126 ($^O eq 'vos' ? 0500 : 0400), 'change a file to read-only' );
128 # change a file to write-only
129 @ARGV = ( 0200, 'ecmdfile' );
130 ExtUtils::Command::chmod();
132 is( ((stat('ecmdfile'))[2] & 07777) & 0700,
133 ($^O eq 'vos' ? 0700 : 0200), 'change a file to write-only' );
136 # change a file to read-write
137 @ARGV = ( 0600, 'ecmdfile' );
138 ExtUtils::Command::chmod();
140 is( ((stat('ecmdfile'))[2] & 07777) & 0700,
141 ($^O eq 'vos' ? 0700 : 0600), 'change a file to read-write' );
144 @ARGV = ( File::Spec->join( 'ecmddir', 'temp2' ) );
145 ok( ! -e $ARGV[0], 'temp directory not there yet' );
148 ok( -e $ARGV[0], 'temp directory created' );
150 # copy a file to a nested subdirectory
151 unshift @ARGV, 'ecmdfile';
154 ok( -e File::Spec->join( 'ecmddir', 'temp2', 'ecmdfile' ), 'copied okay' );
156 # cp should croak if destination isn't directory (not a great warning)
157 @ARGV = ( 'ecmdfile' ) x 3;
160 like( $@, qr/Too many arguments/, 'cp croaks on error' );
162 # move a file to a subdirectory
163 @ARGV = ( 'ecmdfile', 'ecmddir' );
166 ok( ! -e 'ecmdfile', 'moved file away' );
167 ok( -e File::Spec->join( 'ecmddir', 'ecmdfile' ), 'file in new location' );
169 # mv should also croak with the same wacky warning
170 @ARGV = ( 'ecmdfile' ) x 3;
173 like( $@, qr/Too many arguments/, 'mv croaks on error' );
176 my @files = @ARGV = ( File::Spec->catfile( 'ecmddir', 'ecmdfile' ),
177 File::Spec->catfile( 'ecmddir', 'temp2', 'ecmdfile' ) );
180 ok( ! -e $_, "removed $_ successfully" ) for (@ARGV);
183 @ARGV = my $dir = File::Spec->catfile( 'ecmddir' );
185 ok( ! -e $dir, "removed $dir successfully" );
189 1 while unlink 'ecmdfile';
190 File::Path::rmtree( 'ecmddir' );