line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Workflow; |
2
|
45
|
|
|
45
|
|
329
|
use strict; |
|
45
|
|
|
|
|
91
|
|
|
45
|
|
|
|
|
1804
|
|
3
|
45
|
|
|
45
|
|
234
|
use warnings; |
|
45
|
|
|
|
|
80
|
|
|
45
|
|
|
|
|
2301
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000156'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK = qw/parse_args current_build build root_build init_root build_stack/; |
8
|
45
|
|
|
45
|
|
244
|
use base 'Exporter'; |
|
45
|
|
|
|
|
91
|
|
|
45
|
|
|
|
|
4411
|
|
9
|
|
|
|
|
|
|
|
10
|
45
|
|
|
45
|
|
18421
|
use Test2::Workflow::Build; |
|
45
|
|
|
|
|
175
|
|
|
45
|
|
|
|
|
1244
|
|
11
|
45
|
|
|
45
|
|
385
|
use Test2::Workflow::Task::Group; |
|
45
|
|
|
|
|
107
|
|
|
45
|
|
|
|
|
883
|
|
12
|
45
|
|
|
45
|
|
219
|
use Test2::API qw/intercept/; |
|
45
|
|
|
|
|
95
|
|
|
45
|
|
|
|
|
2180
|
|
13
|
45
|
|
|
45
|
|
257
|
use Scalar::Util qw/blessed/; |
|
45
|
|
|
|
|
136
|
|
|
45
|
|
|
|
|
40890
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub parse_args { |
16
|
739
|
|
|
739
|
1
|
2168
|
my %input = @_; |
17
|
739
|
|
|
|
|
1442
|
my $args = delete $input{args}; |
18
|
739
|
|
|
|
|
1176
|
my %out; |
19
|
|
|
|
|
|
|
my %props; |
20
|
|
|
|
|
|
|
|
21
|
739
|
|
33
|
|
|
2195
|
my $caller = $out{frame} = $input{caller} || caller(defined $input{level} ? $input{level} : 1); |
22
|
739
|
|
|
|
|
1551
|
delete @input{qw/caller level/}; |
23
|
|
|
|
|
|
|
|
24
|
739
|
|
|
|
|
1359
|
for my $arg (@$args) { |
25
|
1702
|
100
|
|
|
|
3511
|
if (my $r = ref($arg)) { |
26
|
963
|
100
|
|
|
|
2308
|
if ($r eq 'HASH') { |
|
|
50
|
|
|
|
|
|
27
|
224
|
|
|
|
|
840
|
%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
|
|
|
|
1557
|
if $out{code}; |
32
|
|
|
|
|
|
|
|
33
|
739
|
|
|
|
|
1187
|
$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
|
|
|
|
|
1733
|
next; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
739
|
50
|
|
|
|
2550
|
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
|
|
|
|
1343
|
if $out{name}; |
48
|
|
|
|
|
|
|
|
49
|
739
|
|
|
|
|
1540
|
$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
|
|
|
|
1507
|
unless $out{name}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
die "a codeblock must be provided at $caller->[1] line $caller->[2].\n" |
56
|
739
|
50
|
|
|
|
1478
|
unless $out{code}; |
57
|
|
|
|
|
|
|
|
58
|
739
|
|
|
|
|
4002
|
return { %props, %out, %input }; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
{ |
62
|
|
|
|
|
|
|
my %ROOT_BUILDS; |
63
|
|
|
|
|
|
|
my @BUILD_STACK; |
64
|
|
|
|
|
|
|
|
65
|
841
|
|
|
841
|
1
|
2466
|
sub root_build { $ROOT_BUILDS{$_[0]} } |
66
|
730
|
100
|
|
730
|
1
|
3831
|
sub current_build { @BUILD_STACK ? $BUILD_STACK[-1] : undef } |
67
|
646
|
|
|
646
|
0
|
1336
|
sub build_stack { @BUILD_STACK } |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub init_root { |
70
|
43
|
|
|
43
|
1
|
203
|
my ($pkg, %args) = @_; |
71
|
43
|
|
33
|
|
|
845
|
$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
|
|
|
|
|
360
|
return $ROOT_BUILDS{$pkg}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub build { |
84
|
92
|
|
|
92
|
1
|
402
|
my %params = @_; |
85
|
92
|
|
|
|
|
339
|
my $args = parse_args(%params); |
86
|
|
|
|
|
|
|
|
87
|
92
|
|
|
|
|
804
|
my $build = Test2::Workflow::Build->new(%$args); |
88
|
|
|
|
|
|
|
|
89
|
92
|
100
|
|
|
|
521
|
return $build if $args->{skip}; |
90
|
|
|
|
|
|
|
|
91
|
87
|
|
|
|
|
175
|
push @BUILD_STACK => $build; |
92
|
|
|
|
|
|
|
|
93
|
87
|
|
|
|
|
139
|
my ($ok, $err); |
94
|
|
|
|
|
|
|
my $events = intercept { |
95
|
87
|
100
|
|
87
|
|
91269
|
my $todo = $args->{todo} ? Test2::Todo->new(reason => $args->{todo}) : undef; |
96
|
87
|
|
|
|
|
278
|
$ok = eval { $args->{code}->(); 1 }; |
|
87
|
|
|
|
|
279
|
|
|
82
|
|
|
|
|
269
|
|
97
|
87
|
|
|
|
|
269
|
$err = $@; |
98
|
87
|
100
|
|
|
|
352
|
$todo->end if $todo; |
99
|
87
|
|
|
|
|
814
|
}; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Clear the stash |
102
|
87
|
|
|
|
|
706113
|
$build->{stash} = []; |
103
|
87
|
|
|
|
|
407
|
$build->set_events($events); |
104
|
|
|
|
|
|
|
|
105
|
87
|
|
|
|
|
385
|
pop @BUILD_STACK; |
106
|
|
|
|
|
|
|
|
107
|
87
|
100
|
|
|
|
285
|
unless($ok) { |
108
|
5
|
|
|
|
|
15
|
my $hub = Test2::API::test2_stack->top; |
109
|
5
|
|
|
|
|
55
|
my $count = @$events; |
110
|
5
|
50
|
|
|
|
70
|
my $list = $count |
111
|
|
|
|
|
|
|
? "Overview of unseen events:\n" . join "" => map " " . blessed($_) . " " . $_->trace($hub)->debug . "\n", @$events |
112
|
|
|
|
|
|
|
: ""; |
113
|
5
|
|
|
|
|
370
|
die <<" EOT"; |
114
|
|
|
|
|
|
|
Exception in build '$args->{name}' with $count unseen event(s). |
115
|
|
|
|
|
|
|
$err |
116
|
|
|
|
|
|
|
$list |
117
|
|
|
|
|
|
|
EOT |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
82
|
|
|
|
|
426
|
return $build; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |