line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
## no critic: (Modules::ProhibitAutomaticExportation) |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Test::Data::Unixish; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $DATE = '2019-01-06'; # DATE |
6
|
|
|
|
|
|
|
our $VERSION = '1.570'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
37
|
|
|
37
|
|
25436
|
use 5.010001; |
|
37
|
|
|
|
|
292
|
|
9
|
37
|
|
|
37
|
|
183
|
use strict; |
|
37
|
|
|
|
|
55
|
|
|
37
|
|
|
|
|
817
|
|
10
|
37
|
|
|
37
|
|
179
|
use warnings; |
|
37
|
|
|
|
|
63
|
|
|
37
|
|
|
|
|
1092
|
|
11
|
|
|
|
|
|
|
|
12
|
37
|
|
|
37
|
|
15976
|
use Data::Unixish qw(aiduxa); |
|
37
|
|
|
|
|
84
|
|
|
37
|
|
|
|
|
2435
|
|
13
|
37
|
|
|
37
|
|
18944
|
use File::Which qw(which); |
|
37
|
|
|
|
|
47076
|
|
|
37
|
|
|
|
|
2337
|
|
14
|
37
|
|
|
37
|
|
21641
|
use IPC::Cmd qw(run_forked); |
|
37
|
|
|
|
|
2020289
|
|
|
37
|
|
|
|
|
2229
|
|
15
|
37
|
|
|
37
|
|
17280
|
use JSON::MaybeXS; |
|
37
|
|
|
|
|
257214
|
|
|
37
|
|
|
|
|
2093
|
|
16
|
37
|
|
|
37
|
|
272
|
use Module::Load; |
|
37
|
|
|
|
|
89
|
|
|
37
|
|
|
|
|
496
|
|
17
|
37
|
|
|
37
|
|
15691
|
use String::ShellQuote; |
|
37
|
|
|
|
|
26808
|
|
|
37
|
|
|
|
|
2132
|
|
18
|
37
|
|
|
37
|
|
19172
|
use Test::More 0.96; |
|
37
|
|
|
|
|
2064441
|
|
|
37
|
|
|
|
|
319
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
require Exporter; |
21
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
22
|
|
|
|
|
|
|
our @EXPORT = qw(test_dux_func); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $json = JSON::MaybeXS->new->allow_nonref; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub test_dux_func { |
27
|
37
|
|
|
37
|
|
10900
|
no strict 'refs'; |
|
37
|
|
|
|
|
90
|
|
|
37
|
|
|
|
|
34636
|
|
28
|
|
|
|
|
|
|
|
29
|
34
|
|
|
34
|
0
|
6494
|
my %args = @_; |
30
|
34
|
|
|
|
|
119
|
my $fn = $args{func}; |
31
|
34
|
|
|
|
|
77
|
my $fnl = $fn; $fnl =~ s/.+:://; |
|
34
|
|
|
|
|
105
|
|
32
|
34
|
|
|
|
|
240
|
load "Data::Unixish::$fn"; |
33
|
34
|
|
|
|
|
641
|
my $f = "Data::Unixish::$fn\::$fnl"; |
34
|
34
|
|
|
|
|
76
|
my $spec = \%{"Data::Unixish::$fn\::SPEC"}; |
|
34
|
|
|
|
|
187
|
|
35
|
34
|
|
|
|
|
111
|
my $meta = $spec->{$fn}; |
36
|
|
|
|
|
|
|
|
37
|
34
|
50
|
|
|
|
147
|
$meta or die "BUG: func $fn not found or does not have meta"; |
38
|
|
|
|
|
|
|
|
39
|
34
|
|
|
|
|
74
|
my $i = 0; |
40
|
|
|
|
|
|
|
subtest $fn => sub { |
41
|
|
|
|
|
|
|
TEST: |
42
|
34
|
|
|
34
|
|
37916
|
for my $t (@{$args{tests}}) { |
|
34
|
|
|
|
|
142
|
|
43
|
76
|
|
|
|
|
51284
|
$i++; |
44
|
76
|
|
66
|
|
|
466
|
my $tn = $t->{name} // "test[$i]"; |
45
|
|
|
|
|
|
|
subtest $tn => sub { |
46
|
76
|
100
|
|
|
|
61876
|
if ($t->{skip}) { |
47
|
1
|
|
|
|
|
5
|
my $msg = $t->{skip}->(); |
48
|
1
|
50
|
|
|
|
9
|
plan skip_all => $msg if $msg; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# test func |
52
|
75
|
50
|
|
|
|
264
|
if ($t->{skip_func}) { |
53
|
0
|
|
|
|
|
0
|
diag "func test skipped"; |
54
|
|
|
|
|
|
|
} else { |
55
|
|
|
|
|
|
|
subtest "func" => sub { |
56
|
75
|
|
|
|
|
58864
|
my $in = $t->{in}; |
57
|
75
|
|
|
|
|
184
|
my $out = $t->{out}; |
58
|
75
|
|
|
|
|
159
|
my $rout = []; |
59
|
75
|
|
|
|
|
134
|
my $res; |
60
|
75
|
|
|
|
|
121
|
eval { $res = $f->(in=>$in,out=>$rout,%{$t->{args}}) }; |
|
75
|
|
|
|
|
138
|
|
|
75
|
|
|
|
|
632
|
|
61
|
75
|
|
|
|
|
171
|
my $err = $@; |
62
|
75
|
100
|
66
|
|
|
663
|
if ($t->{func_dies} // $t->{dies} // 0) { |
|
|
|
50
|
|
|
|
|
63
|
3
|
|
|
|
|
11
|
ok($err, "dies"); |
64
|
3
|
|
|
|
|
1240
|
return; |
65
|
|
|
|
|
|
|
} else { |
66
|
72
|
50
|
|
|
|
320
|
ok(!$err, "doesn't die") or do { |
67
|
0
|
|
|
|
|
0
|
diag "func dies: $err"; |
68
|
0
|
|
|
|
|
0
|
return; |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
} |
71
|
72
|
|
|
|
|
31087
|
is($res->[0], 200, "status"); |
72
|
72
|
100
|
|
|
|
29797
|
if ($t->{test_out}) { |
73
|
1
|
|
|
|
|
6
|
$t->{test_out}->($rout); |
74
|
|
|
|
|
|
|
} else { |
75
|
71
|
50
|
|
|
|
308
|
is_deeply($rout, $out, "out") |
76
|
|
|
|
|
|
|
or diag explain $rout; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# if itemfunc, test against each item |
80
|
72
|
100
|
66
|
|
|
54925
|
if ((grep {$_ eq 'itemfunc'} @{$meta->{tags}}) && |
|
147
|
|
|
|
|
694
|
|
|
72
|
|
|
|
|
233
|
|
81
|
|
|
|
|
|
|
ref($in) eq 'ARRAY') { |
82
|
47
|
100
|
|
|
|
168
|
if ($t->{skip_itemfunc}) { |
83
|
3
|
|
|
|
|
14
|
diag "itemfunc test skipped"; |
84
|
|
|
|
|
|
|
} else { |
85
|
44
|
|
|
|
|
140
|
my $rout; |
86
|
44
|
|
|
|
|
259
|
$rout = aiduxa([$fn, $t->{args}], $in); |
87
|
44
|
50
|
|
|
|
168
|
if ($t->{test_out}) { |
88
|
0
|
|
|
|
|
0
|
$t->{test_out}->($rout); |
89
|
|
|
|
|
|
|
} else { |
90
|
44
|
50
|
|
|
|
185
|
is_deeply($rout, $out, "out") |
91
|
|
|
|
|
|
|
or diag explain $rout; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
75
|
|
|
|
|
583
|
}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# test running through cmdline |
99
|
75
|
100
|
100
|
|
|
139055
|
if ($t->{skip_cli} // 1) { |
100
|
|
|
|
|
|
|
#diag "cli test skipped"; |
101
|
|
|
|
|
|
|
} else { |
102
|
|
|
|
|
|
|
subtest cli => sub { |
103
|
3
|
50
|
|
|
|
2239
|
if ($^O =~ /win/i) { |
104
|
0
|
|
|
|
|
0
|
plan skip_all => "run_forked() not available ". |
105
|
|
|
|
|
|
|
"on Windows"; |
106
|
0
|
|
|
|
|
0
|
return; |
107
|
|
|
|
|
|
|
} |
108
|
3
|
50
|
|
|
|
17
|
unless (which("dux")) { |
109
|
3
|
|
|
|
|
695
|
plan skip_all => "dux command-line not available, ". |
110
|
|
|
|
|
|
|
"you might want to install App::dux first"; |
111
|
0
|
|
|
|
|
|
return; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
my $cmd = "dux $fn ". |
114
|
|
|
|
|
|
|
join(" ", map { |
115
|
0
|
|
|
|
|
|
my $v = $t->{args}{$_}; |
116
|
0
|
|
|
|
|
|
my $p = $_; $p =~ s/_/-/g; |
|
0
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
ref($v) ? |
118
|
|
|
|
|
|
|
("--$p-json", |
119
|
|
|
|
|
|
|
shell_quote($json->encode($v))) : |
120
|
|
|
|
|
|
|
("--$p", shell_quote($v)) |
121
|
|
|
|
|
|
|
} |
122
|
0
|
|
|
|
|
|
keys %{ $t->{args} }); |
|
0
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
#diag "cmd: $cmd"; |
124
|
|
|
|
|
|
|
my %runopts = ( |
125
|
0
|
|
|
|
|
|
child_stdin => join("", map {"$_\n"} @{ $t->{in} }), |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
); |
127
|
0
|
|
|
|
|
|
my $res = run_forked($cmd, \%runopts); |
128
|
0
|
0
|
0
|
|
|
|
if ($t->{cli_dies} // $t->{dies} // 0) { |
|
|
|
0
|
|
|
|
|
129
|
0
|
|
|
|
|
|
ok($res->{exit_code}, "dies"); |
130
|
0
|
|
|
|
|
|
return; |
131
|
|
|
|
|
|
|
} else { |
132
|
0
|
0
|
|
|
|
|
ok(!$res->{exit_code}, "doesn't die") or do { |
133
|
0
|
|
|
|
|
|
diag "dux dies ($res->{exit_code})"; |
134
|
0
|
|
|
|
|
|
return; |
135
|
|
|
|
|
|
|
}; |
136
|
|
|
|
|
|
|
} |
137
|
0
|
|
|
|
|
|
is_deeply(join("", map {"$_\n"} @{ $t->{out} }), |
|
0
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
$res->{stdout}, "output"); |
139
|
|
|
|
|
|
|
} |
140
|
3
|
|
|
|
|
58
|
} |
141
|
76
|
|
|
|
|
569
|
}; |
142
|
|
|
|
|
|
|
} |
143
|
34
|
|
|
|
|
381
|
}; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |
147
|
|
|
|
|
|
|
# ABSTRACT: Routines to test Data::Unixish |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
__END__ |