t/000-module.t
changeset 2 1bd03bcf26b4
parent 1 9416fc33d2a0
equal deleted inserted replaced
1:9416fc33d2a0 2:1bd03bcf26b4
     1 use strict;
     1 use strict;
     2 use warnings;
     2 use warnings;
     3 use Test::More;
     3 use Test::More;
       
     4 use File::Temp;
       
     5 
       
     6 my $dir = File::Temp->newdir();
     4 
     7 
     5 use_ok "Fops";
     8 use_ok "Fops";
     6 
     9 
     7 my $fops = Fops->new(native => "/tmp");
    10 my $fops = Fops->new(native => $dir);
     8 isa_ok($fops => "Fops");
    11 isa_ok($fops => "Fops");
     9 isa_ok($fops => "Fops::native");
    12 isa_ok($fops => "Fops::native");
    10 is($fops->type => "native", "type is native");
    13 is($fops->type => "native", "type is native");
    11 
    14 
    12 foreach (qw(type pwd cd)) {
    15 foreach (qw(type pwd cd stat)) {
    13     can_ok $fops => $_;
    16     can_ok $fops => $_;
    14 }
    17 }
    15 is($fops->pwd() => "/", "working dir is /");
    18 is($fops->pwd() => "/", "working dir is /");
       
    19 is($fops->root() => $dir, "root is $dir");
    16 
    20 
    17 my @dir = (
    21 my @dir = (
    18     "////" => "/",
    22     "////" => "/",
    19     "/.//./" => "/",
    23     "/.//./" => "/",
    20     "/.//./." => "/",
    24     "/.//./." => "/",
    21     "././/./." => "/",
    25     "././/./." => "/",
    22     "/a/b/c/d/" => "/a/b/c/d",
    26     "/a/b/c/d/" => "/a/b/c/d",
    23     "/a/b/c/d" => "/a/b/c/d",
    27     "/a/b/c/d" => "/a/b/c/d",
    24     ".."       => "/a/b/c",
    28     ".."       => "/",
    25 );
    29 );
    26 
    30 
    27 while (@dir) {
    31 while (@dir) {
    28     my $dir = shift @dir;
    32     my $dir = shift @dir;
    29     my $pwd = shift @dir;
    33     my $pwd = shift @dir;
       
    34     is(Fops::_path($dir) => $pwd, "canonical $dir");
       
    35 }
       
    36 is(Fops::_path(qw(/a b c)) => "/a/b/c", "canonical /a/b/c");
    30 
    37 
    31     ok($fops->cd($dir), "cd $dir");
    38 
    32     is($fops->pwd(), $pwd, "pwd should be $pwd");
    39 ok($fops->stat("/"), "stat /");
    33 }
    40 ok($fops->is_dir("/"), "is dir /");
       
    41 
       
    42 ok($fops->mkpath("a"), "mkpath a");
       
    43 ok($fops->is_dir("/a"), "dir /a");
       
    44 
       
    45 ok($fops->mkpath("/x/y/z", "/a/b/c"), "dirs");
       
    46 ok($fops->is_dir("/x/y/z"), "dir /x/y/z");
       
    47 ok($fops->is_dir("/a/b/c"), "dir /a/b/c");
       
    48 
    34 
    49 
    35 
    50 
    36 done_testing;
    51 done_testing;