| 1 | package DBIO::Test::AsyncParity; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: The same ResultSet operations, synchronous and asynchronous, on one database, compared | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Test::More (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use DBIO::Exception (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use DBIO::Test::AsyncParity::Cases (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # ---------------------------------------------------------------- the seams | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 4 | my %KIND = map { $_ => 1 } qw(unsupported pending absent); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # The monikers the fixture and the cases use. | ||||||||||||||||||||||||||||
| 20 | 4 | my @REQUIRED = qw(Artist CD Track OneKey); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub table_version { 2 } | ||||||||||||||||||||||||||
|
Subroutine
table_version: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 22 | ▶ | sub cases { return DBIO::Test::AsyncParity::Cases->cases } | ||||||||||||||||||||||||||
|
Subroutine
cases: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | ▶ | sub parity_deviations { {} } | ||||||||||||||||||||||||||
|
Subroutine
parity_deviations: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 184 | ▶ | sub parity_seed { | ||||||||||||||||||||||||||
|
Subroutine
parity_seed: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 184 | my ($class, $schema) = @_; | |||||||||||||||||||||||||||
| 34 | 184 | my $fixture = DBIO::Test::AsyncParity::Cases->fixture; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 184 | my %artist; | |||||||||||||||||||||||||||
| 37 | 184 | for my $a (@{ $fixture->{artists} }) { | |||||||||||||||||||||||||||
| 38 | 552 | my ($name, $rank) = @$a; | |||||||||||||||||||||||||||
| 39 | 552 | $artist{$name} = $schema->resultset('Artist')->create({ name => $name, rank => $rank }); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 184 | my %cd; | |||||||||||||||||||||||||||
| 43 | 184 | for my $c (@{ $fixture->{cds} }) { | |||||||||||||||||||||||||||
| 44 | 736 | my ($artist, $title, $year) = @$c; | |||||||||||||||||||||||||||
| 45 | 736 | $cd{$title} = $artist{$artist}->create_related('cds', { title => $title, year => $year }); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 184 | for my $t (@{ $fixture->{tracks} }) { | |||||||||||||||||||||||||||
| 49 | 736 | my ($cd, $position, $title) = @$t; | |||||||||||||||||||||||||||
| 50 | 736 | $cd{$cd}->create_related('tracks', { position => $position, title => $title }); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 184 | return; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 281 | ▶ | sub parity_reset { | ||||||||||||||||||||||||||
|
Subroutine
parity_reset: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 281 | my ($class, $schema) = @_; | |||||||||||||||||||||||||||
| 59 | 281 | $schema->resultset($_)->delete({ all => 1 }) for qw(OneKey Track CD Artist); | |||||||||||||||||||||||||||
| 60 | 281 | return; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 8 | ▶ | sub parity_capabilities { | ||||||||||||||||||||||||||
|
Subroutine
parity_capabilities: called CC=6 SCAR=20.5
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 8 | my ($class, $harness) = @_; | |||||||||||||||||||||||||||
| 66 | 8 | my $async = $harness->async; | |||||||||||||||||||||||||||
| 67 | 0 | my %have = map { $_ => 1 } $async->transport_capabilities; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 8 | ▶ | if (my $refusal = $async->_pipeline_refusal) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 8 | ▶ | $refusal->failure if $refusal->can('failure'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||
| 73 | 0 | $have{pipeline} = 1; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 8 | ▶ | $have{cancel} = 1 if $async->future_class->can('cancel'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 8 | my $pool = $async->pool; | |||||||||||||||||||||||||||
| 78 | 8 | ▶ | $have{pool_queue} = 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($pool) and $pool->isa("DBIO::Storage::PoolBase")
MC/DC0%0/2
builtin::blessed($pool) and $pool->isa("DBIO::Storage::PoolBase")
builtin::blessed($pool)
$pool->isa("DBIO::Storage::PoolBase")
Truth table33%1/3
A and B
A= builtin::blessed($pool)B= $pool->isa("DBIO::Storage::PoolBase")
| |||||||||||||||||||||||||||||
| 79 | if Scalar::Util::blessed($pool) && $pool->isa('DBIO::Storage::PoolBase'); | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 8 | return sort keys %have; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub parity_fault { | ||||||||||||||||||||||||||
|
Subroutine
parity_fault: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 0 | my ($class, $schema, $harness, $name) = @_; | |||||||||||||||||||||||||||
| 87 | 0 | DBIO::Exception->throw("this transport offers no fault '$name'"); | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 8 | ▶ | sub parity_session_sql { | ||||||||||||||||||||||||||
|
Subroutine
parity_session_sql: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | return ( | ||||||||||||||||||||||||||||
| 93 | 8 | 'CREATE TEMPORARY TABLE parity_session_tmp (a INTEGER)', | |||||||||||||||||||||||||||
| 94 | 'SELECT a FROM parity_session_tmp', | ||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub parity_unreachable { | ||||||||||||||||||||||||||
|
Subroutine
parity_unreachable: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | 0 | DBIO::Exception->throw('this transport offers no unreachable connection'); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 2 | ▶ | sub parity_sync_schema { | ||||||||||||||||||||||||||
|
Subroutine
parity_sync_schema: called CC=6 SCAR=19.0
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 2 | my ($class, $harness) = @_; | |||||||||||||||||||||||||||
| 106 | 2 | my $schema_class = $harness->{schema_class}; | |||||||||||||||||||||||||||
| 107 | DBIO::Exception->throw( | ||||||||||||||||||||||||||||
| 108 | 'parity_sync_schema: the harness carries no schema_class and no DSN; ' | ||||||||||||||||||||||||||||
| 109 | . 'the transport class must override parity_sync_schema' | ||||||||||||||||||||||||||||
| 110 | 2 | ▶ | ) unless defined $schema_class and defined $harness->{dsn}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $schema_class and defined $harness->{"dsn"}
MC/DC0%0/2
defined $schema_class and defined $harness->{"dsn"}
defined $schema_class
defined $harness->{"dsn"}
Truth table33%1/3
A and B
A= defined $schema_classB= defined $harness->{"dsn"}
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | # The harness's driver, declared on a clone so the shared schema class stays | ||||||||||||||||||||||||||||
| 113 | # undeclared (ADR 0067 ยง4); without one the class declares its own or core | ||||||||||||||||||||||||||||
| 114 | # refuses it. | ||||||||||||||||||||||||||||
| 115 | 2 | my $schema = $schema_class; | |||||||||||||||||||||||||||
| 116 | 2 | ▶ | if (defined(my $storage_type = $harness->{storage_type})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 1 | $schema = $schema_class->clone; | |||||||||||||||||||||||||||
| 118 | 1 | $schema->storage_type($storage_type); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | return $schema->connect( | ||||||||||||||||||||||||||||
| 121 | 2 | ▶ | $harness->{dsn}, $harness->{user} // '', $harness->{pass} // '', | ||||||||||||||||||||||||||
|
Condition50%2/4
$harness->{"user"} // ""
$harness->{"pass"} // ""
MC/DC0%0/1
$harness->{"user"} // ""
$harness->{"user"}
MC/DC0%0/1
$harness->{"pass"} // ""
$harness->{"pass"}
Truth table50%1/2
A
A= $harness->{"user"}
Truth table50%1/2
A
A= $harness->{"pass"}
| |||||||||||||||||||||||||||||
| 122 | ); | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | # ---------------------------------------------------- declarations, offline | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 5 | ▶ | sub check_declarations { | ||||||||||||||||||||||||||
|
Subroutine
check_declarations: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||
| 129 | 5 | my ($class) = @_; | |||||||||||||||||||||||||||
| 130 | 5 | my %case = map { $_->{name} => $_ } @{ $class->cases }; | |||||||||||||||||||||||||||
| 131 | 5 | my $declared = $class->parity_deviations; | |||||||||||||||||||||||||||
| 132 | 5 | my @problem; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 5 | ▶ | unless (ref $declared eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 0 | return ('parity_deviations must return a hashref'); | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 5 | for my $name (sort keys %$declared) { | |||||||||||||||||||||||||||
| 139 | 16 | my $decl = $declared->{$name}; | |||||||||||||||||||||||||||
| 140 | 16 | my $label = "deviation '$name'"; | |||||||||||||||||||||||||||
| 141 | 16 | ▶ | push @problem, "$label: unknown case" unless $case{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 16 | ▶ | unless (ref $decl eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 1 | push @problem, "$label: not a hash"; | |||||||||||||||||||||||||||
| 144 | 1 | next; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | 15 | ▶ | my $kind = $decl->{kind} // ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$decl->{"kind"} // ""
MC/DC0%0/1
$decl->{"kind"} // ""
$decl->{"kind"}
Truth table50%1/2
A
A= $decl->{"kind"}
| |||||||||||||||||||||||||||||
| 147 | push @problem, "$label: kind must be 'unsupported', 'pending' or 'absent', not '$kind'" | ||||||||||||||||||||||||||||
| 148 | 15 | ▶ | unless $KIND{$kind}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | push @problem, "$label: reason must be a regex (qr//)" | ||||||||||||||||||||||||||||
| 150 | 15 | ▶ | unless ref $decl->{reason} eq 'Regexp'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | push @problem, "$label: the table already marks this case absent" | ||||||||||||||||||||||||||||
| 152 | 15 | ▶ | if $case{$name} and $case{$name}{absent}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$case{$name} and $case{$name}{"absent"}
MC/DC100%2/2
$case{$name} and $case{$name}{"absent"}
$case{$name}
$case{$name}{"absent"}
Truth table100%3/3
A and B
A= $case{$name}B= $case{$name}{"absent"}
| |||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | 5 | return @problem; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | # What a case may deviate by: the transport's declarations plus the table's own | ||||||||||||||||||||||||||||
| 158 | # absences, by case name. | ||||||||||||||||||||||||||||
| 159 | 8 | ▶ | sub _deviations { | ||||||||||||||||||||||||||
|
Subroutine
_deviations: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 160 | 8 | my ($class) = @_; | |||||||||||||||||||||||||||
| 161 | 8 | my %dev = %{ $class->parity_deviations }; | |||||||||||||||||||||||||||
| 162 | 8 | for my $case (@{ $class->cases }) { | |||||||||||||||||||||||||||
| 163 | $dev{ $case->{name} } = { kind => 'absent', reason => $case->{absent} } | ||||||||||||||||||||||||||||
| 164 | 448 | ▶ | if $case->{absent}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | 8 | return \%dev; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # ------------------------------------------------------------ the run itself | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 9 | ▶ | sub results { | ||||||||||||||||||||||||||
|
Subroutine
results: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 173 | 9 | my ($class, %opt) = @_; | |||||||||||||||||||||||||||
| 174 | my $harness = $opt{harness} | ||||||||||||||||||||||||||||
| 175 | 9 | ▶ | or DBIO::Exception->throw('results() needs harness => a DBIO::Test::AsyncHarness'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 9 | ▶ | my $schema_class = $opt{schema_class} // 'DBIO::Test::Schema'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opt{"schema_class"} // "DBIO::Test::Schema"
MC/DC100%1/1
$opt{"schema_class"} // "DBIO::Test::Schema"
$opt{"schema_class"}
Truth table100%2/2
A
A= $opt{"schema_class"}
| |||||||||||||||||||||||||||||
| 177 | 9 | my $schema = $harness->schema; | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 9 | my @missing = grep { !eval { $schema->source($_); 1 } } @REQUIRED; | |||||||||||||||||||||||||||
| 180 | DBIO::Exception->throw( | ||||||||||||||||||||||||||||
| 181 | 9 | ▶ | "the connected schema has no source " . join(', ', map {"'$_'"} @missing) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | . "; the case table is written for $schema_class" | ||||||||||||||||||||||||||||
| 183 | ) if @missing; | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 8 | my @cases = @{ $class->cases }; | |||||||||||||||||||||||||||
| 186 | 8 | ▶ | if (my $only = $opt{only}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 6 | my %want = map { $_ => 1 } @$only; | |||||||||||||||||||||||||||
| 188 | 6 | @cases = grep { $want{ $_->{name} } } @cases; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 8 | my $deviations = $class->_deviations; | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 8 | my $sync_schema; | |||||||||||||||||||||||||||
| 194 | 8 | my %provided = map { $_ => 1 } $class->parity_capabilities($harness); | |||||||||||||||||||||||||||
| 195 | my $env = { | ||||||||||||||||||||||||||||
| 196 | harness => $harness, | ||||||||||||||||||||||||||||
| 197 | capabilities => \%provided, | ||||||||||||||||||||||||||||
| 198 | 2 | ▶ | sync_schema => sub { $sync_schema ||= $class->parity_sync_schema($harness) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=9.2
Condition33%1/3
$sync_schema ||= $class->parity_sync_schema($harness)
MC/DC0%0/2
$sync_schema ||= $class->parity_sync_schema($harness)
$sync_schema
$class->parity_sync_schema($harness)
Truth table33%1/3
A ||= B
A= $sync_schemaB= $class->parity_sync_schema($harness)
| |||||||||||||||||||||||||||||
| 199 | 2 | ▶ | fault => sub { $class->parity_fault($schema, $harness, @_) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 200 | session_sql => [ $class->parity_session_sql($harness) ], | ||||||||||||||||||||||||||||
| 201 | 0 | ▶ | unreachable => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 202 | 0 | my $secret = 'parity-secret-' . $$; | |||||||||||||||||||||||||||
| 203 | 0 | return ($class->parity_unreachable($harness, $secret), $secret); | |||||||||||||||||||||||||||
| 204 | }, | ||||||||||||||||||||||||||||
| 205 | 8 | }; | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 8 | my @results = map { $class->_run_case($_, $deviations->{ $_->{name} }, $schema, $env) } @cases; | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 8 | ▶ | if ($sync_schema) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | 2 | eval { $sync_schema->storage->disconnect; 1 }; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | 8 | return @results; | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 4 | ▶ | sub summary_line { | ||||||||||||||||||||||||||
|
Subroutine
summary_line: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 217 | 4 | my ($class, $results) = @_; | |||||||||||||||||||||||||||
| 218 | 4 | my @dev = grep { $_->{status} eq 'deviation' } @$results; | |||||||||||||||||||||||||||
| 219 | 4 | my @absent = grep { $_->{status} eq 'absent' } @$results; | |||||||||||||||||||||||||||
| 220 | 4 | my @skip = grep { $_->{status} eq 'skipped' } @$results; | |||||||||||||||||||||||||||
| 221 | 4 | my @part; | |||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | push @part, scalar(@dev) . ' deviation' . (@dev == 1 ? '' : 's') . ': ' | ||||||||||||||||||||||||||||
| 224 | . join(', ', map { | ||||||||||||||||||||||||||||
| 225 | 4 | ▶ | sprintf '%02d %s (%s)', $_->{no}, $_->{case}, $_->{deviation} | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 226 | 7 | } @dev) | |||||||||||||||||||||||||||
| 227 | if @dev; | ||||||||||||||||||||||||||||
| 228 | push @part, scalar(@absent) . ' absent: ' | ||||||||||||||||||||||||||||
| 229 | 4 | ▶ | . join(', ', map { sprintf '%02d %s', $_->{no}, $_->{case} } @absent) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | if @absent; | ||||||||||||||||||||||||||||
| 231 | push @part, scalar(@skip) . ' skipped: ' | ||||||||||||||||||||||||||||
| 232 | 4 | ▶ | . join(', ', map { sprintf '%02d %s (%s)', $_->{no}, $_->{case}, $_->{message} } @skip) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | if @skip; | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 4 | ▶ | return @part ? join('; ', @part) : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 2 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 240 | 2 | my ($class, %opt) = @_; | |||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 2 | my @problem = $class->check_declarations; | |||||||||||||||||||||||||||
| 243 | 2 | ▶ | Test::More::ok(!@problem, 'the parity declarations are whole') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | or Test::More::diag(join "\n", @problem); | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 2 | my @results = $class->results(%opt); | |||||||||||||||||||||||||||
| 247 | 2 | for my $r (@results) { | |||||||||||||||||||||||||||
| 248 | 57 | my $label = sprintf '%02d %s: %s', $r->{no}, $r->{case}, $r->{status}; | |||||||||||||||||||||||||||
| 249 | 57 | ▶ | $label .= " ($r->{deviation})" if $r->{status} eq 'deviation'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | 57 | ▶ | $label .= " ($r->{message})" if $r->{status} eq 'skipped'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | 57 | ▶ | if ($r->{status} eq 'fail') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | 1 | Test::More::ok(0, $label); | |||||||||||||||||||||||||||
| 253 | 1 | Test::More::diag(sprintf 'case %02d %s: %s', $r->{no}, $r->{case}, $r->{message}); | |||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | else { | ||||||||||||||||||||||||||||
| 256 | 56 | Test::More::ok(1, $label); | |||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 2 | my $line = $class->summary_line(\@results); | |||||||||||||||||||||||||||
| 261 | 2 | ▶ | Test::More::diag($line) if defined $line; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | 2 | return; | |||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | # One case: drive each way after a reset and a seed, compare, and turn what | ||||||||||||||||||||||||||||
| 266 | # happened into one answer. | ||||||||||||||||||||||||||||
| 267 | 121 | ▶ | sub _run_case { | ||||||||||||||||||||||||||
|
Subroutine
_run_case: called CC=15 SCAR=27.4
| |||||||||||||||||||||||||||||
| 268 | 121 | my ($class, $case, $deviation, $schema, $env) = @_; | |||||||||||||||||||||||||||
| 269 | 121 | my $harness = $env->{harness}; | |||||||||||||||||||||||||||
| 270 | 121 | my %r = (no => $case->{no}, case => $case->{name}, kind => $case->{kind}); | |||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | # A case that needs a capability the transport does not have is not run; it | ||||||||||||||||||||||||||||
| 273 | # is a result of its own and names what is missing (see "Capabilities"). | ||||||||||||||||||||||||||||
| 274 | 121 | ▶ | if (my @missing = grep { !$env->{capabilities}{$_} } @{ $case->{requires} || [] }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$case->{'requires'} || []
MC/DC100%1/1
$case->{'requires'} || []
$case->{'requires'}
Truth table100%2/2
A
A= $case->{'requires'}
| |||||||||||||||||||||||||||||
| 275 | 24 | return { %r, status => 'skipped', missing => \@missing, | |||||||||||||||||||||||||||
| 276 | message => 'needs ' . join(', ', @missing) }; | ||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 97 | my ($sync, $async); | |||||||||||||||||||||||||||
| 280 | 97 | my $driven = eval { | |||||||||||||||||||||||||||
| 281 | 97 | ▶ | unless ($case->{kind} eq 'async-only') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 282 | 87 | $class->parity_reset($schema, $harness); | |||||||||||||||||||||||||||
| 283 | 87 | $class->parity_seed($schema, $harness); | |||||||||||||||||||||||||||
| 284 | 87 | $sync = $class->_leg($case, 'sync', $schema, $env); | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | 97 | $class->parity_reset($schema, $harness); | |||||||||||||||||||||||||||
| 287 | 97 | $class->parity_seed($schema, $harness); | |||||||||||||||||||||||||||
| 288 | 97 | $async = $class->_leg($case, 'async', $schema, $env); | |||||||||||||||||||||||||||
| 289 | 97 | 1; | |||||||||||||||||||||||||||
| 290 | }; | ||||||||||||||||||||||||||||
| 291 | 97 | ▶ | my $run_error = $driven ? undef : ($@ || 'unknown error'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$@ or "unknown error"
MC/DC0%0/1
$@ or "unknown error"
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 97 | my $cleaned = eval { $class->parity_reset($schema, $harness); 1 }; | |||||||||||||||||||||||||||
| 294 | 97 | ▶ | my $clean_error = $cleaned ? undef : ($@ || 'unknown error'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$@ or "unknown error"
MC/DC0%0/1
$@ or "unknown error"
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | 97 | ▶ | return { %r, status => 'fail', message => "the run itself failed: $run_error" } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 297 | if defined $run_error; | ||||||||||||||||||||||||||||
| 298 | 97 | ▶ | return { %r, status => 'fail', message => "cleanup failed: $clean_error" } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | if defined $clean_error; | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | 97 | my $verdict = $class->_judge($case, $sync, $async); | |||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 97 | ▶ | if ($deviation) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | 12 | my $declared = $deviation->{kind}; | |||||||||||||||||||||||||||
| 305 | 12 | ▶ | return { %r, status => 'fail', | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | message => "stale deviation: declared $declared" | ||||||||||||||||||||||||||||
| 307 | . ' but the case passes' } | ||||||||||||||||||||||||||||
| 308 | unless defined $verdict; | ||||||||||||||||||||||||||||
| 309 | return { %r, status => 'fail', | ||||||||||||||||||||||||||||
| 310 | message => "the deviation does not match its declared reason $deviation->{reason}" | ||||||||||||||||||||||||||||
| 311 | . " -- got: $verdict" } | ||||||||||||||||||||||||||||
| 312 | 10 | ▶ | unless $verdict =~ $deviation->{reason}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | return { | ||||||||||||||||||||||||||||
| 314 | 9 | ▶ | %r, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 315 | status => $declared eq 'absent' ? 'absent' : 'deviation', | ||||||||||||||||||||||||||||
| 316 | deviation => $declared, | ||||||||||||||||||||||||||||
| 317 | message => $verdict, | ||||||||||||||||||||||||||||
| 318 | }; | ||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 85 | ▶ | return { %r, status => 'fail', message => $verdict } if defined $verdict; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | 82 | return { %r, status => 'pass', message => '' }; | |||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | # One way of one case. Never dies for what the case does: an exception is the | ||||||||||||||||||||||||||||
| 326 | # outcome. The state the case left behind is read through the synchronous path | ||||||||||||||||||||||||||||
| 327 | # either way. | ||||||||||||||||||||||||||||
| 328 | 184 | ▶ | sub _leg { | ||||||||||||||||||||||||||
|
Subroutine
_leg: called CC=9 SCAR=23.0
| |||||||||||||||||||||||||||||
| 329 | 184 | my ($class, $case, $way, $schema, $env) = @_; | |||||||||||||||||||||||||||
| 330 | 184 | my $harness = $env->{harness}; | |||||||||||||||||||||||||||
| 331 | 184 | my %out; | |||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | my @raw; | ||||||||||||||||||||||||||||
| 334 | 184 | my $ok = eval { | |||||||||||||||||||||||||||
| 335 | 184 | ▶ | if ($way eq 'sync') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | 87 | @raw = $case->{sync}->($schema, $env); | |||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | else { | ||||||||||||||||||||||||||||
| 339 | 97 | my $future = $case->{async}->($schema, $env); | |||||||||||||||||||||||||||
| 340 | 91 | @raw = $harness->await($future); | |||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | 168 | 1; | |||||||||||||||||||||||||||
| 343 | }; | ||||||||||||||||||||||||||||
| 344 | 184 | ▶ | if ($ok) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 345 | 0 | ▶ | my $norm = $case->{norm} || sub { [ @_ ] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.0
Condition33%1/3
$case->{'norm'} || sub {
[@_];
}
MC/DC0%0/2
$case->{'norm'} || sub {
[@_];
}
$case->{'norm'}
sub {
[@_];
}
Truth table33%1/3
A || B
A= $case->{'norm'}B= sub {
[@_];
}
| |||||||||||||||||||||||||||||
| 346 | 168 | my $value; | |||||||||||||||||||||||||||
| 347 | 168 | ▶ | if (eval { $value = $norm->(@raw); 1 }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | 168 | %out = (ok => 1, value => $value); | |||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | else { | ||||||||||||||||||||||||||||
| 351 | 0 | ▶ | my $e = $@ || 'unknown error'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$@ || 'unknown error'
MC/DC0%0/1
$@ || 'unknown error'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||
| 352 | 0 | %out = (error => $e, class => _class_of($e), text => _text_of($e)); | |||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||
| 355 | else { | ||||||||||||||||||||||||||||
| 356 | 16 | ▶ | my $e = $@ || 'unknown error'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$@ || 'unknown error'
MC/DC0%0/1
$@ || 'unknown error'
$@
Truth table50%1/2
A
A= $@
| |||||||||||||||||||||||||||||
| 357 | 16 | %out = (error => $e, class => _class_of($e), text => _text_of($e)); | |||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 184 | ▶ | if (my $observe = $case->{observe}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 361 | 70 | my $seen = eval { $observe->($schema) }; | |||||||||||||||||||||||||||
| 362 | 70 | ▶ | $out{observed} = $@ ? 'observe failed: ' . _text_of($@) : $seen; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||
| 364 | 184 | return \%out; | |||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | # core throws every string as a DBIO::Exception; an unblessed error is that. | ||||||||||||||||||||||||||||
| 368 | 16 | ▶ | sub _class_of { | ||||||||||||||||||||||||||
|
Subroutine
_class_of: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 369 | 16 | my ($e) = @_; | |||||||||||||||||||||||||||
| 370 | 16 | ▶ | return Scalar::Util::blessed($e) ? ref($e) : 'DBIO::Exception'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 16 | ▶ | sub _text_of { | ||||||||||||||||||||||||||
|
Subroutine
_text_of: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 374 | 16 | my ($e) = @_; | |||||||||||||||||||||||||||
| 375 | 16 | my $t = "$e"; | |||||||||||||||||||||||||||
| 376 | 16 | $t =~ s/\n.*//s; | |||||||||||||||||||||||||||
| 377 | 16 | return $t; | |||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | # The verdict on one case: undef when it is right, else the message. | ||||||||||||||||||||||||||||
| 381 | 97 | ▶ | sub _judge { | ||||||||||||||||||||||||||
|
Subroutine
_judge: called CC=18 SCAR=29.6
| |||||||||||||||||||||||||||||
| 382 | 97 | my ($class, $case, $sync, $async) = @_; | |||||||||||||||||||||||||||
| 383 | 97 | my $want_error = $case->{expect_error}; | |||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 97 | ▶ | if ($case->{kind} eq 'async-only') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 386 | 10 | ▶ | return _judge_error($want_error, 'async', $async) if $want_error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 387 | 6 | ▶ | return "the asynchronous way threw $async->{class}: $async->{text}" unless $async->{ok}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 388 | 6 | ▶ | if (exists $case->{expect}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 389 | return 'the asynchronous way answered ' . _show($async->{value}) | ||||||||||||||||||||||||||||
| 390 | . ', expected ' . _show($case->{expect}) | ||||||||||||||||||||||||||||
| 391 | 6 | ▶ | unless _same($async->{value}, $case->{expect}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||
| 393 | 6 | return undef; | |||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | 87 | ▶ | if ($want_error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 397 | 6 | for my $pair ([ sync => $sync ], [ async => $async ]) { | |||||||||||||||||||||||||||
| 398 | 10 | my $problem = _judge_error($want_error, @$pair); | |||||||||||||||||||||||||||
| 399 | 10 | ▶ | return $problem if defined $problem; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||
| 401 | return "the exception classes differ: sync $sync->{class}, async $async->{class}" | ||||||||||||||||||||||||||||
| 402 | 4 | ▶ | unless $sync->{class} eq $async->{class}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 403 | 3 | return undef; | |||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | 81 | ▶ | if (!$sync->{ok} and !$async->{ok}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$sync->{"ok"} or $async->{"ok"}
MC/DC50%1/2
$sync->{"ok"} or $async->{"ok"}
$sync->{"ok"}
$async->{"ok"}
Truth table66%2/3
A or B
A= $sync->{"ok"}B= $async->{"ok"}
| |||||||||||||||||||||||||||||
| 407 | 2 | return "the case failed on both ways -- sync: $sync->{class}: $sync->{text}" | |||||||||||||||||||||||||||
| 408 | . " -- async: $async->{class}: $async->{text}"; | ||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||
| 410 | return "the ways differ: sync answered, async threw $async->{class}: $async->{text}" | ||||||||||||||||||||||||||||
| 411 | 79 | ▶ | if $sync->{ok} and !$async->{ok}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$sync->{"ok"} and not $async->{"ok"}
MC/DC50%1/2
$sync->{"ok"} and not $async->{"ok"}
$sync->{"ok"}
not $async->{"ok"}
Truth table66%2/3
A and not(B)
A= $sync->{"ok"}B= not $async->{"ok"}
| |||||||||||||||||||||||||||||
| 412 | return "the ways differ: sync threw $sync->{class}: $sync->{text}, async answered" | ||||||||||||||||||||||||||||
| 413 | 77 | ▶ | if !$sync->{ok} and $async->{ok}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $sync->{"ok"} and $async->{"ok"}
MC/DC0%0/2
not $sync->{"ok"} and $async->{"ok"}
not $sync->{"ok"}
$async->{"ok"}
Truth table33%1/3
not(A) and B
A= not $sync->{"ok"}B= $async->{"ok"}
| |||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | return 'the ways differ in the result: sync ' . _show($sync->{value}) | ||||||||||||||||||||||||||||
| 416 | . ', async ' . _show($async->{value}) | ||||||||||||||||||||||||||||
| 417 | 77 | ▶ | unless _same($sync->{value}, $async->{value}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 418 | return 'the ways differ in what they left behind: sync ' . _show($sync->{observed}) | ||||||||||||||||||||||||||||
| 419 | . ', async ' . _show($async->{observed}) | ||||||||||||||||||||||||||||
| 420 | 73 | ▶ | unless _same($sync->{observed}, $async->{observed}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 421 | 73 | return undef; | |||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | 14 | ▶ | sub _judge_error { | ||||||||||||||||||||||||||
|
Subroutine
_judge_error: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||
| 425 | 14 | my ($want, $way, $out) = @_; | |||||||||||||||||||||||||||
| 426 | return "the $way way threw nothing, an exception was expected (answered " | ||||||||||||||||||||||||||||
| 427 | . _show($out->{value}) . ')' | ||||||||||||||||||||||||||||
| 428 | 14 | ▶ | if $out->{ok}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 429 | return "the $way way threw '$out->{text}', which does not match $want" | ||||||||||||||||||||||||||||
| 430 | 10 | ▶ | if ref $want eq 'Regexp' and $out->{text} !~ $want; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $want eq "Regexp" and not $out->{"text"} =~ /$want/
MC/DC0%0/2
ref $want eq "Regexp" and not $out->{"text"} =~ /$want/
ref $want eq "Regexp"
not $out->{"text"} =~ /$want/
Truth table66%2/3
A and not(B)
A= ref $want eq "Regexp"B= not $out->{"text"} =~ /$want/
| |||||||||||||||||||||||||||||
| 431 | 10 | return undef; | |||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | 76 | ▶ | sub _show { | ||||||||||||||||||||||||||
|
Subroutine
_show: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 435 | 76 | my ($v) = @_; | |||||||||||||||||||||||||||
| 436 | 76 | ▶ | return 'undef' unless defined $v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 437 | 76 | ▶ | return '[' . join(', ', map { _show($_) } @$v) . ']' if ref $v eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 438 | 64 | ▶ | return '{' . join(', ', map { "$_ => " . _show($v->{$_}) } sort keys %$v) . '}' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 439 | if ref $v eq 'HASH'; | ||||||||||||||||||||||||||||
| 440 | 44 | ▶ | return ref $v if ref $v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 441 | 42 | return "'$v'"; | |||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | 407 | ▶ | sub _same { | ||||||||||||||||||||||||||
|
Subroutine
_same: called CC=17 SCAR=30.8
| |||||||||||||||||||||||||||||
| 445 | 407 | my ($got, $want) = @_; | |||||||||||||||||||||||||||
| 446 | 407 | ▶ | return 1 if !defined $got and !defined $want; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $got or defined $want
MC/DC50%1/2
defined $got or defined $want
defined $got
defined $want
Truth table66%2/3
A or B
A= defined $gotB= defined $want
| |||||||||||||||||||||||||||||
| 447 | 356 | ▶ | return 0 if !defined $got or !defined $want; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $got and defined $want
MC/DC0%0/2
defined $got and defined $want
defined $got
defined $want
Truth table33%1/3
A and B
A= defined $gotB= defined $want
| |||||||||||||||||||||||||||||
| 448 | 356 | ▶ | return 0 if ref $got ne ref $want; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 449 | 356 | ▶ | if (ref $want eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 450 | 85 | ▶ | return 0 unless @$got == @$want; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 451 | 81 | ▶ | for my $i (0 .. $#$want) { return 0 unless _same($got->[$i], $want->[$i]) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 452 | 81 | return 1; | |||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||
| 454 | 271 | ▶ | if (ref $want eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 455 | 70 | ▶ | return 0 unless keys %$got == keys %$want; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 456 | 70 | for my $k (keys %$want) { | |||||||||||||||||||||||||||
| 457 | 136 | ▶ | return 0 unless exists $got->{$k} and _same($got->{$k}, $want->{$k}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $got->{$k} and _same($got->{$k}, $want->{$k})
MC/DC0%0/2
exists $got->{$k} and _same($got->{$k}, $want->{$k})
exists $got->{$k}
_same($got->{$k}, $want->{$k})
Truth table33%1/3
A and B
A= exists $got->{$k}B= _same($got->{$k}, $want->{$k})
| |||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||
| 459 | 70 | return 1; | |||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||
| 461 | 201 | ▶ | return 0 if ref $want; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 462 | 201 | ▶ | return $got eq $want ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | 4 | 1; | |||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||
| 467 | __END__ | ||||||||||||||||||||||||||||