| 1 | ####################################################################### | ||||||||||||||||||||||||||||||||||||
| 2 | # housekeeping | ||||||||||||||||||||||||||||||||||||
| 3 | ####################################################################### | ||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||
| 5 | package Object::Exercise::Execute v3.1.1; | ||||||||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use v5.20; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 7 | 12 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||
| 11 | 12 | ▶ | use List::Util qw( first ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 12 | 12 | ▶ | use Scalar::Util qw( reftype ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 13 | 12 | ▶ | use Time::HiRes qw( gettimeofday tv_interval ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 14 | 12 | ▶ | use YAML::XS qw( Load ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||
| 16 | 12 | ▶ | use Test::More; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||
| 18 | ######################################################################## | ||||||||||||||||||||||||||||||||||||
| 19 | # package variables | ||||||||||||||||||||||||||||||||||||
| 20 | ######################################################################## | ||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||
| 22 | 12 | our @CARP_NOT = ( __PACKAGE__ ); | |||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||
| 24 | 12 | my @defaultz = | |||||||||||||||||||||||||||||||||||
| 25 | qw | ||||||||||||||||||||||||||||||||||||
| 26 | ( | ||||||||||||||||||||||||||||||||||||
| 27 | benchmark 0 | ||||||||||||||||||||||||||||||||||||
| 28 | counter 0 | ||||||||||||||||||||||||||||||||||||
| 29 | break 0 | ||||||||||||||||||||||||||||||||||||
| 30 | regex 0 | ||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||
| 32 | debug 0 | ||||||||||||||||||||||||||||||||||||
| 33 | verbose 0 | ||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||
| 36 | continue 1 | ||||||||||||||||||||||||||||||||||||
| 37 | finish 1 | ||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||
| 39 | export exercise | ||||||||||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||
| 42 | 12 | my %globalz = @defaultz; | |||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||
| 44 | ######################################################################## | ||||||||||||||||||||||||||||||||||||
| 45 | # local utility subs | ||||||||||||||||||||||||||||||||||||
| 46 | ######################################################################## | ||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||
| 48 | ######################################################################## | ||||||||||||||||||||||||||||||||||||
| 49 | # deal with flag settings | ||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||
| 51 | sub extract_flags | ||||||||||||||||||||||||||||||||||||
| 52 | 163 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
extract_flags: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 53 | 163 | my %flagz = (); | |||||||||||||||||||||||||||||||||||
| 54 | 163 | my $count = 0; | |||||||||||||||||||||||||||||||||||
| 55 | 163 | my $found = 0; | |||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||
| 57 | 163 | for( @_ ) | |||||||||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||||||||||
| 59 | 174 | ▶ | ref $_ | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 60 | and last; | ||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||
| 62 | 25 | ++$count; | |||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||
| 64 | 25 | my ( $negate, $name, $value ) | |||||||||||||||||||||||||||||||||||
| 65 | = m{ (no)? (\w+) (?:=)?( .+ )? }x; | ||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||
| 67 | exists $globalz{ $name } | ||||||||||||||||||||||||||||||||||||
| 68 | or do | ||||||||||||||||||||||||||||||||||||
| 69 | 25 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 70 | 11 | diag "Unknown option: '$_'"; | |||||||||||||||||||||||||||||||||||
| 71 | next | ||||||||||||||||||||||||||||||||||||
| 72 | 11 | }; | |||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||
| 74 | 14 | ++$found; | |||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||
| 76 | 14 | ▶ | $flagz{ $name } | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition75%3/4
$value // 1
$value // 1
MC/DC0%0/1
$value // 1
$value
MC/DC100%1/1
$value // 1
$value
Truth table50%1/2
A
A= $value
Truth table100%2/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||
| 77 | = $negate | ||||||||||||||||||||||||||||||||||||
| 78 | ? ! ( $value // 1 ) | ||||||||||||||||||||||||||||||||||||
| 79 | : ( $value // 1 ) | ||||||||||||||||||||||||||||||||||||
| 80 | ; | ||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||
| 83 | $count | ||||||||||||||||||||||||||||||||||||
| 84 | 163 | ▶ | or return; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||
| 86 | 25 | splice @_, 0, $count; | |||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||
| 88 | 25 | ▶ | note "Extracted flags:\n", explain \%flagz | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 89 | if $found; | ||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||
| 91 | wantarray | ||||||||||||||||||||||||||||||||||||
| 92 | 25 | ▶ | ? %flagz | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 93 | : \%flagz | ||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||
| 96 | sub import_flags | ||||||||||||||||||||||||||||||||||||
| 97 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
import_flags: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 98 | 12 | %globalz = ( @defaultz, &extract_flags ); | |||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||
| 100 | # hand back the name to export. | ||||||||||||||||||||||||||||||||||||
| 101 | # remainder are left in the global settings. | ||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||
| 103 | delete $globalz{ export } | ||||||||||||||||||||||||||||||||||||
| 104 | 12 | } | |||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||
| 106 | ######################################################################## | ||||||||||||||||||||||||||||||||||||
| 107 | # execute individual tests | ||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||
| 109 | my $execute | ||||||||||||||||||||||||||||||||||||
| 110 | = sub | ||||||||||||||||||||||||||||||||||||
| 111 | 68 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.2
| |||||||||||||||||||||||||||||||||||||
| 112 | # note the lack of pass/fail: all this will do is report errors. | ||||||||||||||||||||||||||||||||||||
| 113 | # any pass/fail handling is dealt with in test_result. | ||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||
| 115 | 68 | state $r = []; | |||||||||||||||||||||||||||||||||||
| 116 | 68 | state $t0 = ''; | |||||||||||||||||||||||||||||||||||
| 117 | 68 | state $t1 = ''; | |||||||||||||||||||||||||||||||||||
| 118 | 68 | state $n = 0; | |||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||
| 120 | 68 | my ( $obj, $test ) = @_; | |||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||
| 122 | 68 | my ( $method, @argz ) = @$test; | |||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||
| 124 | # assume that "@$r =" is not significant in the benchmark. | ||||||||||||||||||||||||||||||||||||
| 125 | # also assume that nothing in gettimeofday will set $@. | ||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||
| 127 | 68 | @$r = (); | |||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||
| 129 | eval | ||||||||||||||||||||||||||||||||||||
| 130 | 68 | { | |||||||||||||||||||||||||||||||||||
| 131 | 68 | ▶ | $DB::single = 1 if $globalz{ break }; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||
| 133 | 68 | $t0 = [ gettimeofday ]; | |||||||||||||||||||||||||||||||||||
| 134 | 68 | @$r = $obj->$method( @argz ); | |||||||||||||||||||||||||||||||||||
| 135 | 64 | $t1 = [ gettimeofday ]; | |||||||||||||||||||||||||||||||||||
| 136 | }; | ||||||||||||||||||||||||||||||||||||
| 137 | 68 | chomp( my $error = $@ ); | |||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||
| 139 | 68 | ▶ | if( $globalz{ counter } ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 140 | { | ||||||||||||||||||||||||||||||||||||
| 141 | 0 | note 'Instruction: ' . ++$n; | |||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||
| 144 | 68 | ▶ | if( $globalz{ benchmark } ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||||||||||
| 146 | 14 | state $format = "Benchmark: %0.6f sec\t%s( %s )"; | |||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||
| 148 | 14 | my $wall = tv_interval $t0, $t1; | |||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||
| 150 | 14 | note sprintf $format => $wall, $method, explain @argz; | |||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||
| 153 | 68 | ▶ | if( $error ) | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 154 | { | ||||||||||||||||||||||||||||||||||||
| 155 | 4 | diag "Error: '$method'\n", explain $error; | |||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||
| 157 | elsif( $globalz{ verbose } ) | ||||||||||||||||||||||||||||||||||||
| 158 | { | ||||||||||||||||||||||||||||||||||||
| 159 | 2 | note "Clean: '$method'\n", explain $r; | |||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||
| 162 | 68 | ▶ | if( $error && $globalz{ debug } ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$error and $globalz{"debug"}
MC/DC0%0/2
$error and $globalz{"debug"}
$error
$globalz{"debug"}
Truth table66%2/3
A and B
A= $errorB= $globalz{"debug"}
| |||||||||||||||||||||||||||||||||||||
| 163 | { | ||||||||||||||||||||||||||||||||||||
| 164 | # stop here where the error is visible and the | ||||||||||||||||||||||||||||||||||||
| 165 | # test contents are still in scope. | ||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||
| 167 | 0 | $DB::single = 1; | |||||||||||||||||||||||||||||||||||
| 168 | 0 | 0 | |||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||
| 171 | 68 | ( $error, $r ) | |||||||||||||||||||||||||||||||||||
| 172 | 12 | }; | |||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||
| 174 | my $test_result | ||||||||||||||||||||||||||||||||||||
| 175 | = sub | ||||||||||||||||||||||||||||||||||||
| 176 | 68 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=11 SCAR=28.1
| |||||||||||||||||||||||||||||||||||||
| 177 | 68 | my ( $obj, $test, $expect, $message ) = @_; | |||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||
| 179 | 68 | my $method = $test->[0]; | |||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||
| 181 | 68 | my ( $error, $found ) = $obj->$execute( $test ); | |||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||
| 183 | 68 | ▶ | $message ||= "$method"; | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$message ||= "$method"
MC/DC0%0/2
$message ||= "$method"
$message
"$method"
Truth table66%2/3
A ||= B
A= $messageB= "$method"
| |||||||||||||||||||||||||||||||||||||
| 184 | 68 | ▶ | $message .= " ($error)" | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 185 | if $error; | ||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||
| 187 | 68 | for my $type ( reftype $expect ) | |||||||||||||||||||||||||||||||||||
| 188 | { | ||||||||||||||||||||||||||||||||||||
| 189 | 68 | ▶ | if( 'CODE' eq $type ) | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 190 | { | ||||||||||||||||||||||||||||||||||||
| 191 | 0 | ok $expect->( $test, $found, $error ), $message; | |||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||
| 193 | elsif( $expect ) | ||||||||||||||||||||||||||||||||||||
| 194 | { | ||||||||||||||||||||||||||||||||||||
| 195 | # this may pass if expect is [ undef ] but will | ||||||||||||||||||||||||||||||||||||
| 196 | # report the error text either way. | ||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||
| 198 | 64 | ▶ | if | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
not $type and $globalz{"regex"}
MC/DC0%0/2
not $type and $globalz{"regex"}
not $type
$globalz{"regex"}
Truth table33%1/3
not(A) and B
A= not $typeB= $globalz{"regex"}
| |||||||||||||||||||||||||||||||||||||
| 199 | ( | ||||||||||||||||||||||||||||||||||||
| 200 | ! $type | ||||||||||||||||||||||||||||||||||||
| 201 | and | ||||||||||||||||||||||||||||||||||||
| 202 | $globalz{ regex } | ||||||||||||||||||||||||||||||||||||
| 203 | ) | ||||||||||||||||||||||||||||||||||||
| 204 | { | ||||||||||||||||||||||||||||||||||||
| 205 | 0 | like "@$found", qr{$expect}x, $message; | |||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||
| 207 | elsif( 'REGEXP' eq $type ) | ||||||||||||||||||||||||||||||||||||
| 208 | { | ||||||||||||||||||||||||||||||||||||
| 209 | 0 | like "@$found", $expect, $message; | |||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||
| 211 | elsif( 'ARRAY' eq $type ) | ||||||||||||||||||||||||||||||||||||
| 212 | { | ||||||||||||||||||||||||||||||||||||
| 213 | 64 | is_deeply $found, $expect, $message; | |||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||
| 215 | else | ||||||||||||||||||||||||||||||||||||
| 216 | { | ||||||||||||||||||||||||||||||||||||
| 217 | 0 | BAIL_OUT | |||||||||||||||||||||||||||||||||||
| 218 | "Invalid expect: '$type'\n" . | ||||||||||||||||||||||||||||||||||||
| 219 | explain( $expect, $found, $message ); | ||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||
| 222 | elsif( $error ) | ||||||||||||||||||||||||||||||||||||
| 223 | { | ||||||||||||||||||||||||||||||||||||
| 224 | # explicit undef expects an error. | ||||||||||||||||||||||||||||||||||||
| 225 | # zero the string here to avoid rejecting the test | ||||||||||||||||||||||||||||||||||||
| 226 | # in the caller. | ||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||
| 228 | 4 | pass "Expected error: '$error'"; | |||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||
| 230 | 4 | $error = ''; | |||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||
| 232 | else | ||||||||||||||||||||||||||||||||||||
| 233 | { | ||||||||||||||||||||||||||||||||||||
| 234 | # expected error was not returned, this is a failure. | ||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||
| 236 | 0 | fail "Unexpected success: '$method' (no error)"; | |||||||||||||||||||||||||||||||||||
| 237 | 0 | diag "Return value:\n", explain $found; | |||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||
| 241 | # mainly useful as a boolean value in the caller. | ||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||
| 243 | $error | ||||||||||||||||||||||||||||||||||||
| 244 | 68 | }; | |||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||
| 246 | my $process | ||||||||||||||||||||||||||||||||||||
| 247 | = sub | ||||||||||||||||||||||||||||||||||||
| 248 | 68 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=21.8
| |||||||||||||||||||||||||||||||||||||
| 249 | 68 | my $obj = shift; | |||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||
| 251 | # flattened out test entry is left on the stack. | ||||||||||||||||||||||||||||||||||||
| 252 | # extract any local flags (e.g., verbose for one | ||||||||||||||||||||||||||||||||||||
| 253 | # test only). | ||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||
| 255 | 68 | my $localz = &extract_flags; | |||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||
| 257 | # trailing flags left nothing further to process. | ||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||
| 259 | 68 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 260 | { | ||||||||||||||||||||||||||||||||||||
| 261 | # sane | ||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||
| 263 | else | ||||||||||||||||||||||||||||||||||||
| 264 | { | ||||||||||||||||||||||||||||||||||||
| 265 | 0 | diag "Bogus test: contains only local flags\n", explain $localz; | |||||||||||||||||||||||||||||||||||
| 266 | return | ||||||||||||||||||||||||||||||||||||
| 267 | 0 | } | |||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||
| 269 | 68 | ▶ | local @globalz{ keys %$localz } = values %$localz | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 270 | if $localz; | ||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||
| 272 | # if there is no expect value then skip the ok check and just | ||||||||||||||||||||||||||||||||||||
| 273 | # run the method. | ||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||
| 275 | 68 | ▶ | my $handler | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 276 | = @_> 1 | ||||||||||||||||||||||||||||||||||||
| 277 | ? $test_result | ||||||||||||||||||||||||||||||||||||
| 278 | : $execute | ||||||||||||||||||||||||||||||||||||
| 279 | ; | ||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||
| 281 | 68 | ▶ | my $error = $obj->$handler( @_ ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 282 | or return; | ||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||
| 284 | $globalz{ continue } | ||||||||||||||||||||||||||||||||||||
| 285 | or | ||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | die "Error during processing (continue turned off)\n" . | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 287 | explain $error; | ||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||
| 289 | return | ||||||||||||||||||||||||||||||||||||
| 290 | 0 | }; | |||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||
| 292 | ######################################################################## | ||||||||||||||||||||||||||||||||||||
| 293 | # break up contents of exercise. | ||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||
| 295 | sub validate_plan | ||||||||||||||||||||||||||||||||||||
| 296 | 10 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
validate_plan: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 297 | # entrys are anything that gets run, expects have an | ||||||||||||||||||||||||||||||||||||
| 298 | # tests value and issue a pass/fail for the test. | ||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||
| 300 | 10 | my $entrys = 0; | |||||||||||||||||||||||||||||||||||
| 301 | 10 | my $tests = 0; | |||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||
| 303 | 10 | for my $fieldz ( @_ ) | |||||||||||||||||||||||||||||||||||
| 304 | { | ||||||||||||||||||||||||||||||||||||
| 305 | 80 | ▶ | ref $fieldz or next; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||
| 307 | 68 | my $n = $#$fieldz; | |||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||
| 309 | 68 | ▶ | my $i = first { ref $fieldz->[$_] } ( 0 .. $n ) | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Condition50%1/2
(0 .. $n) // (next)
MC/DC0%0/1
(0 .. $n) // (next)
(0 .. $n)
Truth table50%1/2
A
A= (0 .. $n)
| |||||||||||||||||||||||||||||||||||||
| 310 | // next; | ||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||
| 312 | 68 | ++$entrys; | |||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||
| 314 | 68 | ▶ | $n > $i # i.e., exists $entry->[ 1 + $i ] | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 315 | or next; | ||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||
| 317 | 17 | ++$tests; | |||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||
| 320 | $entrys | ||||||||||||||||||||||||||||||||||||
| 321 | or | ||||||||||||||||||||||||||||||||||||
| 322 | 10 | ▶ | BAIL_OUT 'Bogus exercise: no executable entry', explain \@_; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||
| 324 | note "Executing: $entrys entrys ($tests with tests)" | ||||||||||||||||||||||||||||||||||||
| 325 | 10 | ▶ | if $globalz{ verbose }; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||
| 327 | return | ||||||||||||||||||||||||||||||||||||
| 328 | 10 | } | |||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||
| 330 | sub prepare_tests | ||||||||||||||||||||||||||||||||||||
| 331 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_tests: called CC=10 SCAR=31.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 332 | 12 | ▶ | @_ or croak 'Bogus exercise: no tests on the stack'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||
| 334 | 12 | ▶ | if | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
1 == @_ and not ref $_[0]
MC/DC50%1/2
1 == @_ and not ref $_[0]
1 == @_
not ref $_[0]
Truth table66%2/3
A and not(B)
A= 1 == @_B= not ref $_[0]
| |||||||||||||||||||||||||||||||||||||
| 335 | ( | ||||||||||||||||||||||||||||||||||||
| 336 | 1 == @_ | ||||||||||||||||||||||||||||||||||||
| 337 | and | ||||||||||||||||||||||||||||||||||||
| 338 | ! ref $_[0] | ||||||||||||||||||||||||||||||||||||
| 339 | ) | ||||||||||||||||||||||||||||||||||||
| 340 | { | ||||||||||||||||||||||||||||||||||||
| 341 | 2 | ▶ | if | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
"finish" eq $_[0] or "nofinish" eq $_[0]
MC/DC0%0/2
"finish" eq $_[0] or "nofinish" eq $_[0]
"finish" eq $_[0]
"nofinish" eq $_[0]
Truth table66%2/3
A or B
A= "finish" eq $_[0]B= "nofinish" eq $_[0]
| |||||||||||||||||||||||||||||||||||||
| 342 | ( | ||||||||||||||||||||||||||||||||||||
| 343 | 'finish' eq $_[0] | ||||||||||||||||||||||||||||||||||||
| 344 | or | ||||||||||||||||||||||||||||||||||||
| 345 | 'nofinish' eq $_[0] | ||||||||||||||||||||||||||||||||||||
| 346 | ) | ||||||||||||||||||||||||||||||||||||
| 347 | { | ||||||||||||||||||||||||||||||||||||
| 348 | 2 | %globalz = ( %globalz, &extract_flags ); | |||||||||||||||||||||||||||||||||||
| 349 | return | ||||||||||||||||||||||||||||||||||||
| 350 | 2 | } | |||||||||||||||||||||||||||||||||||
| 351 | else | ||||||||||||||||||||||||||||||||||||
| 352 | { | ||||||||||||||||||||||||||||||||||||
| 353 | # anything else useful requires multiple | ||||||||||||||||||||||||||||||||||||
| 354 | # entries at this point: the input is YAML. | ||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||
| 356 | 0 | my $yaml = shift; | |||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||
| 358 | note "Non-ref test: assume YAML\n$yaml", | ||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||
| 360 | 0 | my $struct = eval { Load $yaml }; | |||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | BAIL_OUT "Invalid YAML: $@" | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 363 | if $@; | ||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | @$struct | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 366 | or BAIL_OUT "Invalid YAML: empty content\n", $yaml; | ||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||
| 368 | 0 | @_ = @$struct; | |||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||
| 372 | # extract any flags floating at the start and | ||||||||||||||||||||||||||||||||||||
| 373 | # leave the tests in place. | ||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||
| 375 | 10 | %globalz = ( %globalz, &extract_flags ); | |||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||
| 377 | # @_ will be empty at this point if there were only flags. | ||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||
| 379 | 10 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 380 | { | ||||||||||||||||||||||||||||||||||||
| 381 | # there is a plan on the stack | ||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||
| 383 | 10 | &validate_plan | |||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||
| 385 | elsif( $globalz{ finish } ) | ||||||||||||||||||||||||||||||||||||
| 386 | { | ||||||||||||||||||||||||||||||||||||
| 387 | 0 | croak | |||||||||||||||||||||||||||||||||||
| 388 | "Bogus plan: no tests and finish is true (missing 'nofinish'?)"; | ||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||
| 390 | else | ||||||||||||||||||||||||||||||||||||
| 391 | { | ||||||||||||||||||||||||||||||||||||
| 392 | # no plan, no finish => fine. | ||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||
| 395 | # at this point the first 'test' is at the head of the stack. | ||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||
| 397 | return | ||||||||||||||||||||||||||||||||||||
| 398 | 10 | } | |||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||
| 401 | ######################################################################## | ||||||||||||||||||||||||||||||||||||
| 402 | # interface pushed into caller via Object::Exercise | ||||||||||||||||||||||||||||||||||||
| 403 | ######################################################################## | ||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||
| 405 | sub exercise | ||||||||||||||||||||||||||||||||||||
| 406 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
exercise: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 407 | 12 | my $obj = shift; | |||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||
| 409 | # test seqeunce is left on the stack. | ||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||
| 411 | 12 | &prepare_tests; | |||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||
| 413 | # at this point the stack may be empty if the inputs were | ||||||||||||||||||||||||||||||||||||
| 414 | # flags (e.g., 'finish', or 'nofinish'). | ||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||
| 416 | 12 | ▶ | while( @_ ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 417 | { | ||||||||||||||||||||||||||||||||||||
| 418 | 71 | ▶ | if( my @flagz = &extract_flags ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 419 | { | ||||||||||||||||||||||||||||||||||||
| 420 | 3 | %globalz = ( %globalz, @flagz ); | |||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||
| 422 | next | ||||||||||||||||||||||||||||||||||||
| 423 | 3 | } | |||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||
| 425 | 68 | ▶ | if( my $entry = shift ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 426 | { | ||||||||||||||||||||||||||||||||||||
| 427 | 68 | $obj->$process( @$entry ); | |||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||
| 429 | else | ||||||||||||||||||||||||||||||||||||
| 430 | { | ||||||||||||||||||||||||||||||||||||
| 431 | 0 | croak "Bogus test: false entry ($entry)."; | |||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||
| 435 | done_testing | ||||||||||||||||||||||||||||||||||||
| 436 | 12 | ▶ | if $globalz{ finish }; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||
| 438 | return | ||||||||||||||||||||||||||||||||||||
| 439 | 12 | } | |||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||
| 441 | # keep require happy | ||||||||||||||||||||||||||||||||||||
| 442 | 12 | 1 | |||||||||||||||||||||||||||||||||||
| 443 | __END__ | ||||||||||||||||||||||||||||||||||||