File Coverage

blib/lib/Test/Data/Sah/Format.pm
Criterion Covered Total %
statement 68 70 97.1
branch 3 8 37.5
condition 3 5 60.0
subroutine 19 19 100.0
pod 1 1 100.0
total 94 103 91.2


line stmt bran cond sub pod time code
1             package Test::Data::Sah::Format;
2              
3 2     2   1578 use 5.010001;
  2         5  
4 2     2   7 use strict 'subs', 'vars';
  2         2  
  2         42  
5 2     2   5 use warnings;
  2         2  
  2         37  
6              
7 2     2   690 use Data::Sah::Format;
  2         3  
  2         49  
8 2     2   795 use Test::Exception;
  2         21552  
  2         6  
9 2     2   1609 use Test::More 0.98;
  2         8811  
  2         14  
10              
11 2     2   530 use Exporter qw(import);
  2         3  
  2         436  
12             our @EXPORT = qw(test_format);
13              
14             sub test_format {
15 10     10 1 358810 my %args = @_;
16              
17 10   50     56 my $compiler = $args{compiler} // 'perl';
18 10         6 my $module;
19 10 50       37 if ($compiler eq 'perl') {
    0          
20 10         13 $module = "Data::Sah::Format";
21             } elsif ($compiler eq 'js') {
22 0         0 $module = "Data::Sah::FormatJS";
23             } else {
24 0         0 die "Unknown compiler '$compiler'";
25             }
26 10 50   1   583 eval "use $module"; die if $@;
  10     1   28  
  1     1   6  
  1     1   1  
  1     1   18  
  1     1   6  
  1     1   1  
  1     1   14  
  1     1   5  
  1     1   1  
  1         12  
  1         8  
  1         2  
  1         14  
  1         5  
  1         1  
  1         11  
  1         5  
  1         1  
  1         11  
  1         5  
  1         1  
  1         13  
  1         4  
  1         1  
  1         11  
  1         5  
  1         1  
  1         11  
  1         4  
  1         1  
  1         12  
27              
28 10         11 my $formatter;
29             subtest +($args{name} // $args{format}) => sub {
30              
31             lives_ok {
32 10         45 $formatter = &{"$module\::gen_formatter"}(
33             format => $args{format},
34             formatter_args => $args{formatter_args},
35 10         199 );
36 10     10   3483 };
37 10 50       1999 if (exists $args{data}) {
38 10         11 for my $i (0..$#{ $args{data} }) {
  10         30  
39 18         1487 my $data = $args{data}[$i];
40 18         406 my $fdata = $formatter->($data);
41 18         610 is_deeply($fdata, $args{fdata}[$i]);
42             }
43             }
44 10   66     73 };
45             }
46              
47             1;
48             # ABSTRACT: Test routines for testing Data::Sah::Format::* modules
49              
50             __END__