line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Workflow; |
2
|
45
|
|
|
45
|
|
280
|
use strict; |
|
45
|
|
|
|
|
82
|
|
|
45
|
|
|
|
|
1255
|
|
3
|
45
|
|
|
45
|
|
314
|
use warnings; |
|
45
|
|
|
|
|
197
|
|
|
45
|
|
|
|
|
2380
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000155'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK = qw/parse_args current_build build root_build init_root build_stack/; |
8
|
45
|
|
|
45
|
|
255
|
use base 'Exporter'; |
|
45
|
|
|
|
|
80
|
|
|
45
|
|
|
|
|
4714
|
|
9
|
|
|
|
|
|
|
|
10
|
45
|
|
|
45
|
|
18359
|
use Test2::Workflow::Build; |
|
45
|
|
|
|
|
128
|
|
|
45
|
|
|
|
|
1387
|
|
11
|
45
|
|
|
45
|
|
310
|
use Test2::Workflow::Task::Group; |
|
45
|
|
|
|
|
93
|
|
|
45
|
|
|
|
|
893
|
|
12
|
45
|
|
|
45
|
|
212
|
use Test2::API qw/intercept/; |
|
45
|
|
|
|
|
91
|
|
|
45
|
|
|
|
|
2385
|
|
13
|
45
|
|
|
45
|
|
262
|
use Scalar::Util qw/blessed/; |
|
45
|
|
|
|
|
110
|
|
|
45
|
|
|
|
|
40136
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub parse_args { |
16
|
739
|
|
|
739
|
1
|
2198
|
my %input = @_; |
17
|
739
|
|
|
|
|
1590
|
my $args = delete $input{args}; |
18
|
739
|
|
|
|
|
1307
|
my %out; |
19
|
|
|
|
|
|
|
my %props; |
20
|
|
|
|
|
|
|
|
21
|
739
|
|
33
|
|
|
2206
|
my $caller = $out{frame} = $input{caller} || caller(defined $input{level} ? $input{level} : 1); |
22
|
739
|
|
|
|
|
1595
|
delete @input{qw/caller level/}; |
23
|
|
|
|
|
|
|
|
24
|
739
|
|
|
|
|
1512
|
for my $arg (@$args) { |
25
|
1702
|
100
|
|
|
|
3859
|
if (my $r = ref($arg)) { |
26
|
963
|
100
|
|
|
|
2464
|
if ($r eq 'HASH') { |
|
|
50
|
|
|
|
|
|
27
|
224
|
|
|
|
|
981
|
%props = (%props, %$arg); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
elsif ($r eq 'CODE') { |
30
|
|
|
|
|
|
|
die "Code is already set, did you provide multiple code blocks at $caller->[1] line $caller->[2].\n" |
31
|
739
|
50
|
|
|
|
1590
|
if $out{code}; |
32
|
|
|
|
|
|
|
|
33
|
739
|
|
|
|
|
1467
|
$out{code} = $arg |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
0
|
|
|
|
|
0
|
die "Not sure what to do with $arg at $caller->[1] line $caller->[2].\n"; |
37
|
|
|
|
|
|
|
} |
38
|
963
|
|
|
|
|
1972
|
next; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
739
|
50
|
|
|
|
2830
|
if ($arg =~ m/^\d+$/) { |
42
|
0
|
|
|
|
|
0
|
push @{$out{lines}} => $arg; |
|
0
|
|
|
|
|
0
|
|
43
|
0
|
|
|
|
|
0
|
next; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
die "Name is already set to '$out{name}', cannot set to '$arg', did you specify multiple names at $caller->[1] line $caller->[2].\n" |
47
|
739
|
50
|
|
|
|
1623
|
if $out{name}; |
48
|
|
|
|
|
|
|
|
49
|
739
|
|
|
|
|
1582
|
$out{name} = $arg; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
die "a name must be provided, and must be truthy at $caller->[1] line $caller->[2].\n" |
53
|
739
|
50
|
|
|
|
1563
|
unless $out{name}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
die "a codeblock must be provided at $caller->[1] line $caller->[2].\n" |
56
|
739
|
50
|
|
|
|
1494
|
unless $out{code}; |
57
|
|
|
|
|
|
|
|
58
|
739
|
|
|
|
|
3943
|
return { %props, %out, %input }; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
{ |
62
|
|
|
|
|
|
|
my %ROOT_BUILDS; |
63
|
|
|
|
|
|
|
my @BUILD_STACK; |
64
|
|
|
|
|
|
|
|
65
|
841
|
|
|
841
|
1
|
2559
|
sub root_build { $ROOT_BUILDS{$_[0]} } |
66
|
730
|
100
|
|
730
|
1
|
4212
|
sub current_build { @BUILD_STACK ? $BUILD_STACK[-1] : undef } |
67
|
646
|
|
|
646
|
0
|
1435
|
sub build_stack { @BUILD_STACK } |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub init_root { |
70
|
43
|
|
|
43
|
1
|
180
|
my ($pkg, %args) = @_; |
71
|
43
|
|
33
|
|
|
757
|
$ROOT_BUILDS{$pkg} ||= Test2::Workflow::Build->new( |
72
|
|
|
|
|
|
|
name => $pkg, |
73
|
|
|
|
|
|
|
flat => 1, |
74
|
|
|
|
|
|
|
iso => 0, |
75
|
|
|
|
|
|
|
async => 0, |
76
|
|
|
|
|
|
|
is_root => 1, |
77
|
|
|
|
|
|
|
%args, |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
43
|
|
|
|
|
325
|
return $ROOT_BUILDS{$pkg}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub build { |
84
|
92
|
|
|
92
|
1
|
382
|
my %params = @_; |
85
|
92
|
|
|
|
|
456
|
my $args = parse_args(%params); |
86
|
|
|
|
|
|
|
|
87
|
92
|
|
|
|
|
1017
|
my $build = Test2::Workflow::Build->new(%$args); |
88
|
|
|
|
|
|
|
|
89
|
92
|
100
|
|
|
|
631
|
return $build if $args->{skip}; |
90
|
|
|
|
|
|
|
|
91
|
87
|
|
|
|
|
234
|
push @BUILD_STACK => $build; |
92
|
|
|
|
|
|
|
|
93
|
87
|
|
|
|
|
189
|
my ($ok, $err); |
94
|
|
|
|
|
|
|
my $events = intercept { |
95
|
87
|
100
|
|
87
|
|
99987
|
my $todo = $args->{todo} ? Test2::Todo->new(reason => $args->{todo}) : undef; |
96
|
87
|
|
|
|
|
298
|
$ok = eval { $args->{code}->(); 1 }; |
|
87
|
|
|
|
|
318
|
|
|
82
|
|
|
|
|
261
|
|
97
|
87
|
|
|
|
|
305
|
$err = $@; |
98
|
87
|
100
|
|
|
|
316
|
$todo->end if $todo; |
99
|
87
|
|
|
|
|
878
|
}; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Clear the stash |
102
|
87
|
|
|
|
|
335774
|
$build->{stash} = []; |
103
|
87
|
|
|
|
|
487
|
$build->set_events($events); |
104
|
|
|
|
|
|
|
|
105
|
87
|
|
|
|
|
418
|
pop @BUILD_STACK; |
106
|
|
|
|
|
|
|
|
107
|
87
|
100
|
|
|
|
279
|
unless($ok) { |
108
|
5
|
|
|
|
|
170
|
my $hub = Test2::API::test2_stack->top; |
109
|
5
|
|
|
|
|
155
|
my $count = @$events; |
110
|
5
|
50
|
|
|
|
85
|
my $list = $count |
111
|
|
|
|
|
|
|
? "Overview of unseen events:\n" . join "" => map " " . blessed($_) . " " . $_->trace($hub)->debug . "\n", @$events |
112
|
|
|
|
|
|
|
: ""; |
113
|
5
|
|
|
|
|
545
|
die <<" EOT"; |
114
|
|
|
|
|
|
|
Exception in build '$args->{name}' with $count unseen event(s). |
115
|
|
|
|
|
|
|
$err |
116
|
|
|
|
|
|
|
$list |
117
|
|
|
|
|
|
|
EOT |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
82
|
|
|
|
|
378
|
return $build; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |