| 1 | #!/usr/bin/perl -w
|
|---|
| 2 |
|
|---|
| 3 | BEGIN {
|
|---|
| 4 | if( $ENV{PERL_CORE} ) {
|
|---|
| 5 | chdir 't';
|
|---|
| 6 | @INC = ('../lib', 'lib/');
|
|---|
| 7 | }
|
|---|
| 8 | else {
|
|---|
| 9 | unshift @INC, 't/lib/';
|
|---|
| 10 | }
|
|---|
| 11 | }
|
|---|
| 12 | chdir 't';
|
|---|
| 13 |
|
|---|
| 14 | BEGIN {
|
|---|
| 15 | $Testfile = 'testfile.foo';
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | BEGIN {
|
|---|
| 19 | 1 while unlink $Testfile, 'newfile';
|
|---|
| 20 | # forcibly remove ecmddir/temp2, but don't import mkpath
|
|---|
| 21 | use File::Path ();
|
|---|
| 22 | File::Path::rmtree( 'ecmddir' );
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | BEGIN {
|
|---|
| 26 | use Test::More tests => 38;
|
|---|
| 27 | use File::Spec;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | BEGIN {
|
|---|
| 31 | # bad neighbor, but test_f() uses exit()
|
|---|
| 32 | *CORE::GLOBAL::exit = ''; # quiet 'only once' warning.
|
|---|
| 33 | *CORE::GLOBAL::exit = sub { return @_ };
|
|---|
| 34 | use_ok( 'ExtUtils::Command' );
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | {
|
|---|
| 38 | # concatenate this file with itself
|
|---|
| 39 | # be extra careful the regex doesn't match itself
|
|---|
| 40 | use TieOut;
|
|---|
| 41 | my $out = tie *STDOUT, 'TieOut';
|
|---|
| 42 | my $self = $0;
|
|---|
| 43 | unless (-f $self) {
|
|---|
| 44 | my ($vol, $dirs, $file) = File::Spec->splitpath($self);
|
|---|
| 45 | my @dirs = File::Spec->splitdir($dirs);
|
|---|
| 46 | unshift(@dirs, File::Spec->updir);
|
|---|
| 47 | $dirs = File::Spec->catdir(@dirs);
|
|---|
| 48 | $self = File::Spec->catpath($vol, $dirs, $file);
|
|---|
| 49 | }
|
|---|
| 50 | @ARGV = ($self, $self);
|
|---|
| 51 |
|
|---|
| 52 | cat();
|
|---|
| 53 | is( scalar( $$out =~ s/use_ok\( 'ExtUtils::Command'//g), 2,
|
|---|
| 54 | 'concatenation worked' );
|
|---|
| 55 |
|
|---|
| 56 | # the truth value here is reversed -- Perl true is C false
|
|---|
| 57 | @ARGV = ( $Testfile );
|
|---|
| 58 | ok( test_f(), 'testing non-existent file' );
|
|---|
| 59 |
|
|---|
| 60 | @ARGV = ( $Testfile );
|
|---|
| 61 | cmp_ok( ! test_f(), '==', defined (-f $Testfile), 'testing non-existent file' );
|
|---|
| 62 |
|
|---|
| 63 | # these are destructive, have to keep setting @ARGV
|
|---|
| 64 | @ARGV = ( $Testfile );
|
|---|
| 65 | touch();
|
|---|
| 66 |
|
|---|
| 67 | @ARGV = ( $Testfile );
|
|---|
| 68 | ok( test_f(), 'now creating that file' );
|
|---|
| 69 | is_deeply( \@ARGV, [$Testfile], 'test_f preserves @ARGV' );
|
|---|
| 70 |
|
|---|
| 71 | @ARGV = ( $Testfile );
|
|---|
| 72 | ok( -e $ARGV[0], 'created!' );
|
|---|
| 73 |
|
|---|
| 74 | my ($now) = time;
|
|---|
| 75 | utime ($now, $now, $ARGV[0]);
|
|---|
| 76 | sleep 2;
|
|---|
| 77 |
|
|---|
| 78 | # Just checking modify time stamp, access time stamp is set
|
|---|
| 79 | # to the beginning of the day in Win95.
|
|---|
| 80 | # There's a small chance of a 1 second flutter here.
|
|---|
| 81 | my $stamp = (stat($ARGV[0]))[9];
|
|---|
| 82 | cmp_ok( abs($now - $stamp), '<=', 1, 'checking modify time stamp' ) ||
|
|---|
| 83 | diag "mtime == $stamp, should be $now";
|
|---|
| 84 |
|
|---|
| 85 | @ARGV = qw(newfile);
|
|---|
| 86 | touch();
|
|---|
| 87 |
|
|---|
| 88 | my $new_stamp = (stat('newfile'))[9];
|
|---|
| 89 | cmp_ok( abs($new_stamp - $stamp), '>=', 2, 'newer file created' );
|
|---|
| 90 |
|
|---|
| 91 | @ARGV = ('newfile', $Testfile);
|
|---|
| 92 | eqtime();
|
|---|
| 93 |
|
|---|
| 94 | $stamp = (stat($Testfile))[9];
|
|---|
| 95 | cmp_ok( abs($new_stamp - $stamp), '<=', 1, 'eqtime' );
|
|---|
| 96 |
|
|---|
| 97 | # eqtime use to clear the contents of the file being equalized!
|
|---|
| 98 | open(FILE, ">>$Testfile") || die $!;
|
|---|
| 99 | print FILE "Foo";
|
|---|
| 100 | close FILE;
|
|---|
| 101 |
|
|---|
| 102 | @ARGV = ('newfile', $Testfile);
|
|---|
| 103 | eqtime();
|
|---|
| 104 | ok( -s $Testfile, "eqtime doesn't clear the file being equalized" );
|
|---|
| 105 |
|
|---|
| 106 | SKIP: {
|
|---|
| 107 | if ($^O eq 'amigaos' || $^O eq 'os2' || $^O eq 'MSWin32' ||
|
|---|
| 108 | $^O eq 'NetWare' || $^O eq 'dos' || $^O eq 'cygwin' ||
|
|---|
| 109 | $^O eq 'MacOS'
|
|---|
| 110 | ) {
|
|---|
| 111 | skip( "different file permission semantics on $^O", 3);
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | # change a file to execute-only
|
|---|
| 115 | @ARGV = ( '0100', $Testfile );
|
|---|
| 116 | ExtUtils::Command::chmod();
|
|---|
| 117 |
|
|---|
| 118 | is( ((stat($Testfile))[2] & 07777) & 0700,
|
|---|
| 119 | 0100, 'change a file to execute-only' );
|
|---|
| 120 |
|
|---|
| 121 | # change a file to read-only
|
|---|
| 122 | @ARGV = ( '0400', $Testfile );
|
|---|
| 123 | ExtUtils::Command::chmod();
|
|---|
| 124 |
|
|---|
| 125 | is( ((stat($Testfile))[2] & 07777) & 0700,
|
|---|
| 126 | ($^O eq 'vos' ? 0500 : 0400), 'change a file to read-only' );
|
|---|
| 127 |
|
|---|
| 128 | # change a file to write-only
|
|---|
| 129 | @ARGV = ( '0200', $Testfile );
|
|---|
| 130 | ExtUtils::Command::chmod();
|
|---|
| 131 |
|
|---|
| 132 | is( ((stat($Testfile))[2] & 07777) & 0700,
|
|---|
| 133 | ($^O eq 'vos' ? 0700 : 0200), 'change a file to write-only' );
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | # change a file to read-write
|
|---|
| 137 | @ARGV = ( '0600', $Testfile );
|
|---|
| 138 | my @orig_argv = @ARGV;
|
|---|
| 139 | ExtUtils::Command::chmod();
|
|---|
| 140 | is_deeply( \@ARGV, \@orig_argv, 'chmod preserves @ARGV' );
|
|---|
| 141 |
|
|---|
|
|---|