File Coverage

t/dir.t
Criterion Covered Total %
statement 45 45 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 53 53 100.0


line stmt bran cond sub pod time code
1 1     1   11385 use strict;
  1         2  
  1         30  
2 1     1   4 use warnings;
  1         1  
  1         19  
3 1     1   10 use v5.12;
  1         3  
  1         26  
4              
5 1     1   303 use Test::More tests => 9;
  1         10710  
  1         6  
6              
7 1     1   651 use File::Temp qw(tempdir);
  1         11899  
  1         50  
8 1     1   183 use Sweet::Dir;
  1         3  
  1         27  
9 1     1   232 use Sweet::File::CSV;
  1         3  
  1         2277  
10              
11 1         122556 my $test_dir = Sweet::Dir->new( path => 't' );
12              
13 1         3 ok $test_dir->is_a_directory, 't/ is a directory';
14              
15 1         289 my $sub_dir1 = $test_dir->sub_dir( 'foo', 'bar' );
16 1         5 my $sub_dir2 = $test_dir->sub_dir( [ 'foo', 'bar' ] );
17              
18 1         2 my $dir1 = $test_dir->sub_dir('dir1');
19              
20 1         19 is $sub_dir1->path, $sub_dir2->path, "both sub_dir('foo','bar') and sub_dir(['foo','bar']) work";
21              
22 1         178 my $file = $test_dir->file('file');
23 1         3 isa_ok $file , 'Sweet::File';
24 1         227 ok $file->does_not_exists, 'file() returns a reference to a file without creating it';
25              
26             my $file2 = $test_dir->file('file', sub {
27 1     1   2         my ( $dir, $name ) = @_;
28              
29 1         28         my $file = Sweet::File::CSV->new(
30                         dir => $dir,
31                         name => $name,
32                     );
33              
34 1         2         return $file;
35 1         199 });
36 1         4 isa_ok $file2, 'Sweet::File::CSV', 'file() accepts an optional reference to a sub builder';
37              
38 1         207 my $temp_dir = Sweet::Dir->new( path => tempdir() )->sub_dir('created');
39 1         21 ok $temp_dir->does_not_exists, 'to be created dir does not exists';
40 1         196 $temp_dir->create;
41 1         136 ok $temp_dir->is_a_directory, 'created dir now exists';
42              
43 1         187 my @expected_files1 = sort qw(file1.csv file1.dat file1.txt file2 file2.ext);
44 1         4 my @got_files1 = sort $dir1->file_list;
45 1         5 is_deeply \@got_files1, \@expected_files1, 'file_list';
46              
47 1         368 my @expected_files2 = sort qw(file1.csv file1.dat file1.txt);
48 1         4 my @got_files2 = sort $test_dir->file_list('file\d\.\w\w\w');
49 1         4 is_deeply \@got_files2, \@expected_files2, 'file_list(regexp)';
50              
51