line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Base::Less; |
2
|
10
|
|
|
10
|
|
14387
|
use strict; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
238
|
|
3
|
10
|
|
|
10
|
|
49
|
use warnings; |
|
10
|
|
|
|
|
13
|
|
|
10
|
|
|
|
|
224
|
|
4
|
10
|
|
|
10
|
|
902
|
use utf8; |
|
10
|
|
|
|
|
24
|
|
|
10
|
|
|
|
|
43
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
7
|
|
|
|
|
|
|
|
8
|
10
|
|
|
10
|
|
7490
|
use parent qw/Test::Builder::Module Exporter/; |
|
10
|
|
|
|
|
3013
|
|
|
10
|
|
|
|
|
54
|
|
9
|
10
|
|
|
10
|
|
147949
|
use Test::More; |
|
10
|
|
|
|
|
50991
|
|
|
10
|
|
|
|
|
84
|
|
10
|
10
|
|
|
10
|
|
8437
|
use Data::Section::TestBase (); |
|
10
|
|
|
|
|
29
|
|
|
10
|
|
|
|
|
182
|
|
11
|
10
|
|
|
10
|
|
50
|
use Carp (); |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
2444
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT = (@Test::More::EXPORT, qw/filters blocks register_filter run run_is run_is_deeply/); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our %FILTER_MAP; |
16
|
|
|
|
|
|
|
our %FILTERS; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub register_filter($&) { |
19
|
50
|
|
|
50
|
1
|
201
|
my ($name, $code) = @_; |
20
|
50
|
|
|
|
|
162
|
$FILTERS{$name} = $code; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub filters($) { |
24
|
6
|
|
|
6
|
1
|
71
|
my $data = shift; |
25
|
6
|
|
|
|
|
26
|
for my $key (keys %$data) { |
26
|
9
|
|
50
|
|
|
60
|
$FILTER_MAP{$key} ||= []; |
27
|
9
|
|
|
|
|
13
|
push @{$FILTER_MAP{$key}}, @{$data->{$key}}; |
|
9
|
|
|
|
|
23
|
|
|
9
|
|
|
|
|
31
|
|
28
|
|
|
|
|
|
|
} |
29
|
6
|
|
|
|
|
21
|
return; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub blocks() { |
33
|
7
|
|
|
7
|
1
|
39
|
my @blocks = _get_blocks(scalar(caller(0))); |
34
|
7
|
|
|
|
|
63
|
return @blocks; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _get_blocks { |
38
|
14
|
|
|
14
|
|
30
|
my $package = shift; |
39
|
|
|
|
|
|
|
|
40
|
10
|
|
|
10
|
|
49
|
my $d = do { no strict 'refs'; \*{"${package}::DATA"} }; |
|
10
|
|
|
|
|
16
|
|
|
10
|
|
|
|
|
6909
|
|
|
14
|
|
|
|
|
24
|
|
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
62
|
|
41
|
14
|
50
|
|
|
|
64
|
unless (defined fileno $d) { |
42
|
0
|
|
|
|
|
0
|
Carp::croak("Missing __DATA__ section in $package."); |
43
|
|
|
|
|
|
|
} |
44
|
14
|
|
|
|
|
122
|
seek $d, 0, 0; |
45
|
|
|
|
|
|
|
|
46
|
14
|
|
|
|
|
353
|
my $content = join '', <$d>; |
47
|
|
|
|
|
|
|
|
48
|
14
|
|
|
|
|
125
|
my $parser = Text::TestBase->new(); |
49
|
14
|
|
|
|
|
61
|
my @blocks = $parser->parse($content); |
50
|
14
|
|
|
|
|
28
|
my @retval; |
51
|
14
|
|
|
|
|
34
|
for my $block (@blocks) { |
52
|
27
|
|
|
|
|
90
|
for my $section_name ($block->get_section_names) { |
53
|
38
|
|
|
|
|
119
|
my @data = $block->get_section($section_name); |
54
|
38
|
100
|
|
|
|
128
|
if (my $filter_names = $FILTER_MAP{$section_name}) { |
55
|
20
|
|
|
|
|
39
|
for my $filter_stuff (@$filter_names) { |
56
|
23
|
100
|
|
|
|
53
|
if (ref $filter_stuff eq 'CODE') { # filters { input => [\&code] }; |
57
|
4
|
|
|
|
|
18
|
@data = $filter_stuff->(@data); |
58
|
|
|
|
|
|
|
} else { # filters { input => [qw/eval/] }; |
59
|
19
|
|
|
|
|
38
|
my $filter = $FILTERS{$filter_stuff}; |
60
|
19
|
50
|
|
|
|
47
|
unless ($filter) { |
61
|
0
|
|
|
|
|
0
|
Carp::croak "Unknown filter name: $filter_stuff"; |
62
|
|
|
|
|
|
|
} |
63
|
19
|
|
|
|
|
79
|
@data = $filter->(@data); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
38
|
|
|
|
|
170
|
$block->set_section($section_name => @data); |
68
|
|
|
|
|
|
|
} |
69
|
27
|
100
|
|
|
|
96
|
if ($block->has_section('ONLY')) { |
70
|
1
|
|
|
|
|
14
|
__PACKAGE__->builder->diag("I found ONLY: maybe you're debugging?"); |
71
|
1
|
|
|
|
|
184
|
return $block; |
72
|
|
|
|
|
|
|
} |
73
|
26
|
100
|
|
|
|
84
|
if ($block->has_section('SKIP')) { |
74
|
1
|
|
|
|
|
2
|
next; |
75
|
|
|
|
|
|
|
} |
76
|
25
|
|
|
|
|
45
|
push @retval, $block; |
77
|
25
|
100
|
|
|
|
74
|
if ($block->has_section('LAST')) { |
78
|
1
|
|
|
|
|
17
|
return @retval; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
12
|
|
|
|
|
104
|
return @retval; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub run(&) { |
85
|
4
|
|
|
4
|
0
|
564
|
my $code = shift; |
86
|
|
|
|
|
|
|
|
87
|
4
|
|
|
|
|
23
|
for my $block (_get_blocks(scalar(caller(0)))) { |
88
|
|
|
|
|
|
|
__PACKAGE__->builder->subtest($block->name || 'L: ' . $block->get_lineno, sub { |
89
|
8
|
|
|
8
|
|
5134
|
$code->($block); |
90
|
8
|
|
66
|
|
|
5558
|
}); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub run_is($$) { |
95
|
2
|
|
|
2
|
0
|
19
|
my ($a, $b) = @_; |
96
|
|
|
|
|
|
|
|
97
|
2
|
|
|
|
|
11
|
for my $block (_get_blocks(scalar(caller(0)))) { |
98
|
3
|
|
66
|
|
|
525
|
__PACKAGE__->builder->is_eq( |
99
|
|
|
|
|
|
|
$block->get_section($a), |
100
|
|
|
|
|
|
|
$block->get_section($b), |
101
|
|
|
|
|
|
|
$block->name || 'L: ' . $block->get_lineno |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub run_is_deeply($$) { |
107
|
1
|
|
|
1
|
0
|
8
|
my ($a, $b) = @_; |
108
|
|
|
|
|
|
|
|
109
|
1
|
|
|
|
|
5
|
for my $block (_get_blocks(scalar(caller(0)))) { |
110
|
1
|
|
|
|
|
3
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
111
|
1
|
|
33
|
|
|
5
|
Test::More::is_deeply( |
112
|
|
|
|
|
|
|
$block->get_section($a), |
113
|
|
|
|
|
|
|
$block->get_section($b), |
114
|
|
|
|
|
|
|
$block->name || 'L: ' . $block->get_lineno |
115
|
|
|
|
|
|
|
); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
package Test::Base::Less::Filter; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Test::Base::Less::register_filter(eval => \&_eval); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub _eval { |
124
|
12
|
|
|
12
|
|
54
|
my $src = shift; |
125
|
10
|
|
|
10
|
|
68
|
no warnings; |
|
10
|
|
|
|
|
29
|
|
|
10
|
|
|
|
|
3407
|
|
126
|
12
|
|
|
|
|
625
|
my @return = CORE::eval $src; |
127
|
12
|
50
|
|
|
|
73
|
return $@ if $@; |
128
|
12
|
|
|
|
|
43
|
return @return; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Test::Base::Less::register_filter(chomp => \&_chomp); |
132
|
|
|
|
|
|
|
sub _chomp { |
133
|
0
|
|
|
0
|
|
0
|
map { CORE::chomp; $_ } @_; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Test::Base::Less::register_filter(uc => \&_uc); |
137
|
|
|
|
|
|
|
sub _uc { |
138
|
1
|
|
|
1
|
|
3
|
map { CORE::uc($_) } @_; |
|
1
|
|
|
|
|
11
|
|
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Test::Base::Less::register_filter(trim => \&_trim); |
142
|
|
|
|
|
|
|
sub _trim { |
143
|
|
|
|
|
|
|
map { |
144
|
5
|
|
|
5
|
|
10
|
s/\A([ \t]*\n)+//; |
|
5
|
|
|
|
|
18
|
|
145
|
5
|
|
|
|
|
30
|
s/(?<=\n)\s*\z//g; |
146
|
5
|
|
|
|
|
62
|
$_; |
147
|
|
|
|
|
|
|
} @_; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Test::Base::Less::register_filter(lines => \&_lines); |
151
|
|
|
|
|
|
|
sub _lines { |
152
|
1
|
|
|
1
|
|
3
|
my $src = shift; |
153
|
1
|
50
|
|
|
|
5
|
return () unless length $src; |
154
|
1
|
|
|
|
|
13
|
my @lines = ($src =~ /^(.*\n?)/gm); |
155
|
1
|
|
|
|
|
6
|
return @lines; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1; |
159
|
|
|
|
|
|
|
__END__ |