1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
use strict;
use warnings;
use Test::More tests => 36;
use Test::NoWarnings;
use lib './lib';
use File::Util qw( SL OS );
my $f = File::Util->new();
my @fls = ( qq[t${\SL}txt], qq[t${\SL}bin], 't', '.', '..' );
# types
is_deeply
[ $f->file_type( $fls[0] ) ],
[ qw( PLAIN TEXT ) ],
'text file detected as PLAIN TEXT OK';
is_deeply
[ $f->file_type( $fls[1] ) ],
[ qw( PLAIN BINARY ) ],
'bin file detected as PLAIN BINARY OK';
# file is/isn't binary
ok $f->is_bin( $fls[1], 1 ), 'detects binary file is binary';
ok !$f->is_bin( __FILE__ ), 'detects source file is NOT binary';
for my $file ( @fls ) {
# get file size
ok $f->size( $file ) == -s $file,
'File::Util correctly calculates a file\'s size';
# get file creation time
ok $f->created( $file ) == $^T - ((-M $file) * 60 * 60 * 24),
'and gets correct file creation time OK';
# get file last access time
ok $f->last_access( $file ) == $^T - ((-A $file) * 60 * 60 * 24),
'and gets last access time OK';
# get file last modified time
ok $f->last_modified( $file ) == $^T - ((-M $file) * 60 * 60 * 24),
'and gets lastmod time OK';
# get file's bitmask
ok $f->bitmask( $file ) eq sprintf('%04o',(stat($file))[2] & 0777),
'and gets bitmask OK';
}
SKIP: {
skip 'these tests not performed on window$', 3 if OS eq 'WINDOWS';
is_deeply
[ $f->file_type( $fls[2] ) ],
[ qw( BINARY DIRECTORY ) ],
'detects directory filetype OK';
is_deeply
[ $f->file_type( $fls[3] ) ],
[ qw( BINARY DIRECTORY ) ],
'detects directory filetype OK';
is_deeply
[ $f->file_type( $fls[4] ) ],
[ qw( BINARY DIRECTORY ) ],
'detects directory filetype OK';
}
is +( $f->file_type( $fls[2] ) )[-1],
'DIRECTORY',
'detects file is a directory OK';
is +( $f->file_type( $fls[3] ) )[-1],
'DIRECTORY',
'detects file is a directory OK';
is +( $f->file_type( $fls[4] ) )[-1],
'DIRECTORY',
'detects file is a directory OK';
exit;
|