#!/usr/bin/perl
{
my
$t
= File::TreeCreate->new();
ok(
$t
,
"TreeCreate object was initialized"
);
is(
$t
->get_path(
"./t/file.txt"
),
File::Spec->catfile( File::Spec->curdir(),
"t"
,
"file.txt"
) );
is(
$t
->get_path(
"./t/mydir/"
),
File::Spec->catdir( File::Spec->curdir(),
"t"
,
"mydir"
) );
is(
$t
->get_path(
"./t/hello/there/world.jpg"
),
File::Spec->catfile(
File::Spec->curdir(),
"t"
,
"hello"
,
"there"
,
"world.jpg"
)
);
is(
$t
->get_path(
"./one/two/three/four/"
),
File::Spec->catdir(
File::Spec->curdir(),
"one"
,
"two"
,
"three"
,
"four"
)
);
}
{
my
$t
= File::TreeCreate->new();
ok(
$t
->exist(
"./MANIFEST"
),
"Checking the exist() method"
);
ok( !
$t
->exist(
"./BKLASDJASFDJODIJASDOJASODJ.wok"
),
"Checking the exist() method"
);
ok(
$t
->is_file(
"./MANIFEST"
),
"Checking the is_file method"
);
ok( !
$t
->is_file(
"./t"
),
"Checking the is_file method - 2"
);
ok( !
$t
->is_dir(
"./MANIFEST"
),
"Checking the is_dir method - false"
);
ok(
$t
->is_dir(
"./t"
),
"Checking the is_dir method - true"
);
is(
$t
->cat(
"./t/sample-data/h.txt"
),
"Hello."
,
"Checking the cat method"
);
{
mkdir
(
$t
->get_path(
"./t/sample-data/tree-create-ls-test"
) );
mkdir
(
$t
->get_path(
"./t/sample-data/tree-create-ls-test/a"
) );
{
open
my
$out_fh
,
">"
,
$t
->get_path(
"./t/sample-data/tree-create-ls-test/b.txt"
);
print
{
$out_fh
}
"Yowza"
;
close
(
$out_fh
);
}
mkdir
(
$t
->get_path(
"./t/sample-data/tree-create-ls-test/c"
) );
{
open
my
$out_fh
,
">"
,
$t
->get_path(
"./t/sample-data/tree-create-ls-test/h.xls"
);
print
{
$out_fh
}
"FooBardom!\n"
;
close
(
$out_fh
);
}
is_deeply(
$t
->ls(
"./t/sample-data/tree-create-ls-test"
),
[
"a"
,
"b.txt"
,
"c"
,
"h.xls"
],
"Testing the ls method"
,
);
rmtree(
$t
->get_path(
"./t/sample-data/tree-create-ls-test"
) );
}
{
my
$tree
= {
'name'
=>
"tree-create--tree-test-1/"
,
'subs'
=> [
{
'name'
=>
"b.doc"
,
'contents'
=>
"This file was spotted in the wild."
,
},
{
'name'
=>
"a/"
,
},
{
'name'
=>
"foo/"
,
'subs'
=> [
{
'name'
=>
"yet/"
,
},
],
},
],
};
$t
->create_tree(
"./t/sample-data/"
,
$tree
);
is_deeply(
$t
->ls(
"./t/sample-data/tree-create--tree-test-1"
),
[
"a"
,
"b.doc"
,
"foo"
],
"Testing the contents of the root tree"
);
ok(
$t
->is_dir(
"./t/sample-data/tree-create--tree-test-1/a"
),
"a is a dir"
);
is_deeply(
$t
->ls(
"./t/sample-data/tree-create--tree-test-1/a"
),
[],
"Testing the contents of a"
);
is_deeply(
$t
->ls(
"./t/sample-data/tree-create--tree-test-1/foo"
),
[
"yet"
],
"Testing the contents of foo"
);
ok(
$t
->is_dir(
"./t/sample-data/tree-create--tree-test-1/foo/yet"
),
"Testing that foo/yet is a dir"
);
is_deeply(
$t
->ls(
"./t/sample-data/tree-create--tree-test-1/foo/yet"
),
[],
"Testing that foo/yet is a dir"
);
ok(
$t
->is_file(
"./t/sample-data/tree-create--tree-test-1/b.doc"
),
"Checking that b.doc is a file"
);
is(
$t
->cat(
"./t/sample-data/tree-create--tree-test-1/b.doc"
),
"This file was spotted in the wild."
,
"Checking for contents of b.doc"
);
rmtree(
$t
->get_path(
"./t/sample-data/tree-create--tree-test-1"
) );
}
{
is(
$t
->get_path(
"s/hello"
),
File::Spec->catfile(
"s"
,
"hello"
),
"Bug that eliminated ^[AnyChar]/ instead of ^\\./"
);
}
}