File: file.t

package info (click to toggle)
libdevel-cover-report-clover-perl 1.01-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 252 kB
  • sloc: perl: 1,740; makefile: 2
file content (100 lines) | stat: -rw-r--r-- 2,499 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!perl

use Test::More;

use Devel::Cover::Report::Clover::Builder;

use FindBin;
use lib ($FindBin::Bin);
use testcover;

my $DB = testcover::run('multi_file');

my $b = BUILDER( { name => 'test', db => $DB } );
my @files = @{ $b->file_registry->files };

my @test = (
    sub {
        my $t = "files - file registry has all files listed";
        is( scalar @files, 3, $t );
    },
);

my %expected_file_stats = (
    'MultiFile/First.pm' => {
        loc         => 3,
        ncloc       => 6,
        line_count  => 9,
        class_count => 1,
        total       => {
            covered    => 3,
            percentage => 100,
            total      => 3,
        }
    },
    'MultiFile/Second.pm' => {
        loc         => 2,
        ncloc       => 6,
        line_count  => 8,
        class_count => 1,
        total       => {
            covered    => 3,
            percentage => 100,
            total      => 3,
        }
    },
    'MultiFile.pm' => {
        loc         => 12,
        ncloc       => 22,
        line_count  => 34,
        class_count => 2,
        total       => {
            covered    => 19,
            error      => 3,
            percentage => '86.3636363636364',
            total      => 29,
        }
    },
);

foreach my $file (@files) {
    ( my $rel_path = $file ) =~ s{.*cover_db_test/multi_file/}{};
    my $expected = $expected_file_stats{$rel_path};
    push @test, sub {
        my $t   = "loc - $file";
        my $got = $file->loc;
        is( $got, $expected->{loc}, $t );
    };
    push @test, sub {
        my $t   = "ncloc - $file";
        my $got = $file->ncloc;
        is( $got, $expected->{ncloc}, $t );
    };
    push @test, sub {
        my $t   = "line count - $file";
        my $got = scalar @{ $file->lines };
        is( $got, $expected->{line_count}, $t );
    };
    push @test, sub {
        my $t   = "summary calculation - $file";
        my $got = $file->summarize();

        is( $got->{total}->{total},   $expected->{total}->{total},   "$t - total" );
        is( $got->{total}->{covered}, $expected->{total}->{covered}, "$t - covered" );
    };
    push @test, sub {
        my $t       = "class count -> $file";
        my @classes = @{ $file->classes };
        my $got     = scalar @classes;
        is( $got, $expected->{class_count}, $t );
        }
}

plan tests => scalar @test + ( 1 * scalar @files );

$_->() foreach @test;

sub BUILDER {
    return Devel::Cover::Report::Clover::Builder->new(shift);
}