| 1 | package Test2::Harness::UI::Util; | ||||||||||||||||||||||||||||
| 2 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 8 | our $VERSION = '0.000150'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use File::ShareDir(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use Test2::Harness::Util qw/mod2file/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use Test2::Harness::UI::UUID qw/uuid_inflate/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 8 | ▶ | use Importer Importer => 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 8 | our @EXPORT = qw/share_dir share_file qdb_driver dbd_driver config_from_settings find_job format_duration parse_duration is_invalid_subtest_name/; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 8 | my %SCHEMA_TO_QDB_DRIVER = ( | |||||||||||||||||||||||||||
| 19 | mariadb => 'MySQL', | ||||||||||||||||||||||||||||
| 20 | mysql => 'MySQL', | ||||||||||||||||||||||||||||
| 21 | postgresql => 'PostgreSQL', | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 8 | my %SCHEMA_TO_DBD_DRIVER = ( | |||||||||||||||||||||||||||
| 25 | mariadb => 'DBD::MariaDB', | ||||||||||||||||||||||||||||
| 26 | mysql => 'DBD::mysql', | ||||||||||||||||||||||||||||
| 27 | postgresql => 'DBD::postgresql', | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 8 | my %BAD_ST_NAME = ( | |||||||||||||||||||||||||||
| 31 | '__ANON__' => 1, | ||||||||||||||||||||||||||||
| 32 | 'unnamed' => 1, | ||||||||||||||||||||||||||||
| 33 | 'unnamed subtest' => 1, | ||||||||||||||||||||||||||||
| 34 | 'unnamed summary' => 1, | ||||||||||||||||||||||||||||
| 35 | '<UNNAMED ASSERTION>' => 1, | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub is_invalid_subtest_name { | ||||||||||||||||||||||||||
|
Subroutine
is_invalid_subtest_name: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | 0 | my ($name) = @_; | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | return $BAD_ST_NAME{$name} // 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$BAD_ST_NAME{$name} // 0
MC/DC0%0/1
$BAD_ST_NAME{$name} // 0
$BAD_ST_NAME{$name}
Truth table0%0/2
A
A= $BAD_ST_NAME{$name}
| |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub find_job { | ||||||||||||||||||||||||||
|
Subroutine
find_job: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 0 | my ($schema, $uuid, $try) = @_; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $uuid = uuid_inflate($uuid) or croak "Invalid job identifier"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | my $jobs = $schema->resultset('Job'); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if (length $try) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return $jobs->search({job_id => $uuid}, {order_by => {'-desc' => 'job_try'}, limit => 1})->first | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | if $try == -1; | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | return $jobs->search({job_id => $uuid, job_try => $try})->first; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | return $jobs->search({job_key => $uuid})->first | ||||||||||||||||||||||||||
|
Condition0%0/3
$jobs->search({'job_key', $uuid})->first || $jobs->search({'job_id', $uuid}, {'order_by', {'-desc', 'job_try'}, 'limit', 1})->first
MC/DC0%0/2
$jobs->search({'job_key', $uuid})->first || $jobs->search({'job_id', $uuid}, {'order_by', {'-desc', 'job_try'}, 'limit', 1})->first
$jobs->search({'job_key', $uuid})->first
$jobs->search({'job_id', $uuid}, {'order_by', {'-desc', 'job_try'}, 'limit', 1})->first
Truth table0%0/3
A || B
A= $jobs->search({'job_key', $uuid})->firstB= $jobs->search({'job_id', $uuid}, {'order_by', {'-desc', 'job_try'}, 'limit', 1})->first
| |||||||||||||||||||||||||||||
| 58 | || $jobs->search({job_id => $uuid}, {order_by => {'-desc' => 'job_try'}, limit => 1})->first; | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 4 | ▶ | sub base_name { | ||||||||||||||||||||||||||
|
Subroutine
base_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 62 | 4 | my ($in) = @_; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 4 | my $out = lc($in); | |||||||||||||||||||||||||||
| 65 | 4 | $out =~ s/\.sql$//; | |||||||||||||||||||||||||||
| 66 | 4 | $out =~ s/\d+$//g; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 4 | return $out; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 4 | ▶ | sub qdb_driver { | ||||||||||||||||||||||||||
|
Subroutine
qdb_driver: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 72 | 4 | my $base = base_name(@_); | |||||||||||||||||||||||||||
| 73 | 4 | return $SCHEMA_TO_QDB_DRIVER{$base}; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub dbd_driver { | ||||||||||||||||||||||||||
|
Subroutine
dbd_driver: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 77 | 0 | my $base = base_name(@_); | |||||||||||||||||||||||||||
| 78 | 0 | return $SCHEMA_TO_DBD_DRIVER{$base}; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub share_file { | ||||||||||||||||||||||||||
|
Subroutine
share_file: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 82 | 0 | my ($file) = @_; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | return File::ShareDir::dist_file('Test2-Harness-UI' => $file) | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | unless 'dev' eq ($ENV{T2_HARNESS_UI_ENV} || ''); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$ENV{'T2_HARNESS_UI_ENV'} || ''
MC/DC0%0/1
$ENV{'T2_HARNESS_UI_ENV'} || ''
$ENV{'T2_HARNESS_UI_ENV'}
Truth table0%0/2
A
A= $ENV{'T2_HARNESS_UI_ENV'}
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | my $path = "share/$file"; | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | croak "Could not find '$file'" unless -e $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | return $path; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub share_dir { | ||||||||||||||||||||||||||
|
Subroutine
share_dir: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 94 | 0 | my ($dir) = @_; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | my $path; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ('dev' eq ($ENV{T2_HARNESS_UI_ENV} || '')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$ENV{'T2_HARNESS_UI_ENV'} || ''
MC/DC0%0/1
$ENV{'T2_HARNESS_UI_ENV'} || ''
$ENV{'T2_HARNESS_UI_ENV'}
Truth table0%0/2
A
A= $ENV{'T2_HARNESS_UI_ENV'}
| |||||||||||||||||||||||||||||
| 99 | 0 | $path = "share/$dir"; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | else { | ||||||||||||||||||||||||||||
| 102 | 0 | my $root = File::ShareDir::dist_dir('Test2-Harness-UI'); | |||||||||||||||||||||||||||
| 103 | 0 | $path = "$root/$dir"; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | croak "Could not find '$dir'" unless -d $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | return $path; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub config_from_settings { | ||||||||||||||||||||||||||
|
Subroutine
config_from_settings: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 112 | 0 | my ($settings) = @_; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | my $db = $settings->prefix('yathui-db') or die "No DB settings"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if (my $cmod = $db->config) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | my $file = mod2file($cmod); | |||||||||||||||||||||||||||
| 118 | 0 | require $file; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | return $cmod->yath_ui_config(%$$db); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | my $dsn = $db->dsn; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | unless ($dsn) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | $dsn = ""; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | my $driver = $db->driver; | |||||||||||||||||||||||||||
| 129 | 0 | my $name = $db->name; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | $dsn .= "dbi:$driver" if $driver; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | $dsn .= ":dbname=$name" if $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if (my $socket = $db->socket) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 0 | my $ld = lc($driver); | |||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ($ld eq 'pg') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 0 | $dsn .= ";host=$socket"; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | else { | ||||||||||||||||||||||||||||
| 140 | 0 | $dsn .= ";${ld}_socket=$socket"; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | else { | ||||||||||||||||||||||||||||
| 144 | 0 | my $host = $db->host; | |||||||||||||||||||||||||||
| 145 | 0 | my $port = $db->port; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | $dsn .= ";host=$host" if $host; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | $dsn .= ";port=$port" if $port; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | require Test2::Harness::UI::Config; | |||||||||||||||||||||||||||
| 153 | 0 | ▶ | return Test2::Harness::UI::Config->new( | ||||||||||||||||||||||||||
|
Condition0%0/4
$db->user // ""
$db->pass // ""
MC/DC0%0/1
$db->user // ""
$db->user
MC/DC0%0/1
$db->pass // ""
$db->pass
Truth table0%0/2
A
A= $db->user
Truth table0%0/2
A
A= $db->pass
| |||||||||||||||||||||||||||||
| 154 | dbi_dsn => $dsn, | ||||||||||||||||||||||||||||
| 155 | dbi_user => $db->user // '', | ||||||||||||||||||||||||||||
| 156 | dbi_pass => $db->pass // '', | ||||||||||||||||||||||||||||
| 157 | ); | ||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 1 | ▶ | sub format_duration { | ||||||||||||||||||||||||||
|
Subroutine
format_duration: called CC=6 SCAR=18.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 161 | 1 | my $seconds = shift; | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 1 | my $minutes = int($seconds / 60); | |||||||||||||||||||||||||||
| 164 | 1 | my $hours = int($minutes / 60); | |||||||||||||||||||||||||||
| 165 | 1 | my $days = int($hours / 24); | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 1 | $minutes %= 60; | |||||||||||||||||||||||||||
| 168 | 1 | $hours %= 24; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 1 | $seconds -= $minutes * 60; | |||||||||||||||||||||||||||
| 171 | 1 | $seconds -= $hours * 60 * 60; | |||||||||||||||||||||||||||
| 172 | 1 | $seconds -= $days * 60 * 60 * 24; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 1 | my @dur; | |||||||||||||||||||||||||||
| 175 | 1 | ▶ | push @dur => sprintf("%02dd", $days) if $days; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 1 | ▶ | push @dur => sprintf("%02dh", $hours) if @dur || $hours; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@dur or $hours
MC/DC0%0/2
@dur or $hours
@dur
$hours
Truth table33%1/3
A or B
A= @durB= $hours
| |||||||||||||||||||||||||||||
| 177 | 1 | ▶ | push @dur => sprintf("%02dm", $minutes) if @dur || $minutes; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@dur or $minutes
MC/DC0%0/2
@dur or $minutes
@dur
$minutes
Truth table33%1/3
A or B
A= @durB= $minutes
| |||||||||||||||||||||||||||||
| 178 | 1 | push @dur => sprintf("%07.4fs", $seconds); | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 1 | return join ':' => @dur; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 7 | ▶ | sub parse_duration { | ||||||||||||||||||||||||||
|
Subroutine
parse_duration: called CC=9 SCAR=22.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 184 | 7 | my $duration = shift; | |||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 7 | ▶ | return 0 unless $duration; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 6 | ▶ | return $duration unless $duration =~ m/:?.*[dhms]$/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 5 | my $out = 0; | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 5 | my (@parts) = split ':' => $duration; | |||||||||||||||||||||||||||
| 193 | 5 | for my $part (@parts) { | |||||||||||||||||||||||||||
| 194 | 8 | my ($num, $type) = ($part =~ m/^([0-9\.]+)([dhms])$/); | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 8 | ▶ | unless ($num && $type) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$num and $type
MC/DC0%0/2
$num and $type
$num
$type
Truth table33%1/3
A and B
A= $numB= $type
| |||||||||||||||||||||||||||||
| 197 | 0 | warn "invalid duration section '$part'"; | |||||||||||||||||||||||||||
| 198 | 0 | next; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 8 | ▶ | if ($type eq 'd') { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 202 | 2 | $out += ($num * 60 * 60 * 24); | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | elsif ($type eq 'h') { | ||||||||||||||||||||||||||||
| 205 | 2 | $out += ($num * 60 * 60); | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | elsif ($type eq 'm') { | ||||||||||||||||||||||||||||
| 208 | 2 | $out += ($num * 60); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | else { | ||||||||||||||||||||||||||||
| 211 | 2 | $out += $num; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 5 | return $out; | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 8 | 1; | |||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | __END__ | ||||||||||||||||||||||||||||