Change use|require 5.005_64 to use|require 5.6.1.
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / Command.t
CommitLineData
e38fdfdb 1#!./perl -w
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 1 while unlink 'ecmdfile';
7 # forcibly remove ecmddir/temp2, but don't import mkpath
8 use File::Path ();
9 File::Path::rmtree( 'ecmddir' );
10}
11
12use Test::More tests => 22;
13use File::Spec;
14
15SKIP: {
16 skip( 'ExtUtils::Command is a Win32 module', 22 ) unless $^O =~ /Win32/;
17
18 use vars qw( *CORE::GLOBAL::exit );
19
20 # bad neighbor, but test_f() uses exit()
21 *CORE::GLOBAL::exit = sub { return @_ };
22
23 use_ok( 'ExtUtils::Command' );
24
25 # get a file in the current directory, replace last char with wildcard
26 my $file;
27 {
28 local *DIR;
29 opendir(DIR, File::Spec->curdir());
30 while ($file = readdir(DIR)) {
31 last if $file =~ /^\w/;
32 }
33 }
34
35 # this should find the file
36 ($ARGV[0] = $file) =~ s/.\z/\?/;
37 ExtUtils::Command::expand_wildcards();
38
39 is( scalar @ARGV, 1, 'found one file' );
40 like( $ARGV[0], qr/$file/, 'expanded wildcard ? successfully' );
41
42 # try it with the asterisk now
43 ($ARGV[0] = $file) =~ s/.{3}\z/\*/;
44 ExtUtils::Command::expand_wildcards();
45
46 ok( (grep { qr/$file/ } @ARGV), 'expanded wildcard * successfully' );
47
48 # concatenate this file with itself
49 # be extra careful the regex doesn't match itself
50 my $out = tie *STDOUT, 'TieOut';
51 @ARGV = ($0, $0);
52
53 cat();
54 is( scalar( $$out =~ s/use_ok\( 'ExtUtils::Command'//g), 2,
55 'concatenation worked' );
56
57 # the truth value here is reversed -- Perl true is C false
58 @ARGV = ( 'ecmdfile' );
59 ok( test_f(), 'testing non-existent file' );
60
61 @ARGV = ( 'ecmdfile' );
62 is( ! test_f(), (-f 'ecmdfile'), 'testing non-existent file' );
63
64 # these are destructive, have to keep setting @ARGV
65 @ARGV = ( 'ecmdfile' );
66 touch();
67
68 @ARGV = ( 'ecmdfile' );
69 ok( test_f(), 'now creating that file' );
70
71 @ARGV = ( 'ecmdfile' );
72 ok( -e $ARGV[0], 'created!' );
73
74 # use utime to set the timestamps
75 $ARGV[1] = (my $now = time);
76 utime();
77
78 is( (stat($ARGV[0]))[8], $now, 'checking access time stamp' );
79 is( (stat($ARGV[0]))[9], $now, 'checking modify time stamp' );
80
81 # change a file to read-only
82 @ARGV = ( 0600, 'ecmdfile' );
83 ExtUtils::Command::chmod();
84
85 is( (stat('ecmdfile'))[2] & 07777, 0600, 'removed non-owner permissions' );
86
87 # mkpath
88 @ARGV = ( File::Spec->join( 'ecmddir', 'temp2' ) );
89 ok( ! -e $ARGV[0], 'temp directory not there yet' );
90
91 mkpath();
92 ok( -e $ARGV[0], 'temp directory created' );
93
94 # copy a file to a nested subdirectory
95 unshift @ARGV, 'ecmdfile';
96 cp();
97
98 ok( -e File::Spec->join( 'ecmddir', 'temp2', 'ecmdfile' ), 'copied okay' );
99
100 # cp should croak if destination isn't directory (not a great warning)
101 @ARGV = ( 'ecmdfile' ) x 3;
102 eval { cp() };
103
104 like( $@, qr/Too many arguments/, 'cp croaks on error' );
105
106 # move a file to a subdirectory
107 @ARGV = ( 'ecmdfile', 'ecmddir' );
108 mv();
109
110 ok( ! -e 'ecmdfile', 'moved file away' );
111 ok( -e File::Spec->join( 'ecmddir', 'ecmdfile' ), 'file in new location' );
112
113 # mv should also croak with the same wacky warning
114 @ARGV = ( 'ecmdfile' ) x 3;
115
116 eval { mv() };
117 like( $@, qr/Too many arguments/, 'mv croaks on error' );
118
119 # remove some files
120 my @files = @ARGV = ( File::Spec->catfile( 'ecmddir', 'ecmdfile' ),
121 File::Spec->catfile( 'ecmddir', 'temp2', 'ecmdfile' ) );
122 rm_f();
123
124 ok( ! -e $_, "removed $_ successfully" ) for (@ARGV);
125
126 # rm_f dir
127 @ARGV = my $dir = File::Spec->catfile( 'ecmddir' );
128 rm_rf();
129 ok( ! -e $dir, "removed $dir successfully" );
130}
131
132END {
133 1 while unlink 'ecmdfile';
134 File::Path::rmtree( 'ecmddir' );
135}
136
137package TieOut;
138
139sub TIEHANDLE {
140 bless( \(my $text), $_[0] );
141}
142
143sub PRINT {
144 ${ $_[0] } .= join($/, @_);
145}