| 1 | package Test2::Tools::Defer; | ||||||||||||
| 2 | 163 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 163 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 163 | our $VERSION = '1.302226'; | |||||||||||
| 6 | |||||||||||||
| 7 | 163 | ▶ | use Carp qw/croak/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 163 | ▶ | use Test2::Util qw/get_tid/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 163 | ▶ | use Test2::API qw{ | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | test2_add_callback_exit | ||||||||||||
| 12 | test2_pid test2_tid | ||||||||||||
| 13 | 163 | }; | |||||||||||
| 14 | |||||||||||||
| 15 | 163 | our @EXPORT = qw/def do_def/; | |||||||||||
| 16 | 163 | ▶ | use base 'Exporter'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | |||||||||||||
| 18 | 163 | my %TODO; | |||||||||||
| 19 | |||||||||||||
| 20 | 54 | ▶ | sub def { | ||||||||||
|
Subroutine
def: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 21 | 54 | my ($func, @args) = @_; | |||||||||||
| 22 | |||||||||||||
| 23 | 54 | my @caller = caller(0); | |||||||||||
| 24 | |||||||||||||
| 25 | 54 | ▶ | $TODO{$caller[0]} ||= []; | ||||||||||
|
Condition100%2/2
$TODO{$caller[0]} ||= []
MC/DC100%1/1
$TODO{$caller[0]} ||= []
$TODO{$caller[0]}
Truth table100%2/2
A
A= $TODO{$caller[0]}
| |||||||||||||
| 26 | 54 | push @{$TODO{$caller[0]}} => [$func, \@args, \@caller]; | |||||||||||
| 27 | } | ||||||||||||
| 28 | |||||||||||||
| 29 | 11 | ▶ | sub do_def { | ||||||||||
|
Subroutine
do_def: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 30 | 11 | my $for = caller; | |||||||||||
| 31 | 11 | ▶ | my $tests = delete $TODO{$for} or croak "No tests to run!"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 32 | |||||||||||||
| 33 | 10 | for my $test (@$tests) { | |||||||||||
| 34 | 51 | my ($func, $args, $caller) = @$test; | |||||||||||
| 35 | |||||||||||||
| 36 | 51 | my ($pkg, $file, $line) = @$caller; | |||||||||||
| 37 | |||||||||||||
| 38 | 51 | chomp(my $eval = <<" EOT"); | |||||||||||
| 39 | package $pkg; | ||||||||||||
| 40 | # line $line "(eval in Test2::Tools::Defer) $file" | ||||||||||||
| 41 | \&$func(\@\$args); | ||||||||||||
| 42 | 1; | ||||||||||||
| 43 | EOT | ||||||||||||
| 44 | |||||||||||||
| 45 | 51 | ▶ | eval $eval and next; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | 1 | chomp(my $error = $@); | |||||||||||
| 47 | |||||||||||||
| 48 | 1 | require Data::Dumper; | |||||||||||
| 49 | 1 | chomp(my $td = Data::Dumper::Dumper($args)); | |||||||||||
| 50 | 1 | $td =~ s/^\$VAR1 =/\$args: /; | |||||||||||
| 51 | 1 | die <<" EOT"; | |||||||||||
| 52 | Exception: $error | ||||||||||||
| 53 | --eval-- | ||||||||||||
| 54 | $eval | ||||||||||||
| 55 | -------- | ||||||||||||
| 56 | Tool: $func | ||||||||||||
| 57 | Caller: $caller->[0], $caller->[1], $caller->[2] | ||||||||||||
| 58 | $td | ||||||||||||
| 59 | EOT | ||||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | 9 | return; | |||||||||||
| 63 | } | ||||||||||||
| 64 | |||||||||||||
| 65 | 119 | ▶ | sub _verify { | ||||||||||
|
Subroutine
_verify: called CC=4 SCAR=13.9
| |||||||||||||
| 66 | 119 | my ($context, $exit, $new_exit) = @_; | |||||||||||
| 67 | |||||||||||||
| 68 | 119 | my $not_ok = 0; | |||||||||||
| 69 | 119 | for my $pkg (keys %TODO) { | |||||||||||
| 70 | 3 | my $tests = delete $TODO{$pkg}; | |||||||||||
| 71 | 3 | my $caller = $tests->[0]->[-1]; | |||||||||||
| 72 | 3 | ▶ | print STDOUT "not ok - deferred tests were not run!\n" unless $not_ok++; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 73 | 3 | print STDERR "# '$pkg' has deferred tests that were never run!\n"; | |||||||||||
| 74 | 3 | print STDERR "# $caller->[1] at line $caller->[2]\n"; | |||||||||||
| 75 | 3 | ▶ | $$new_exit ||= 255; | ||||||||||
|
Condition100%2/2
$$new_exit ||= 255
MC/DC100%1/1
$$new_exit ||= 255
$$new_exit
Truth table100%2/2
A
A= $$new_exit
| |||||||||||||
| 76 | } | ||||||||||||
| 77 | } | ||||||||||||
| 78 | |||||||||||||
| 79 | 163 | test2_add_callback_exit(\&_verify); | |||||||||||
| 80 | |||||||||||||
| 81 | 163 | 1; | |||||||||||
| 82 | |||||||||||||
| 83 | __END__ | ||||||||||||