| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Test::Perinci::Sub::Wrapper; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-07-04'; # DATE |
|
4
|
|
|
|
|
|
|
our $VERSION = '0.851'; # VERSION |
|
5
|
|
|
|
|
|
|
|
|
6
|
17
|
|
|
17
|
|
1857387
|
use 5.010; |
|
|
17
|
|
|
|
|
90
|
|
|
7
|
17
|
|
|
17
|
|
91
|
use strict; |
|
|
17
|
|
|
|
|
224
|
|
|
|
17
|
|
|
|
|
265
|
|
|
8
|
17
|
|
|
15
|
|
1482
|
use warnings; |
|
|
15
|
|
|
|
|
122
|
|
|
|
15
|
|
|
|
|
401
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
15
|
|
|
15
|
|
5536
|
use Function::Fallback::CoreOrPP qw(clone); |
|
|
15
|
|
|
|
|
7939
|
|
|
|
15
|
|
|
|
|
735
|
|
|
11
|
|
|
|
|
|
|
#use List::Util qw(shuffle); |
|
12
|
15
|
|
|
15
|
|
7519
|
use Perinci::Sub::Wrapper qw(wrap_sub); |
|
|
15
|
|
|
|
|
132
|
|
|
|
15
|
|
|
|
|
866
|
|
|
13
|
15
|
|
|
15
|
|
427
|
use Test::More 0.96; |
|
|
15
|
|
|
|
|
374
|
|
|
|
15
|
|
|
|
|
94
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw(test_wrap); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub test_wrap { |
|
19
|
59
|
|
|
59
|
0
|
179792
|
my %test_args = @_; |
|
20
|
59
|
50
|
|
|
|
312
|
$test_args{wrap_args} or die "BUG: wrap_args not defined"; |
|
21
|
59
|
50
|
|
|
|
207
|
my $test_name = $test_args{name} or die "BUG: test_name not defined"; |
|
22
|
|
|
|
|
|
|
|
|
23
|
59
|
|
|
|
|
546
|
for my $wrapper_type (qw/dynamic embed/) { |
|
24
|
116
|
100
|
100
|
|
|
156456
|
next if $wrapper_type eq 'dynamic' && $test_args{skip_dynamic}; |
|
25
|
115
|
100
|
100
|
|
|
576
|
next if $wrapper_type eq 'embed' && $test_args{skip_embed}; |
|
26
|
|
|
|
|
|
|
subtest "$test_name ($wrapper_type)" => sub { |
|
27
|
|
|
|
|
|
|
|
|
28
|
114
|
50
|
|
114
|
|
110562
|
if ($test_args{pretest}) { |
|
29
|
2
|
|
|
|
|
4
|
$test_args{pretest}->(); |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
114
|
|
|
|
|
549
|
my $wrap_args = clone($test_args{wrap_args}); |
|
33
|
|
|
|
|
|
|
die "BUG: embed must not be specified in wrap_args, test_wrap() ". |
|
34
|
|
|
|
|
|
|
"will always test dynamic (embed=0) *and* embed mode" |
|
35
|
114
|
50
|
|
|
|
22297
|
if exists $wrap_args->{embed}; |
|
36
|
114
|
100
|
|
|
|
357
|
if ($wrapper_type eq 'embed') { |
|
37
|
58
|
|
|
|
|
571
|
$wrap_args->{embed} = 1; |
|
38
|
|
|
|
|
|
|
#diag explain $wrap_args->{meta}; |
|
39
|
|
|
|
|
|
|
} else { |
|
40
|
57
|
|
|
|
|
239
|
$wrap_args->{embed} = 0; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
113
|
|
|
|
|
195
|
my $wrap_res; |
|
44
|
113
|
|
|
|
|
564
|
eval { $wrap_res = wrap_sub(%$wrap_args) }; |
|
|
113
|
|
|
|
|
590
|
|
|
45
|
113
|
|
|
|
|
34726
|
my $wrap_eval_err = $@; |
|
46
|
113
|
100
|
|
|
|
445
|
if ($test_args{wrap_dies}) { |
|
47
|
9
|
|
|
|
|
120
|
ok($wrap_eval_err, "wrap dies"); |
|
48
|
9
|
|
|
|
|
3881
|
return; |
|
49
|
|
|
|
|
|
|
} else { |
|
50
|
105
|
50
|
|
|
|
857
|
ok(!$wrap_eval_err, "wrap doesn't die") or do { |
|
51
|
1
|
|
|
|
|
6
|
diag $wrap_eval_err; |
|
52
|
1
|
|
|
|
|
2
|
return; |
|
53
|
|
|
|
|
|
|
}; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
105
|
100
|
|
|
|
50493
|
if (defined $test_args{wrap_status}) { |
|
57
|
27
|
|
|
|
|
236
|
is(ref($wrap_res), 'ARRAY', 'wrap res is array'); |
|
58
|
|
|
|
|
|
|
is($wrap_res->[0], $test_args{wrap_status}, |
|
59
|
27
|
50
|
|
|
|
10135
|
"wrap status is $test_args{wrap_status}") |
|
60
|
|
|
|
|
|
|
or diag "wrap res: ", explain($wrap_res); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
105
|
50
|
|
|
|
10424
|
return unless $wrap_res->[0] == 200; |
|
64
|
|
|
|
|
|
|
|
|
65
|
105
|
|
|
|
|
194
|
my $sub; |
|
66
|
105
|
100
|
|
|
|
319
|
if ($wrapper_type eq 'embed') { |
|
67
|
53
|
|
|
|
|
159
|
my $src = $wrap_res->[2]{source}; |
|
68
|
53
|
|
|
|
|
216
|
my $meta = $wrap_res->[2]{meta}; |
|
69
|
53
|
|
|
|
|
122
|
my $args_as = $meta->{args_as}; |
|
70
|
53
|
|
100
|
|
|
609
|
my $orig_args_as = $wrap_args->{meta}{args_as} // 'hash'; |
|
71
|
53
|
|
|
|
|
123
|
my $sub_name = $wrap_res->[2]{sub_name}; |
|
72
|
|
|
|
|
|
|
my $eval_src = join( |
|
73
|
|
|
|
|
|
|
"\n", |
|
74
|
|
|
|
|
|
|
$src->{presub1}, |
|
75
|
|
|
|
|
|
|
$src->{presub2}, |
|
76
|
|
|
|
|
|
|
'sub {', |
|
77
|
|
|
|
|
|
|
' my %args;', |
|
78
|
|
|
|
|
|
|
(' my @args;') x !!($orig_args_as eq 'array' || $args_as eq 'array'), |
|
79
|
|
|
|
|
|
|
(' my $args;') x !!($orig_args_as =~ /ref/ || $args_as =~ /ref/), |
|
80
|
|
|
|
|
|
|
' '. |
|
81
|
|
|
|
|
|
|
($args_as eq 'hash' ? '%args = @_;' : |
|
82
|
|
|
|
|
|
|
$args_as eq 'hashref' ? '$args = $_[0] // {}; %args = %$args;' : |
|
83
|
|
|
|
|
|
|
$args_as eq 'array' ? '@args = @_;' : |
|
84
|
|
|
|
|
|
|
'$args = $_[0] // [];'), |
|
85
|
|
|
|
|
|
|
$src->{preamble}, |
|
86
|
|
|
|
|
|
|
($src->{postamble} ? ' $_w_res = do {' : ''), |
|
87
|
|
|
|
|
|
|
$sub_name. ($sub_name =~ /\A\$/ ? '->':'').'('. |
|
88
|
|
|
|
|
|
|
($orig_args_as eq 'hash' ? '%args' : |
|
89
|
|
|
|
|
|
|
$orig_args_as eq 'hashref' ? '$args' : |
|
90
|
|
|
|
|
|
|
$orig_args_as eq 'array' ? '@args' : |
|
91
|
|
|
|
|
|
|
'$args').');', |
|
92
|
|
|
|
|
|
|
($src->{postamble} ? '}; # do' : ''), |
|
93
|
|
|
|
|
|
|
$src->{postamble}, |
|
94
|
53
|
100
|
100
|
|
|
1363
|
'}; # sub', |
|
|
|
100
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
); |
|
96
|
53
|
|
|
10
|
|
5980
|
$sub = eval $eval_src; |
|
|
8
|
|
|
10
|
|
60
|
|
|
|
8
|
|
|
1
|
|
18
|
|
|
|
8
|
|
|
1
|
|
47
|
|
|
|
8
|
|
|
1
|
|
577
|
|
|
|
8
|
|
|
1
|
|
15
|
|
|
|
8
|
|
|
1
|
|
2434
|
|
|
|
|
|
|
1
|
|
|
|
|
|
|
|
|
1
|
|
|
|
|
|
|
|
|
1
|
|
|
|
|
|
|
|
|
1
|
|
|
|
|
|
|
|
|
1
|
|
|
|
|
|
|
|
|
1
|
|
|
|
|
|
|
|
|
1
|
|
|
|
|
|
|
|
|
1
|
|
|
|
|
|
|
|
|
1
|
|
|
|
|
|
|
|
|
1
|
|
|
|
|
|
|
|
|
1
|
|
|
|
|
|
|
|
|
1
|
|
|
|
|
|
|
|
|
1
|
|
|
|
|
|
|
|
|
1
|
|
|
|
|
|
|
|
|
1
|
|
|
|
|
97
|
53
|
|
|
|
|
283
|
my $eval_err = $@; |
|
98
|
53
|
50
|
|
|
|
186
|
ok(!$eval_err, "embed code compiles ok") or do { |
|
99
|
1
|
|
|
|
|
342
|
diag "eval err: ", $eval_err; |
|
100
|
1
|
|
|
|
|
7
|
diag "eval source: ", $eval_src; |
|
101
|
1
|
|
|
|
|
1
|
return; |
|
102
|
|
|
|
|
|
|
}; |
|
103
|
|
|
|
|
|
|
diag "eval source: ", $eval_src |
|
104
|
53
|
50
|
|
|
|
21098
|
if $ENV{LOG_PERINCI_WRAPPER_CODE}; |
|
105
|
|
|
|
|
|
|
} else { |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# check that we don't generate comment after code (unless it |
|
108
|
|
|
|
|
|
|
# uses '##' instead of '#'), because this makes cutting comments |
|
109
|
|
|
|
|
|
|
# easier. XXX this is using a simple regex and misses some. |
|
110
|
53
|
|
|
|
|
676
|
for my $line (split /^/, $wrap_res->[2]{source}) { |
|
111
|
2539
|
100
|
|
|
|
4798
|
if ($line =~ /(.*?)\s+#\s+(.*)/) { |
|
112
|
400
|
|
|
|
|
1199
|
my ($before, $after) = ($1, $2); |
|
113
|
400
|
50
|
|
|
|
794
|
next unless $before =~ /\S/; |
|
114
|
1
|
|
|
|
|
2
|
ok 0; diag "Source code contains comment line after some code '$line' (if you do this, you must use ## instead of # to help ease removing comment lines (e.g. in Dist::Zilla::Plugin::Rinci::Wrap))"; |
|
|
1
|
|
|
|
|
8
|
|
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
53
|
|
|
|
|
348
|
$sub = $wrap_res->[2]{sub}; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# testing a single sub call |
|
122
|
105
|
|
|
|
|
238
|
my $call_argsr = $test_args{call_argsr}; |
|
123
|
105
|
|
|
|
|
554
|
my $call_res; |
|
124
|
105
|
100
|
|
|
|
258
|
if ($call_argsr) { |
|
125
|
11
|
|
|
|
|
23
|
eval { $call_res = $sub->(@$call_argsr) }; |
|
|
11
|
|
|
|
|
255
|
|
|
126
|
11
|
|
|
|
|
147
|
my $call_eval_err = $@; |
|
127
|
11
|
50
|
|
|
|
32
|
if ($test_args{call_dies}) { |
|
128
|
1
|
|
|
|
|
550
|
ok($call_eval_err, "call dies"); |
|
129
|
1
|
0
|
|
|
|
7
|
if ($test_args{call_die_message}) { |
|
130
|
|
|
|
|
|
|
like($call_eval_err, $test_args{call_die_message}, |
|
131
|
1
|
|
|
|
|
3
|
"call die message"); |
|
132
|
|
|
|
|
|
|
} |
|
133
|
1
|
|
|
|
|
6
|
return; |
|
134
|
|
|
|
|
|
|
} else { |
|
135
|
11
|
50
|
|
|
|
130
|
ok(!$call_eval_err, "call doesn't die") |
|
136
|
|
|
|
|
|
|
or diag $call_eval_err; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
11
|
50
|
|
|
|
3432
|
if (defined $test_args{call_status}) { |
|
140
|
11
|
50
|
|
|
|
710
|
is(ref($call_res), 'ARRAY', 'call res is array') |
|
141
|
|
|
|
|
|
|
or diag "call res = ", explain($call_res); |
|
142
|
|
|
|
|
|
|
is($call_res->[0], $test_args{call_status}, |
|
143
|
11
|
50
|
|
|
|
3559
|
"call status is $test_args{call_status}") |
|
144
|
|
|
|
|
|
|
or diag "call res = ", explain($call_res); |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
11
|
100
|
|
|
|
3613
|
if (exists $test_args{call_res}) { |
|
148
|
|
|
|
|
|
|
is_deeply($call_res, $test_args{call_res}, |
|
149
|
3
|
50
|
|
|
|
19
|
"call res") |
|
150
|
|
|
|
|
|
|
or diag explain $call_res; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
11
|
50
|
|
|
|
1476
|
if (exists $test_args{call_actual_res}) { |
|
154
|
|
|
|
|
|
|
is_deeply($call_res->[2], $test_args{call_actual_res}, |
|
155
|
1
|
0
|
|
|
|
2
|
"call actual res") |
|
156
|
|
|
|
|
|
|
or diag explain $call_res->[2]; |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
|
|
159
|
11
|
100
|
|
|
|
34
|
if (exists $test_args{call_actual_res_re}) { |
|
160
|
|
|
|
|
|
|
like($call_res->[2], $test_args{call_actual_res_re}, |
|
161
|
3
|
|
|
|
|
113
|
"call actual res"); |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# testing multiple sub calls |
|
166
|
105
|
100
|
|
|
|
1077
|
if ($test_args{calls}) { |
|
167
|
67
|
|
|
|
|
563
|
my $i = 0; |
|
168
|
66
|
|
|
|
|
104
|
for my $call (@{$test_args{calls}}) { |
|
|
66
|
|
|
|
|
172
|
|
|
169
|
170
|
|
|
|
|
192340
|
$i++; |
|
170
|
|
|
|
|
|
|
subtest "call #$i: ".($call->{name} // "") => sub { |
|
171
|
170
|
|
|
|
|
170074
|
my $res; |
|
172
|
170
|
|
|
|
|
311
|
eval { $res = $sub->(@{$call->{argsr}}) }; |
|
|
170
|
|
|
|
|
254
|
|
|
|
170
|
|
|
|
|
4889
|
|
|
173
|
170
|
|
|
|
|
392
|
my $eval_err = $@; |
|
174
|
170
|
100
|
|
|
|
459
|
if ($call->{dies}) { |
|
175
|
2
|
|
|
|
|
7
|
ok($eval_err, "dies"); |
|
176
|
2
|
50
|
|
|
|
727
|
if ($call->{die_message}) { |
|
177
|
|
|
|
|
|
|
like($eval_err, $call->{die_message}, |
|
178
|
0
|
|
|
|
|
0
|
"die message"); |
|
179
|
|
|
|
|
|
|
} |
|
180
|
2
|
|
|
|
|
4
|
return; |
|
181
|
|
|
|
|
|
|
} else { |
|
182
|
168
|
50
|
|
|
|
507
|
ok(!$eval_err, "doesn't die") |
|
183
|
|
|
|
|
|
|
or diag $eval_err; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
168
|
100
|
|
|
|
69148
|
if (defined $call->{status}) { |
|
187
|
154
|
50
|
|
|
|
630
|
is(ref($res), 'ARRAY', 'res is array') |
|
188
|
|
|
|
|
|
|
or diag "res = ", explain($res); |
|
189
|
|
|
|
|
|
|
is($res->[0], $call->{status}, |
|
190
|
154
|
50
|
|
|
|
63946
|
"status is $call->{status}") |
|
191
|
|
|
|
|
|
|
or diag "res = ", explain($res); |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
|
|
194
|
168
|
100
|
|
|
|
63513
|
if (exists $call->{res}) { |
|
195
|
16
|
50
|
|
|
|
66
|
is_deeply($res, $call->{res}, "res") |
|
196
|
|
|
|
|
|
|
or diag explain $res; |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
|
|
199
|
168
|
100
|
|
|
|
12246
|
if (exists $call->{actual_res}) { |
|
200
|
32
|
50
|
|
|
|
124
|
is_deeply($res->[2], $call->{actual_res}, "actual res") |
|
201
|
|
|
|
|
|
|
or diag explain $res->[2]; |
|
202
|
|
|
|
|
|
|
} |
|
203
|
|
|
|
|
|
|
|
|
204
|
168
|
100
|
|
|
|
12957
|
if (exists $call->{actual_res_re}) { |
|
205
|
|
|
|
|
|
|
like($res->[2], $call->{actual_res_re}, |
|
206
|
4
|
|
|
|
|
12
|
"actual res re"); |
|
207
|
|
|
|
|
|
|
} |
|
208
|
170
|
|
100
|
|
|
1780
|
}; # subtest call #$i |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
} # if calls |
|
211
|
|
|
|
|
|
|
|
|
212
|
104
|
100
|
|
|
|
119810
|
if ($test_args{posttest}) { |
|
213
|
24
|
|
|
|
|
92
|
$test_args{posttest}->($wrap_res, $call_res, $sub); |
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
|
|
216
|
104
|
|
|
|
|
19871
|
done_testing(); |
|
217
|
|
|
|
|
|
|
|
|
218
|
114
|
|
|
|
|
1488
|
}; # subtest |
|
219
|
|
|
|
|
|
|
} # for $wrapper_type |
|
220
|
|
|
|
|
|
|
} |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
1; |
|
223
|
|
|
|
|
|
|
# ABSTRACT: Provide test_wrap() to test wrapper |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
__END__ |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=pod |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=encoding UTF-8 |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head1 NAME |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Test::Perinci::Sub::Wrapper - Provide test_wrap() to test wrapper |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head1 VERSION |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
This document describes version 0.851 of Test::Perinci::Sub::Wrapper (from Perl distribution Perinci-Sub-Wrapper), released on 2019-07-04. |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=for Pod::Coverage test_wrap |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head1 HOMEPAGE |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
Please visit the project's homepage at L<https://metacpan.org/release/Perinci-Sub-Wrapper>. |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 SOURCE |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Source repository is at L<https://github.com/perlancar/perl-Perinci-Sub-Wrapper>. |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head1 BUGS |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-Sub-Wrapper> |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
|
254
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
|
255
|
|
|
|
|
|
|
feature. |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head1 AUTHOR |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
perlancar <perlancar@cpan.org> |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
This software is copyright (c) 2019, 2017, 2016, 2015, 2014, 2013, 2012, 2011 by perlancar@cpan.org. |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
266
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=cut |