| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Test::Workflow::Test; | 
| 2 | 137 |  |  | 137 |  | 726 | use strict; | 
|  | 137 |  |  |  |  | 246 |  | 
|  | 137 |  |  |  |  | 3033 |  | 
| 3 | 137 |  |  | 137 |  | 535 | use warnings; | 
|  | 137 |  |  |  |  | 214 |  | 
|  | 137 |  |  |  |  | 2987 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 137 |  |  | 137 |  | 625 | use Fennec::Util qw/accessors/; | 
|  | 137 |  |  |  |  | 237 |  | 
|  | 137 |  |  |  |  | 647 |  | 
| 6 | 137 |  |  | 137 |  | 26774 | use List::Util qw/shuffle/; | 
|  | 137 |  |  |  |  | 238 |  | 
|  | 137 |  |  |  |  | 9953 |  | 
| 7 | 137 |  |  | 137 |  | 708 | use Carp qw/cluck/; | 
|  | 137 |  |  |  |  | 363 |  | 
|  | 137 |  |  |  |  | 95892 |  | 
| 8 |  |  |  |  |  |  | require Time::HiRes; | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | accessors qw/setup tests teardown around block_name is_wrap control/; | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | sub new { | 
| 13 | 891 |  |  | 891 | 0 | 1218 | my $class  = shift; | 
| 14 | 891 |  |  |  |  | 2705 | my %params = @_; | 
| 15 |  |  |  |  |  |  | return bless( | 
| 16 |  |  |  |  |  |  | { | 
| 17 |  |  |  |  |  |  | setup      => $params{setup}      || [], | 
| 18 |  |  |  |  |  |  | tests      => $params{tests}      || [], | 
| 19 |  |  |  |  |  |  | teardown   => $params{teardown}   || [], | 
| 20 |  |  |  |  |  |  | around     => $params{around}     || [], | 
| 21 |  |  |  |  |  |  | control    => $params{control}    || [], | 
| 22 |  |  |  |  |  |  | block_name => $params{block_name} || "", | 
| 23 | 891 |  | 50 |  |  | 9098 | is_wrap    => $params{is_wrap}    || 0, | 
|  |  |  | 50 |  |  |  |  | 
|  |  |  | 50 |  |  |  |  | 
|  |  |  | 50 |  |  |  |  | 
|  |  |  | 50 |  |  |  |  | 
|  |  |  | 50 |  |  |  |  | 
|  |  |  | 100 |  |  |  |  | 
| 24 |  |  |  |  |  |  | }, | 
| 25 |  |  |  |  |  |  | $class | 
| 26 |  |  |  |  |  |  | ); | 
| 27 |  |  |  |  |  |  | } | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | sub name { | 
| 30 | 174 |  |  | 174 | 0 | 186 | my $self = shift; | 
| 31 |  |  |  |  |  |  | return $self->tests->[0]->name | 
| 32 | 174 | 100 |  |  |  | 163 | if @{$self->tests} == 1; | 
|  | 174 |  |  |  |  | 231 |  | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 21 |  |  |  |  | 41 | return $self->block_name; | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | sub run { | 
| 38 | 621 |  |  | 621 | 0 | 280768 | my $self = shift; | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 621 |  |  |  |  | 1830 | my ($instance) = @_; | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 621 |  |  |  |  | 3850 | my $run       = $self->_wrap_tests($instance); | 
| 43 | 621 |  |  |  |  | 2255 | my $prunner   = $instance->TEST_WORKFLOW->test_run; | 
| 44 | 621 |  |  |  |  | 984 | my $testcount = @{$self->tests}; | 
|  | 621 |  |  |  |  | 1541 |  | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 621 | 100 |  |  |  | 1972 | return $run->() if $self->is_wrap; | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 539 | 100 | 66 |  |  | 5064 | return $prunner->( $run, $self, $instance ) | 
| 49 |  |  |  |  |  |  | if $prunner && $testcount == 1; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 13 |  |  |  |  | 18 | $run->(); | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | sub _wrap_tests { | 
| 55 | 621 |  |  | 621 |  | 1274 | my $self = shift; | 
| 56 | 621 |  |  |  |  | 1179 | my ($instance) = @_; | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 621 |  |  |  |  | 3549 | my $ref = ref $self; | 
| 59 | 621 |  |  |  |  | 9738 | $ref =~ s/^.*:://; | 
| 60 |  |  |  |  |  |  |  | 
| 61 | 621 |  |  |  |  | 6952 | my $meta = $instance->TEST_WORKFLOW; | 
| 62 |  |  |  |  |  |  |  | 
| 63 | 621 |  | 100 |  |  | 5116 | my $sort = $meta->test_sort || 'rand'; | 
| 64 | 621 |  |  |  |  | 1397 | my @tests = Test::Workflow::order_tests( $sort, @{$self->tests} ); | 
|  | 621 |  |  |  |  | 2387 |  | 
| 65 |  |  |  |  |  |  |  | 
| 66 | 621 |  |  |  |  | 4722 | my $wait = $meta->test_wait; | 
| 67 | 621 |  |  |  |  | 4754 | my $pid  = $$; | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 621 |  | 66 |  |  | 9454 | my $debug = $instance->can('FENNEC') && $instance->FENNEC->debug; | 
| 70 | 621 | 50 |  |  |  | 1671 | my $collector = $debug ? Fennec::Runner->new->collector : undef; | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | return sub { | 
| 73 | 268 |  |  | 268 |  | 1834 | my $control_store = []; | 
| 74 | 268 |  |  |  |  | 3880 | $meta->control_store($control_store); | 
| 75 | 268 |  |  |  |  | 558 | for my $sub (@{$self->control}) { | 
|  | 268 |  |  |  |  | 2845 |  | 
| 76 | 10 |  |  |  |  | 226 | my $control = $sub->(); | 
| 77 | 10 | 50 |  |  |  | 8719 | if ($debug) { | 
| 78 | 0 |  |  |  |  | 0 | my ($sec, $ms) = Time::HiRes::gettimeofday(); | 
| 79 |  |  |  |  |  |  | my $msg = sprintf( | 
| 80 |  |  |  |  |  |  | "FENNEC_DEBUG_MOCK:PID:%d\0CLASS:%s\0SEC:%d\0MSEC:%d\0OVERRIDES:%s\n", | 
| 81 |  |  |  |  |  |  | $$, | 
| 82 |  |  |  |  |  |  | $control->package, | 
| 83 |  |  |  |  |  |  | $sec, | 
| 84 |  |  |  |  |  |  | $ms, | 
| 85 | 0 |  |  |  |  | 0 | join ' ' => grep { /^\w/ } keys %$control | 
|  | 0 |  |  |  |  | 0 |  | 
| 86 |  |  |  |  |  |  | ); | 
| 87 | 0 |  |  |  |  | 0 | $collector->diag($msg); | 
| 88 |  |  |  |  |  |  | } | 
| 89 | 10 |  |  |  |  | 58 | push @$control_store => $control; | 
| 90 |  |  |  |  |  |  | } | 
| 91 |  |  |  |  |  |  |  | 
| 92 | 268 | 100 | 66 |  |  | 8978 | $wait->() if $wait && $self->can('is_wrap') && $self->is_wrap; | 
|  |  |  | 100 |  |  |  |  | 
| 93 |  |  |  |  |  |  |  | 
| 94 | 268 |  |  |  |  | 3995 | $_->run($instance) for @{$self->setup}; | 
|  | 268 |  |  |  |  | 1914 |  | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | my $base = sub { | 
| 97 | 258 |  |  |  |  | 1065 | for my $test (@tests) { | 
| 98 | 369 |  |  |  |  | 123974 | $test->run($instance); | 
| 99 |  |  |  |  |  |  | } | 
| 100 | 268 |  |  |  |  | 3402 | }; | 
| 101 |  |  |  |  |  |  |  | 
| 102 | 268 |  |  |  |  | 1165 | my $outer = $base; | 
| 103 | 268 |  |  |  |  | 791 | for my $around ( @{$self->around} ) { | 
|  | 268 |  |  |  |  | 1569 |  | 
| 104 | 31 |  |  |  |  | 81 | my $inner = $outer; | 
| 105 | 31 |  |  |  |  | 229 | $outer = sub { $around->run( $instance, $inner ) }; | 
|  | 31 |  |  |  |  | 722 |  | 
| 106 |  |  |  |  |  |  | } | 
| 107 |  |  |  |  |  |  |  | 
| 108 | 268 |  |  |  |  | 1300 | $outer->(); | 
| 109 |  |  |  |  |  |  |  | 
| 110 | 230 |  |  |  |  | 18247 | $_->run($instance) for @{$self->teardown}; | 
|  | 230 |  |  |  |  | 1553 |  | 
| 111 |  |  |  |  |  |  |  | 
| 112 | 230 |  |  |  |  | 1491 | $meta->control_store(undef); | 
| 113 | 230 |  |  |  |  | 840 | $control_store = undef; | 
| 114 |  |  |  |  |  |  |  | 
| 115 | 230 | 100 | 66 |  |  | 5743 | $wait->() if $wait && $self->can('is_wrap') && $self->is_wrap; | 
|  |  |  | 100 |  |  |  |  | 
| 116 | 621 |  |  |  |  | 6415 | }; | 
| 117 |  |  |  |  |  |  | } | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | 1; | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | __END__ |