lib/Test2/Harness/UI/Schema/Overlay/Run.pm

filter: Statementstmt 18.8% 20 / 106 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 35.7% 5 / 14 Podpod 0.0% 0 / 8 totaltotal 12.8% 25 / 195 CC 27 SCAR 35.8
CC
27
Cov
12%
__ANON__
90.0
rerun_data
56.0
TO_JSON
20.0
CRAP 35.8
« lib/Test2/Harness/UI/Response.pm ↑ Summary lib/Test2/Harness/UI/Loader.pm »
1 package Test2::Harness::UI::Schema::Result::Run;
2 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Carp qw/confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '0.000150';
9  
10 2 ▶use Test2::Harness::UI::Util::DateTimeFormat qw/DTF/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 __PACKAGE__->inflate_column(
13 parameters => {
14 inflate => DBIx::Class::InflateColumn::Serializer::JSON->get_unfreezer('parameters', {}),
15 deflate => DBIx::Class::InflateColumn::Serializer::JSON->get_freezer('parameters', {}),
16 },
17 );
18  
19 # For joining
20 2 __PACKAGE__->belongs_to(
21 "user_join",
22 "Test2::Harness::UI::Schema::Result::User",
23 { user_id => "user_id" },
24 { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
25 );
26  
27 2 my %COMPLETE_STATUS = (complete => 1, failed => 1, canceled => 1, broken => 1);
28 0 ▶sub complete { return $COMPLETE_STATUS{$_[0]->status} // 0 }
Subroutine complete: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/2
$COMPLETE_STATUS{$_[0]->status} // 0
l!l
00
MC/DC0%0/1
$COMPLETE_STATUS{$_[0]->status} // 0
$COMPLETE_STATUS{$_[0]->status}
Truth table0%0/2
A
A= $COMPLETE_STATUS{$_[0]->status}
Aresult
11
00
29  
30 0 ▶sub sig {
Subroutine sig: not called CC=3 SCAR=24.8
Pod undocumented
31 0 my $self = shift;
32  
33 return join ";" => (
34 0 ▶ (map {$self->$_ // ''} qw/status pinned passed failed retried concurrency/),
Condition0%0/2
$self->$_ // ""
l!l
00
MC/DC0%0/1
$self->$_ // ""
$self->$_
Truth table0%0/2
A
A= $self->$_
Aresult
11
00
35 0 ▶ (map {length($self->$_ // '')} qw/parameters/),
Condition0%0/2
$self->$_ // ""
l!l
00
MC/DC0%0/1
$self->$_ // ""
$self->$_
Truth table0%0/2
A
A= $self->$_
Aresult
11
00
36 ($self->run_fields->count),
37 );
38 }
39  
40 0 ▶sub short_run_fields {
Subroutine short_run_fields: not called CC=2 SCAR=17.9
Pod undocumented
41 0 my $self = shift;
42  
43 0 ▶ return [ map { my $d = +{$_->get_all_fields}; $d->{data} = $d->{has_data} ? \'1' : \'0'; $d } $self->run_fields->search(undef, {
Branch: 1 branch
BranchTrueFalseTotal
$d->{'has_data'} ? : 0 0 0
44 remove_columns => ['data'],
45 '+select' => ['data IS NOT NULL AS has_data'],
46 '+as' => ['has_data'],
47 })->all ];
48 }
49  
50 0 ▶sub TO_JSON {
Subroutine TO_JSON: not called CC=4 SCAR=30.0
Pod undocumented
51 0 my $self = shift;
52 0 my %cols = $self->get_all_fields;
53  
54 # Just No.
55 0 delete $cols{log_data};
56  
57 # Inflate
58 0 $cols{parameters} = $self->parameters;
59 0 ▶ $cols{user} //= $self->user->username;
Condition0%0/3
$cols{"user"} //= $self->user->username
l!l&&r!l&&!r
000
MC/DC0%0/2
$cols{"user"} //= $self->user->username
$cols{"user"} $self->user->username
Truth table0%0/3
A //= B
A= $cols{"user"}B= $self->user->username
ABresult
1X1
011
000
60 0 ▶ $cols{project} //= $self->project->name;
Condition0%0/3
$cols{"project"} //= $self->project->name
l!l&&r!l&&!r
000
MC/DC0%0/2
$cols{"project"} //= $self->project->name
$cols{"project"} $self->project->name
Truth table0%0/3
A //= B
A= $cols{"project"}B= $self->project->name
ABresult
1X1
011
000
61  
62 0 ▶ if ($cols{prefetched_fields}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cols{'prefetched_fields'}) { } 0 0 0
63 0 $cols{fields} = [ map { {$_->get_all_fields} } $self->run_fields ];
64 }
65 else {
66 0 $cols{fields} = $self->short_run_fields;
67 }
68  
69 0 my $dt = DTF()->parse_datetime( $cols{added} );
70  
71 0 $cols{added} = $dt->strftime("%Y-%m-%d %I:%M%P");
72  
73 0 return \%cols;
74 }
75  
76 0 ▶sub normalize_to_mode {
Subroutine normalize_to_mode: not called CC=3 SCAR=24.8
Pod undocumented
77 0 my $self = shift;
78 0 my %params = @_;
79  
80 0 my $mode = $params{mode};
81  
82 0 ▶ if ($mode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode) { } 0 0 0
83 0 $self->update({mode => $mode});
84 }
85 else {
86 0 $mode = $self->mode;
87 }
88  
89 0 $_->normalize_to_mode(mode => $mode) for $self->jobs->all;
90 }
91  
92 0 ▶sub expanded_coverages {
Subroutine expanded_coverages: not called CC=2 SCAR=17.9
Pod undocumented
93 0 my $self = shift;
94 0 my ($query) = @_;
95  
96 0 my $pick_me = {run_id => $self->run_id};
97  
98 0 ▶ if ($query) {
Branch: 1 branch
BranchTrueFalseTotal
if ($query) { } 0 0 0
99 0 $query = {'-and' => [$query, $pick_me]};
100 }
101 else {
102 0 $query = $pick_me;
103 }
104  
105 0 my $schema = $self->result_source->schema;
106 0 $schema->resultset('Coverage')->search(
107 $query,
108 {
109 order_by => [qw/test_file_id source_file_id source_sub_id/],
110 join => [qw/test_file source_file source_sub coverage_manager/],
111 '+columns' => {
112 test_file => 'test_file.filename',
113 source_file => 'source_file.filename',
114 source_sub => 'source_sub.subname',
115 manager => 'coverage_manager.package',
116 },
117 },
118 );
119 }
120  
121 0 ▶sub coverage_data {
Subroutine coverage_data: not called CC=3 SCAR=24.8
Pod undocumented
122 0 my $self = shift;
123 0 my (%params) = @_;
124  
125 0 my $query = $params{query};
126 0 my $rs = $self->expanded_coverages($query);
127  
128 0 my $curr_test;
129 my $data;
130 0 my $end = 0;
131  
132 0 my $run_id;
133 0 ▶ my $iterator = sub {
Subroutine __ANON__: not called CC=9 SCAR=45.0
134 0 while (1) {
135 0 ▶ return undef if $end;
Branch: 1 branch
BranchTrueFalseTotal
if $end 0 0 0
136  
137 0 my $out;
138  
139 0 my $item = $rs->next;
140 0 ▶ if (!$item) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($item) 0 0 0
141 0 $end = 1;
142 0 $out = $data;
143 0 $data = undef;
144 0 return $out;
145 }
146  
147 0 ▶ $run_id //= $item->run_id;
Condition0%0/3
$run_id //= $item->run_id
l!l&&r!l&&!r
000
MC/DC0%0/2
$run_id //= $item->run_id
$run_id $item->run_id
Truth table0%0/3
A //= B
A= $run_idB= $item->run_id
ABresult
1X1
011
000
148 0 ▶ die "Different run id!" if $run_id ne $item->run_id;
Branch: 1 branch
BranchTrueFalseTotal
if $run_id ne $item->run_id 0 0 0
149  
150 0 my $fields = $item->human_fields;
151 0 my $test = $fields->{test_file};
152 0 ▶ if (!$curr_test || $curr_test ne $test) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $curr_test or $curr_test ne $test) 0 0 0
Condition0%0/3
not $curr_test or $curr_test ne $test
l!l&&r!l&&!r
000
MC/DC0%0/2
not $curr_test or $curr_test ne $test
not $curr_test $curr_test ne $test
Truth table0%0/3
not(A) or B
A= not $curr_testB= $curr_test ne $test
ABresult
1X1
011
000
153 0 $out = $data;
154 0 $data = undef;
155  
156 0 $curr_test = $test;
157  
158 0 $data = {
159 test => $test,
160 aggregator => 'Test2::Harness::Log::CoverageAggregator::ByTest',
161 files => {},
162 };
163  
164 0 ▶ $data->{manager} = $fields->{manager} if $fields->{manager};
Branch: 1 branch
BranchTrueFalseTotal
if $fields->{"manager"} 0 0 0
165 }
166  
167 0 my $source = $fields->{source_file};
168 0 my $sub = $fields->{source_sub};
169 0 my $meta = $fields->{metadata};
170  
171 0 $data->{files}->{$source}->{$sub} = $meta;
172  
173 0 ▶ return $out if $out;
Branch: 1 branch
BranchTrueFalseTotal
if $out 0 0 0
174 }
175 0 };
176  
177 0 ▶ return $iterator if $params{iterator};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"iterator"} 0 0 0
178  
179 0 my @out;
180 0 ▶ while (my $item = $iterator->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $item = &$iterator()) 0 0 0
181 0 push @out => $item;
182 }
183  
184 0 return @out;
185 }
186  
187 0 ▶sub rerun_data {
Subroutine rerun_data: not called CC=7 SCAR=40.3
Pod undocumented
188 0 my $self = shift;
189  
190 0 my $files = $self->jobs->search(
191 {},
192 {join => 'test_file', order_by => 'test_file.filename'},
193 );
194  
195 0 my $data = {};
196  
197 0 ▶ while (my $file = $files->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = $files->next) 0 0 0
198 0 ▶ my $name = $file->file || next;
Condition0%0/2
$file->file || (next)
l!l
00
MC/DC0%0/1
$file->file || (next)
$file->file
Truth table0%0/2
A
A= $file->file
Aresult
11
00
199  
200 0 ▶ my $row = $data->{$name} //= {};
Condition0%0/2
$data->{$name} //= {}
l!l
00
MC/DC0%0/1
$data->{$name} //= {}
$data->{$name}
Truth table0%0/2
A
A= $data->{$name}
Aresult
11
00
201  
202 0 ▶ $row->{retry}++ if $file->job_try > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $file->job_try > 0 0 0 0
203  
204 0 ▶ if($file->ended) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->ended) 0 0 0
205 0 $row->{end}++;
206 0 ▶ $row->{$file->fail ? 'fail' : 'pass'}++;
Branch: 1 branch
BranchTrueFalseTotal
$file->fail ? : 0 0 0
207 }
208 }
209  
210 0 return $data;
211 }
212  
213 2 1;
214  
215 __END__
« lib/Test2/Harness/UI/Response.pm ↑ Summary lib/Test2/Harness/UI/Loader.pm »