1#!perl
2
3use Test::More;
4
5use Devel::Cover::Report::Clover::Builder;
6
7use FindBin;
8use lib ($FindBin::Bin);
9use testcover;
10
11my $DB = testcover::run('multi_file');
12
13my $b = BUILDER( { name => 'test', db => $DB } );
14my @files = @{ $b->file_registry->files };
15
16my @test = (
17    sub {
18        my $t = "files - file registry has all files listed";
19        is( scalar @files, 3, $t );
20    },
21);
22
23my %expected_file_stats = (
24    'MultiFile/First.pm' => {
25        loc         => 3,
26        ncloc       => 6,
27        line_count  => 9,
28        class_count => 1,
29        total       => {
30            covered    => 3,
31            percentage => 100,
32            total      => 3,
33        }
34    },
35    'MultiFile/Second.pm' => {
36        loc         => 2,
37        ncloc       => 6,
38        line_count  => 8,
39        class_count => 1,
40        total       => {
41            covered    => 3,
42            percentage => 100,
43            total      => 3,
44        }
45    },
46    'MultiFile.pm' => {
47        loc         => 12,
48        ncloc       => 22,
49        line_count  => 34,
50        class_count => 2,
51        total       => {
52            covered    => 19,
53            error      => 3,
54            percentage => '86.3636363636364',
55            total      => 29,
56        }
57    },
58);
59
60foreach my $file (@files) {
61    ( my $rel_path = $file ) =~ s{.*cover_db_test/multi_file/}{};
62    my $expected = $expected_file_stats{$rel_path};
63    push @test, sub {
64        my $t   = "loc - $file";
65        my $got = $file->loc;
66        is( $got, $expected->{loc}, $t );
67    };
68    push @test, sub {
69        my $t   = "ncloc - $file";
70        my $got = $file->ncloc;
71        is( $got, $expected->{ncloc}, $t );
72    };
73    push @test, sub {
74        my $t   = "line count - $file";
75        my $got = scalar @{ $file->lines };
76        is( $got, $expected->{line_count}, $t );
77    };
78    push @test, sub {
79        my $t   = "summary calculation - $file";
80        my $got = $file->summarize();
81
82        is( $got->{total}->{total},   $expected->{total}->{total},   "$t - total" );
83        is( $got->{total}->{covered}, $expected->{total}->{covered}, "$t - covered" );
84    };
85    push @test, sub {
86        my $t       = "class count -> $file";
87        my @classes = @{ $file->classes };
88        my $got     = scalar @classes;
89        is( $got, $expected->{class_count}, $t );
90        }
91}
92
93plan tests => scalar @test + ( 1 * scalar @files );
94
95$_->() foreach @test;
96
97sub BUILDER {
98    return Devel::Cover::Report::Clover::Builder->new(shift);
99}
100
101