File Coverage

blib/lib/Test/File/Cmp.pm
Criterion Covered Total %
statement 40 40 100.0
branch 5 6 83.3
condition 2 3 66.6
subroutine 8 8 100.0
pod 1 1 100.0
total 56 58 96.5


line stmt bran cond sub pod time code
1             package Test::File::Cmp;
2              
3 2     2   185840 use 5.010;
  2         7  
4 2     2   19 use strict;
  2         6  
  2         67  
5 2     2   9 use warnings;
  2         4  
  2         120  
6              
7 2     2   12 use File::Spec;
  2         3  
  2         81  
8              
9 2     2   10 use Test::Builder;
  2         3  
  2         46  
10              
11 2     2   9 use Exporter 'import';
  2         2  
  2         946  
12              
13              
14             our $VERSION = '0.06';
15              
16             our @EXPORT_OK = qw(file_is);
17              
18             my $Test = Test::Builder->new;
19              
20             sub file_is($$;$) {
21 5     5 1 244686 my ($got_f, $exp_f, $name) = (_resolve(shift), _resolve(shift), shift);
22 5   66     26 $name //= "compare file '$got_f' with '$exp_f'";
23 5         9 my @got_lines = split(/\r?\n/, do { local (*ARGV, $/); @ARGV = ($got_f); <> });
  5         48  
  5         14  
  5         582  
24 5         17 my @exp_lines = split(/\r?\n/, do { local (*ARGV, $/); @ARGV = ($exp_f); <> });
  5         31  
  5         18  
  5         350  
25 5 100       28 if (@got_lines != @exp_lines) {
26 1         30 $Test->ok(0, $name);
27 1         1263 $Test->diag(" Different number of lines");
28 1         564 return 0;
29             }
30 4         10 my $n = @got_lines;
31 4         16 for (my $i = 0; $i < $n; ++$i) {
32 10         23 my ($got, $exp) = ($got_lines[$i], $exp_lines[$i]);
33 10 100       34 if ($got ne $exp) {
34 1         10 $Test->ok(0, $name);
35 1         1439 $Test->diag(" Files differ at line " . ($i + 1));
36 1         620 return 0;
37             }
38             }
39 3         18 return $Test->ok(1, $name);
40             }
41              
42              
43             sub _resolve {
44 10 50   10   179 $_[0] =~ m{/} ? File::Spec->catfile(split(m{/}, shift)) : shift;
45             }
46              
47              
48              
49             1; # End of Test::File::Cmp
50              
51              
52             __END__