| 1 | #!/usr/bin/perl |
| 2 | |
| 3 | use strict; |
| 4 | use warnings; |
| 5 | use File::Spec; |
| 6 | use File::Basename; |
| 7 | use Test::More; |
| 8 | use File::Path qw(make_path remove_tree); |
| 9 | use Test::CheckManifest; |
| 10 | use Cwd; |
| 11 | |
| 12 | # create a directory and a file |
| 13 | my $sub = Test::CheckManifest->can('_find_home'); |
| 14 | ok $sub; |
| 15 | |
| 16 | my $dir = Cwd::realpath( File::Spec->catdir( dirname( __FILE__ ), '..' ) ); |
| 17 | my $file = File::Spec->catfile( $dir, 'MANIFEST' ); |
| 18 | |
| 19 | my @dirs_one = File::Spec->splitdir( $dir ); |
| 20 | my @dirs_two = File::Spec->splitdir( $sub->( {} ) ); |
| 21 | is_deeply \@dirs_two, \@dirs_one, 'tmp_path => $0'; |
| 22 | |
| 23 | my ($vol,$dirs,$file_one) = File::Spec->splitpath($file); |
| 24 | |
| 25 | my @dirs_three = File::Spec->splitdir( $sub->( {file => $file} ) ); |
| 26 | is_deeply \@dirs_three, \@dirs_one, 'file ' . $file; |
| 27 | |
| 28 | my @dirs_five = File::Spec->splitdir( $sub->( { dir => $dir } ) ); |
| 29 | is_deeply \@dirs_five, \@dirs_one, 'dir ' . $dir; |
| 30 | |
| 31 | $sub->( { dir => $vol || '/' } ); |
| 32 | $sub->( { dir => '/this/dir/does/not/exist/test/checkmanifest' } ); |
| 33 | |
| 34 | my $deep_path_one = File::Spec->catdir( $dir, 'deep' ); |
| 35 | my $deep_path_two = File::Spec->catdir( $deep_path_one, qw/path one and another level to search for/ ); |
| 36 | make_path $deep_path_two; |
| 37 | $sub->( { dir => $deep_path_two } ); |
| 38 | remove_tree $deep_path_one; |
| 39 | |
| 40 | done_testing(); |