Model/File.pm

filter: Statementstmt 48.8% 44 / 90 Branchbran 3.3% 1 / 30 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 48.5% 17 / 35 Podpod 94.7% 18 / 19 totaltotal 44.0% 81 / 184 CC 19 SCAR 24.7
CC
19
Cov
37%
_test_structs
56.0
equal
20.0
bailed_out
12.0
CRAP 11.8
↑ Summary Model/Subtest.pm »
1 #!/usr/bin/perl
2  
3 package Test::TAP::Model::File;
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Test::TAP::Model::Subtest;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use List::Util (); # don't import max, we have our own. We use it fully qualified
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use overload '""' => "name", '==' => "equal";
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Method::Alias (
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 (map { ($_ => 'cases') } qw/seen_tests seen test_cases subtests/),
15 1 (map { ($_ => 'ok_tests') } qw/passed_tests/),
16 1 (map { ($_ => 'nok_tests') } qw/failed_tests/),
17 1 (map { ($_ => 'planned') } qw/max/),
18 1 (map { ($_ => 'ok') } qw/passed/),
19 1 (map { ($_ => 'nok') } qw/failed/),
20 1 );
21  
22 # TODO test this more thoroughly, probably with Devel::Cover
23  
24 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
25 1 my $pkg = shift;
26 1 my $struct = shift;
27 1 bless { struct => $struct }, $pkg; # don't bless the structure, it's not ours to mess with
28 }
29  
30 # predicates about the test file
31 6 ▶sub ok { $_[0]{struct}{results}->passing };
Subroutine ok: called CC=1 SCAR=0.0
Pod documented
32 1 ▶sub nok { !$_[0]->ok };
Subroutine nok: called CC=1 SCAR=0.0
Pod documented
33 2 ▶sub skipped { defined($_[0]{struct}{results}->skip_all) };
Subroutine skipped: called CC=1 SCAR=0.0
Pod documented
34 0 ▶sub bailed_out {
Subroutine bailed_out: not called CC=3 SCAR=24.8
Pod documented
35 0 ▶ my $event = $_[0]{struct}{events}[-1] or return;
Branch: 1 branch
BranchTrueFalseTotal
my $event = $_[0]{"struct"}{"events"}[-1] or return 0 0 0
36 0 ▶ return unless exists $event->{type};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $event->{"type"} 0 0 0
37 0 return $event->{type} eq "bailout";
38 }
39  
40 # member data queries
41 0 ▶sub name { $_[0]{struct}{file} }
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
42  
43 # utility methods for extracting tests.
44 0 ▶sub subtest_class { "Test::TAP::Model::Subtest" }
Subroutine subtest_class: not called CC=1 SCAR=6.9
Pod documented
45 0 ▶sub _mk_objs { my $self = shift; wantarray ? map { $self->subtest_class->new($_) } @_ : @_ }
Subroutine _mk_objs: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
46 0 ▶sub _test_structs {
Subroutine _test_structs: not called CC=7 SCAR=40.3
47 0 my $self = shift;
48 0 my $max = $self->{struct}{results}->max;
49  
50 # cases is an array of *copies*... that's what the map is about
51 0 ▶ my @cases = grep { exists $_->{type} and $_->{type} eq "test" } @{ $self->{struct}{events} };
Condition0%0/3
exists $_->{'type'} && $_->{'type'} eq 'test'
!ll&&!rl&&r
000
MC/DC0%0/2
exists $_->{'type'} && $_->{'type'} eq 'test'
exists $_->{'type'} $_->{'type'} eq 'test'
Truth table0%0/3
A && B
A= exists $_->{'type'}B= $_->{'type'} eq 'test'
ABresult
0X0
100
111
52  
53 0 ▶ if (defined $max){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max) 0 0 0
54 0 ▶ if ($max > @cases){
Branch: 2 branches
BranchTrueFalseTotal
if ($max > @cases) { } 0 0 0
elsif (@cases > $max) { } 0 0 0
55 # add failed stubs for tests missing from plan
56 0 my %bailed = (
57 type => "test",
58 ok => 0,
59 line => "stub",
60 );
61  
62 0 for my $num (@cases + 1 .. $max) {
63 0 push @cases, { %bailed, num => $num };
64 }
65 } elsif (@cases > $max) {
66 # mark extra tests as unplanned
67 0 my $diff = @cases - $max;
68 0 ▶ for (my $i = $diff; $i; $i--){
Branch: 1 branch
BranchTrueFalseTotal
if ($i) 0 0 0
69 0 $cases[-$i]{unplanned} = 1;
70 }
71 }
72 }
73  
74 0 @cases;
75 }
76 9 ▶sub _c {
Subroutine _c: called CC=3 SCAR=13.5
77 9 my $self = shift;
78 9 my $sub = shift;
79 9 my $scalar = shift;
80 9 ▶ return $scalar if not wantarray and defined $scalar; # if we have a precomputed scalar
Branch: 1 branch
BranchTrueFalseTotal
if not wantarray and defined $scalar 9 0 9
Condition33%1/3
not wantarray and defined $scalar
!ll&&!rl&&r
009
MC/DC0%0/2
not wantarray and defined $scalar
not wantarray defined $scalar
Truth table33%1/3
not(A) and B
A= not wantarrayB= defined $scalar
ABresult
0X0
100
111
81 0 $self->_mk_objs(grep { &$sub } $self->_test_structs);
82 }
83  
84 # queries about the test cases
85 1 ▶sub planned { $_[0]{struct}{results}->max };
Subroutine planned: called CC=1 SCAR=0.0
Pod documented
86  
87 2 ▶sub cases {
Subroutine cases: called CC=1 SCAR=0.1
Pod documented
88 2 my @values = map { $_[0]{struct}{results}->$_ } qw/seen max/;
89 2 my $scalar = List::Util::max(@values);
90 0 ▶ $_[0]->_c(sub { 1 }, $scalar)
Subroutine __ANON__: not called CC=1 SCAR=1.2
91 };
92 0 ▶sub actual_cases { $_[0]->_c(sub { $_->{line} ne "stub" }, $_[0]{struct}{results}->seen) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine actual_cases: not called CC=1 SCAR=6.9
Pod documented
93 0 ▶sub ok_tests { $_[0]->_c(sub { $_->{ok} }, $_[0]{struct}{results}->ok) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
Subroutine ok_tests: called CC=1 SCAR=1.2
Pod documented
94 0 ▶sub nok_tests { $_[0]->_c(sub { not $_->{ok} }, $_[0]->seen - $_[0]->ok_tests )};
Subroutine __ANON__: not called CC=1 SCAR=1.2
Subroutine nok_tests: called CC=1 SCAR=1.2
Pod documented
95 0 ▶sub todo_tests { $_[0]->_c(sub { $_->{todo} }, $_[0]{struct}{results}->todo) }
Subroutine __ANON__: not called CC=1 SCAR=1.2
Subroutine todo_tests: called CC=1 SCAR=1.2
Pod documented
96 0 ▶sub skipped_tests { $_[0]->_c(sub { $_->{skip} }, $_[0]{struct}{results}->skip) }
Subroutine __ANON__: not called CC=1 SCAR=1.2
Subroutine skipped_tests: called CC=1 SCAR=1.2
Pod documented
97 0 ▶sub unexpectedly_succeeded_tests { $_[0]->_c(sub { $_->{todo} and $_->{actual_ok} }) }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Subroutine unexpectedly_succeeded_tests: not called CC=1 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_->{"todo"} and $_->{"actual_ok"} 0 0 0
98  
99 0 ▶sub ratio {
Subroutine ratio: not called CC=3 SCAR=24.8
Pod documented
100 0 my $self = shift;
101 0 ▶ $self->seen ? $self->ok_tests / $self->seen : ($self->ok ? 1 : 0); # no tests is an error
Branch: 2 branches
BranchTrueFalseTotal
$self->seen ? : 0 0 0
$self->ok ? : 0 0 0
102 }
103  
104 0 ▶sub percentage {
Subroutine percentage: not called CC=1 SCAR=6.9
Pod documented
105 0 my $self = shift;
106 0 sprintf("%.2f%%", 100 * $self->ratio);
107 }
108  
109 0 ▶sub pre_diag { $_[0]{struct}{pre_diag} || ""}
Subroutine pre_diag: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"struct"}{"pre_diag"} or "" 0 0 0
110  
111 0 ▶sub equal {
Subroutine equal: not called CC=4 SCAR=30.0
Pod undocumented
112 0 my $self = shift;
113 0 my $other = shift;
114  
115 # number of sub-tests
116 0 ▶ return unless $self->seen == $other->seen;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->seen == $other->seen 0 0 0
117  
118 # values of subtests
119 0 my @self = $self->cases;
120 0 my @other = $other->cases;
121  
122 0 ▶ while (@self) {
Branch: 1 branch
BranchTrueFalseTotal
if (@self) 0 0 0
123 0 ▶ return unless (pop @self) == (pop @other);
Branch: 1 branch
BranchTrueFalseTotal
unless pop @self == pop @other 0 0 0
124 }
125  
126 0 1;
127 }
128  
129 1 __PACKAGE__
130  
131 __END__
↑ Summary Model/Subtest.pm »