summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchromatic <chromatic@wgz.org>2001-09-10 05:20:56 -0600
committerAbhijit Menon-Sen <ams@wiw.org>2001-09-10 16:31:43 +0000
commite38fdfdb5f3ea685da12415b6241a1b1d3fecf90 (patch)
tree1c4eea971ed3076c8ea1005ddf91f5dc1f5d2a5b
parent14bf678466e32b2037048e39113c054405426688 (diff)
downloadperl-e38fdfdb5f3ea685da12415b6241a1b1d3fecf90.tar.gz
Fix Pod Typo, Add Test for ExtUtils::Command
Message-Id: <20010910172528.54160.qmail@onion.perl.org> p4raw-id: //depot/perl@11981
-rw-r--r--MANIFEST1
-rw-r--r--lib/ExtUtils/Command.pm2
-rw-r--r--lib/ExtUtils/Command.t145
3 files changed, 147 insertions, 1 deletions
diff --git a/MANIFEST b/MANIFEST
index 9322302d22..ab8fda0ecc 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -853,6 +853,7 @@ lib/Exporter.t See if Exporter works
lib/Exporter/Heavy.pm Complicated routines for Exporter
lib/ExtUtils.t See if extutils work
lib/ExtUtils/Command.pm Utilities for Make on non-UNIX platforms
+lib/ExtUtils/Command.pm See if ExtUtils::Command works (Win32 only)
lib/ExtUtils/Constant.pm generate XS code to import C header constants
lib/ExtUtils/Embed.pm Utilities for embedding Perl in C programs
lib/ExtUtils/inst Give information about installed extensions
diff --git a/lib/ExtUtils/Command.pm b/lib/ExtUtils/Command.pm
index 5b5c4103b7..d77580a43c 100644
--- a/lib/ExtUtils/Command.pm
+++ b/lib/ExtUtils/Command.pm
@@ -71,7 +71,7 @@ sub eqtime
utime((stat($src))[8,9],$dst);
}
-=item rm_f files....
+=item rm_rf files....
Removes directories - recursively (even if readonly)
diff --git a/lib/ExtUtils/Command.t b/lib/ExtUtils/Command.t
new file mode 100644
index 0000000000..d1522d3ff5
--- /dev/null
+++ b/lib/ExtUtils/Command.t
@@ -0,0 +1,145 @@
+#!./perl -w
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+ 1 while unlink 'ecmdfile';
+ # forcibly remove ecmddir/temp2, but don't import mkpath
+ use File::Path ();
+ File::Path::rmtree( 'ecmddir' );
+}
+
+use Test::More tests => 22;
+use File::Spec;
+
+SKIP: {
+ skip( 'ExtUtils::Command is a Win32 module', 22 ) unless $^O =~ /Win32/;
+
+ use vars qw( *CORE::GLOBAL::exit );
+
+ # bad neighbor, but test_f() uses exit()
+ *CORE::GLOBAL::exit = sub { return @_ };
+
+ use_ok( 'ExtUtils::Command' );
+
+ # get a file in the current directory, replace last char with wildcard
+ my $file;
+ {
+ local *DIR;
+ opendir(DIR, File::Spec->curdir());
+ while ($file = readdir(DIR)) {
+ last if $file =~ /^\w/;
+ }
+ }
+
+ # this should find the file
+ ($ARGV[0] = $file) =~ s/.\z/\?/;
+ ExtUtils::Command::expand_wildcards();
+
+ is( scalar @ARGV, 1, 'found one file' );
+ like( $ARGV[0], qr/$file/, 'expanded wildcard ? successfully' );
+
+ # try it with the asterisk now
+ ($ARGV[0] = $file) =~ s/.{3}\z/\*/;
+ ExtUtils::Command::expand_wildcards();
+
+ ok( (grep { qr/$file/ } @ARGV), 'expanded wildcard * successfully' );
+
+ # concatenate this file with itself
+ # be extra careful the regex doesn't match itself
+ my $out = tie *STDOUT, 'TieOut';
+ @ARGV = ($0, $0);
+
+ cat();
+ is( scalar( $$out =~ s/use_ok\( 'ExtUtils::Command'//g), 2,
+ 'concatenation worked' );
+
+ # the truth value here is reversed -- Perl true is C false
+ @ARGV = ( 'ecmdfile' );
+ ok( test_f(), 'testing non-existent file' );
+
+ @ARGV = ( 'ecmdfile' );
+ is( ! test_f(), (-f 'ecmdfile'), 'testing non-existent file' );
+
+ # these are destructive, have to keep setting @ARGV
+ @ARGV = ( 'ecmdfile' );
+ touch();
+
+ @ARGV = ( 'ecmdfile' );
+ ok( test_f(), 'now creating that file' );
+
+ @ARGV = ( 'ecmdfile' );
+ ok( -e $ARGV[0], 'created!' );
+
+ # use utime to set the timestamps
+ $ARGV[1] = (my $now = time);
+ utime();
+
+ is( (stat($ARGV[0]))[8], $now, 'checking access time stamp' );
+ is( (stat($ARGV[0]))[9], $now, 'checking modify time stamp' );
+
+ # change a file to read-only
+ @ARGV = ( 0600, 'ecmdfile' );
+ ExtUtils::Command::chmod();
+
+ is( (stat('ecmdfile'))[2] & 07777, 0600, 'removed non-owner permissions' );
+
+ # mkpath
+ @ARGV = ( File::Spec->join( 'ecmddir', 'temp2' ) );
+ ok( ! -e $ARGV[0], 'temp directory not there yet' );
+
+ mkpath();
+ ok( -e $ARGV[0], 'temp directory created' );
+
+ # copy a file to a nested subdirectory
+ unshift @ARGV, 'ecmdfile';
+ cp();
+
+ ok( -e File::Spec->join( 'ecmddir', 'temp2', 'ecmdfile' ), 'copied okay' );
+
+ # cp should croak if destination isn't directory (not a great warning)
+ @ARGV = ( 'ecmdfile' ) x 3;
+ eval { cp() };
+
+ like( $@, qr/Too many arguments/, 'cp croaks on error' );
+
+ # move a file to a subdirectory
+ @ARGV = ( 'ecmdfile', 'ecmddir' );
+ mv();
+
+ ok( ! -e 'ecmdfile', 'moved file away' );
+ ok( -e File::Spec->join( 'ecmddir', 'ecmdfile' ), 'file in new location' );
+
+ # mv should also croak with the same wacky warning
+ @ARGV = ( 'ecmdfile' ) x 3;
+
+ eval { mv() };
+ like( $@, qr/Too many arguments/, 'mv croaks on error' );
+
+ # remove some files
+ my @files = @ARGV = ( File::Spec->catfile( 'ecmddir', 'ecmdfile' ),
+ File::Spec->catfile( 'ecmddir', 'temp2', 'ecmdfile' ) );
+ rm_f();
+
+ ok( ! -e $_, "removed $_ successfully" ) for (@ARGV);
+
+ # rm_f dir
+ @ARGV = my $dir = File::Spec->catfile( 'ecmddir' );
+ rm_rf();
+ ok( ! -e $dir, "removed $dir successfully" );
+}
+
+END {
+ 1 while unlink 'ecmdfile';
+ File::Path::rmtree( 'ecmddir' );
+}
+
+package TieOut;
+
+sub TIEHANDLE {
+ bless( \(my $text), $_[0] );
+}
+
+sub PRINT {
+ ${ $_[0] } .= join($/, @_);
+}