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/;
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";
104 if ($^O eq 'amigaos' || $^O eq 'os2' || $^O eq 'MSWin32' ||
105 $^O eq 'NetWare' || $^O eq 'dos' || $^O eq 'cygwin') {
106 skip( "different file permission semantics on $^O", 3);
109 # change a file to execute-only
110 @ARGV = ( 0100, 'ecmdfile' );
111 ExtUtils::Command::chmod();
113 is( ((stat('ecmdfile'))[2] & 07777) & 0700,
114 0100, 'change a file to execute-only' );
116 # change a file to read-only
117 @ARGV = ( 0400, 'ecmdfile' );
118 ExtUtils::Command::chmod();
120 is( ((stat('ecmdfile'))[2] & 07777) & 0700,
121 ($^O eq 'vos' ? 0500 : 0400), 'change a file to read-only' );
123 # change a file to write-only
124 @ARGV = ( 0200, 'ecmdfile' );
125 ExtUtils::Command::chmod();
127 is( ((stat('ecmdfile'))[2] & 07777) & 0700,
128 ($^O eq 'vos' ? 0700 : 0200), 'change a file to write-only' );
131 # change a file to read-write
132 @ARGV = ( 0600, 'ecmdfile' );
133 ExtUtils::Command::chmod();
135 is( ((stat('ecmdfile'))[2] & 07777) & 0700,
136 ($^O eq 'vos' ? 0700 : 0600), 'change a file to read-write' );
139 @ARGV = ( File::Spec->join( 'ecmddir', 'temp2' ) );
140 ok( ! -e $ARGV[0], 'temp directory not there yet' );
143 ok( -e $ARGV[0], 'temp directory created' );
145 # copy a file to a nested subdirectory
146 unshift @ARGV, 'ecmdfile';
149 ok( -e File::Spec->join( 'ecmddir', 'temp2', 'ecmdfile' ), 'copied okay' );
151 # cp should croak if destination isn't directory (not a great warning)
152 @ARGV = ( 'ecmdfile' ) x 3;
155 like( $@, qr/Too many arguments/, 'cp croaks on error' );
157 # move a file to a subdirectory
158 @ARGV = ( 'ecmdfile', 'ecmddir' );
161 ok( ! -e 'ecmdfile', 'moved file away' );
162 ok( -e File::Spec->join( 'ecmddir', 'ecmdfile' ), 'file in new location' );
164 # mv should also croak with the same wacky warning
165 @ARGV = ( 'ecmdfile' ) x 3;
168 like( $@, qr/Too many arguments/, 'mv croaks on error' );
171 my @files = @ARGV = ( File::Spec->catfile( 'ecmddir', 'ecmdfile' ),
172 File::Spec->catfile( 'ecmddir', 'temp2', 'ecmdfile' ) );
175 ok( ! -e $_, "removed $_ successfully" ) for (@ARGV);
178 @ARGV = my $dir = File::Spec->catfile( 'ecmddir' );
180 ok( ! -e $dir, "removed $dir successfully" );
184 1 while unlink 'ecmdfile';
185 File::Path::rmtree( 'ecmddir' );