Badger
view release on metacpan or search on metacpan
t/filesystem/filesystem.t view on Meta::CPAN
#============================================================= -*-perl-*-
#
# t/filesystem/filesystem.t
#
# Test the Badger::Filesystem module.
#
# Written by Andy Wardley <abw@wardley.org>
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
#========================================================================
use lib qw( ./lib ../lib ../../lib );
use strict;
use warnings;
use File::Spec;
use Badger::Filesystem 'FS VFS :types :dirs cwd getcwd $Bin Bin';
use Badger::Test
tests => 74,
debug => 'Badger::Filesystem',
args => \@ARGV;
our $TDIR = -d 't' ? FS->join_dir(qw(t filesystem)) : FS->directory;
# ugly hack to grok file separator on local filesystem
my $PATHSEP = File::Spec->catdir(('badger') x 2);
$PATHSEP =~ s/badger//g;
# convert unix-like paths into local equivalent
sub lp($) {
my $path = shift;
$path =~ s|/|$PATHSEP|g;
$path;
}
#-----------------------------------------------------------------------
# test $Bin from FindBin, and Bin() as directory wrapper around it
#-----------------------------------------------------------------------
ok( $Bin, "\$Bin is set to $Bin" );
my $bin = Bin;
ok( $bin, "\$bin is set to $bin" );
is( ref $bin, 'Badger::Filesystem::Directory', '$bin is a directory object' );
#-----------------------------------------------------------------------
# test Path(), File() and Directory()
#-----------------------------------------------------------------------
my $rel = File::Spec->catdir('badger_test_p1', 'badger_test_p2');
my $abs = File::Spec->rel2abs($rel, File::Spec->rootdir);
my $path = Path('/badger_test_p1/badger_test_p2');
ok( $path, 'created path using constructor sub' );
is( $path, $abs, 'matched path' );
is( Path('badger_test_p1', 'badger_test_p2'), $rel, 'path with separates' );
my $file = File('/badger_test_p1/badger_test_p2');
is( $file, $abs, 'absolute file' );
is( File('badger_test_p1', 'badger_test_p2'), $rel, 'relative file with separates' );
my $dir = Dir('/badger_test_p1/badger_test_p2');
ok( $dir, 'created dir using constructor sub' );
is( $dir, $abs, 'absolute dir' );
is( Dir('badger_test_p1', 'badger_test_p2'), $rel, 'relative dir with separates' );
$dir = Directory('/badger_test_p1/badger_test_p2');
ok( $dir, 'created directory using constructor sub' );
is( $dir, $abs, 'absolute directory' );
is( Directory('badger_test_p1', 'badger_test_p2'), $rel, 'relative directory with separates' );
#-----------------------------------------------------------------------
# should also work without arguments as class name providers
#-----------------------------------------------------------------------
$path = Path->new('/badger_test_p1/badger_test_p2');
ok( $path, 'created path using constructor class' );
$file = File->new('/badger_test_p1/badger_test_p2');
ok( $file, 'created file using constructor class' );
$dir = Dir->new('/badger_test_p1/badger_test_p2');
ok( $dir, 'created dir using constructor class' );
$dir = Directory->new('/badger_test_p1/badger_test_p2');
ok( $dir, 'created directory using constructor class' );
( run in 2.544 seconds using v1.01-cache-2.11-cpan-364913b4093 )