line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Config::IOD::Common; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
519
|
use 5.010; |
|
1
|
|
|
|
|
8
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
30
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
525
|
use Test::More 0.98; |
|
1
|
|
|
|
|
59220
|
|
|
1
|
|
|
|
|
9
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
10
|
|
|
|
|
|
|
our $DATE = '2022-05-02'; # DATE |
11
|
|
|
|
|
|
|
our $DIST = 'Config-IOD-Reader'; # DIST |
12
|
|
|
|
|
|
|
our $VERSION = '0.344'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $CLASS = "Config::IOD::Reader"; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub test_common_iod { |
17
|
|
|
|
|
|
|
|
18
|
1
|
50
|
|
1
|
0
|
116
|
eval "require $CLASS"; die if $@; ## no critic: BuiltinFunctions::ProhibitStringyEval |
|
1
|
|
|
|
|
5
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
subtest "opt: default_section" => sub { |
21
|
1
|
|
|
1
|
|
861
|
test_read_iod( |
22
|
|
|
|
|
|
|
args => {default_section=>'bawaan'}, |
23
|
|
|
|
|
|
|
input => <<'_', |
24
|
|
|
|
|
|
|
a=1 |
25
|
|
|
|
|
|
|
_ |
26
|
|
|
|
|
|
|
result => {bawaan=>{a=>1}}, |
27
|
|
|
|
|
|
|
); |
28
|
1
|
|
|
|
|
7
|
}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
subtest "opt: allow_directives" => sub { |
31
|
1
|
|
|
1
|
|
589
|
test_read_iod( |
32
|
|
|
|
|
|
|
args => {allow_directives=>['merge']}, |
33
|
|
|
|
|
|
|
input => <<'_', |
34
|
|
|
|
|
|
|
;!noop |
35
|
|
|
|
|
|
|
_ |
36
|
|
|
|
|
|
|
dies => 1, |
37
|
|
|
|
|
|
|
); |
38
|
1
|
|
|
|
|
1074
|
test_read_iod( |
39
|
|
|
|
|
|
|
args => {allow_directives=>['noop']}, |
40
|
|
|
|
|
|
|
input => <<'_', |
41
|
|
|
|
|
|
|
;!noop |
42
|
|
|
|
|
|
|
_ |
43
|
|
|
|
|
|
|
result => {}, |
44
|
|
|
|
|
|
|
); |
45
|
1
|
|
|
|
|
2868
|
}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
subtest "opt: disallow_directives" => sub { |
48
|
1
|
|
|
1
|
|
602
|
test_read_iod( |
49
|
|
|
|
|
|
|
args => {disallow_directives=>['noop']}, |
50
|
|
|
|
|
|
|
input => <<'_', |
51
|
|
|
|
|
|
|
;!noop |
52
|
|
|
|
|
|
|
_ |
53
|
|
|
|
|
|
|
dies => 1, |
54
|
|
|
|
|
|
|
); |
55
|
1
|
|
|
|
|
1014
|
test_read_iod( |
56
|
|
|
|
|
|
|
args => {disallow_directives=>['merge']}, |
57
|
|
|
|
|
|
|
input => <<'_', |
58
|
|
|
|
|
|
|
;!noop |
59
|
|
|
|
|
|
|
_ |
60
|
|
|
|
|
|
|
result => {}, |
61
|
|
|
|
|
|
|
); |
62
|
1
|
|
|
|
|
2486
|
}; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
subtest "opt: allow_directives + disallow_directives" => sub { |
65
|
1
|
|
|
1
|
|
621
|
test_read_iod( |
66
|
|
|
|
|
|
|
args => { |
67
|
|
|
|
|
|
|
allow_directives => ['noop'], |
68
|
|
|
|
|
|
|
disallow_directives => ['noop'], |
69
|
|
|
|
|
|
|
}, |
70
|
|
|
|
|
|
|
input => <<'_', |
71
|
|
|
|
|
|
|
;!noop |
72
|
|
|
|
|
|
|
_ |
73
|
|
|
|
|
|
|
dies => 1, |
74
|
|
|
|
|
|
|
); |
75
|
1
|
|
|
|
|
2500
|
}; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
subtest "opt: enable_directive=0" => sub { |
78
|
1
|
|
|
1
|
|
589
|
test_read_iod( |
79
|
|
|
|
|
|
|
args => {enable_directive=>0}, |
80
|
|
|
|
|
|
|
input => <<'_', |
81
|
|
|
|
|
|
|
[s1] |
82
|
|
|
|
|
|
|
a=1 |
83
|
|
|
|
|
|
|
[s2] |
84
|
|
|
|
|
|
|
;!merge s1 |
85
|
|
|
|
|
|
|
b=2 |
86
|
|
|
|
|
|
|
_ |
87
|
|
|
|
|
|
|
result => {s1=>{a=>1}, s2=>{b=>2}}, |
88
|
|
|
|
|
|
|
); |
89
|
1
|
|
|
|
|
1839
|
test_read_iod( |
90
|
|
|
|
|
|
|
args => {enable_directive=>0}, |
91
|
|
|
|
|
|
|
input => <<'_', |
92
|
|
|
|
|
|
|
[s1] |
93
|
|
|
|
|
|
|
a=1 |
94
|
|
|
|
|
|
|
[s2] |
95
|
|
|
|
|
|
|
!merge s1 |
96
|
|
|
|
|
|
|
b=2 |
97
|
|
|
|
|
|
|
_ |
98
|
|
|
|
|
|
|
dies => 1, |
99
|
|
|
|
|
|
|
); |
100
|
1
|
|
|
|
|
1951
|
}; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
subtest "opt: enable_quoting=0" => sub { |
103
|
1
|
|
|
1
|
|
600
|
test_read_iod( |
104
|
|
|
|
|
|
|
args => {enable_quoting=>0}, |
105
|
|
|
|
|
|
|
input => <<'_', |
106
|
|
|
|
|
|
|
name="1\n2" |
107
|
|
|
|
|
|
|
_ |
108
|
|
|
|
|
|
|
result => {GLOBAL=>{name=>'"1\\n2"'}}, |
109
|
|
|
|
|
|
|
); |
110
|
1
|
|
|
|
|
2015
|
}; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
subtest "opt: enable_bracket=0" => sub { |
113
|
1
|
|
|
1
|
|
604
|
test_read_iod( |
114
|
|
|
|
|
|
|
args => {enable_bracket=>0}, |
115
|
|
|
|
|
|
|
input => <<'_', |
116
|
|
|
|
|
|
|
name=[1,2,3] |
117
|
|
|
|
|
|
|
_ |
118
|
|
|
|
|
|
|
result => {GLOBAL=>{name=>'[1,2,3]'}}, |
119
|
|
|
|
|
|
|
); |
120
|
1
|
|
|
|
|
2649
|
}; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
subtest "opt: enable_brace=0" => sub { |
123
|
1
|
|
|
1
|
|
583
|
test_read_iod( |
124
|
|
|
|
|
|
|
args => {enable_brace=>0}, |
125
|
|
|
|
|
|
|
input => <<'_', |
126
|
|
|
|
|
|
|
name={"a":1} |
127
|
|
|
|
|
|
|
_ |
128
|
|
|
|
|
|
|
result => {GLOBAL=>{name=>'{"a":1}'}}, |
129
|
|
|
|
|
|
|
); |
130
|
1
|
|
|
|
|
2618
|
}; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
subtest "opt: enable_encoding=0" => sub { |
133
|
1
|
|
|
1
|
|
586
|
test_read_iod( |
134
|
|
|
|
|
|
|
args => {enable_encoding=>0}, |
135
|
|
|
|
|
|
|
input => <<'_', |
136
|
|
|
|
|
|
|
name=!hex 5e5e |
137
|
|
|
|
|
|
|
_ |
138
|
|
|
|
|
|
|
result => {GLOBAL=>{name=>'!hex 5e5e'}}, |
139
|
|
|
|
|
|
|
); |
140
|
1
|
|
|
|
|
2586
|
}; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
subtest "opt: allow_encodings" => sub { |
143
|
1
|
|
|
1
|
|
919
|
test_read_iod( |
144
|
|
|
|
|
|
|
args => {allow_encodings=>['hex']}, |
145
|
|
|
|
|
|
|
input => <<'_', |
146
|
|
|
|
|
|
|
name=!json "1\n2" |
147
|
|
|
|
|
|
|
_ |
148
|
|
|
|
|
|
|
dies => 1, |
149
|
|
|
|
|
|
|
); |
150
|
1
|
|
|
|
|
1027
|
test_read_iod( |
151
|
|
|
|
|
|
|
args => {allow_encodings=>['json']}, |
152
|
|
|
|
|
|
|
input => <<'_', |
153
|
|
|
|
|
|
|
name=!json "1\n2" |
154
|
|
|
|
|
|
|
name2=!j "3\n4" |
155
|
|
|
|
|
|
|
_ |
156
|
|
|
|
|
|
|
result => {GLOBAL=>{name=>"1\n2", name2=>"3\n4"}}, |
157
|
|
|
|
|
|
|
); |
158
|
1
|
|
|
|
|
2597
|
}; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
subtest "opt: disallow_encodings" => sub { |
161
|
1
|
|
|
1
|
|
588
|
test_read_iod( |
162
|
|
|
|
|
|
|
args => {disallow_encodings=>['json']}, |
163
|
|
|
|
|
|
|
input => <<'_', |
164
|
|
|
|
|
|
|
name=!json "1\n2" |
165
|
|
|
|
|
|
|
_ |
166
|
|
|
|
|
|
|
dies => 1, |
167
|
|
|
|
|
|
|
); |
168
|
1
|
|
|
|
|
1054
|
test_read_iod( |
169
|
|
|
|
|
|
|
args => {disallow_encodings=>['json']}, |
170
|
|
|
|
|
|
|
input => <<'_', |
171
|
|
|
|
|
|
|
name=!j "1\n2" |
172
|
|
|
|
|
|
|
_ |
173
|
|
|
|
|
|
|
dies => 1, |
174
|
|
|
|
|
|
|
); |
175
|
1
|
|
|
|
|
1022
|
test_read_iod( |
176
|
|
|
|
|
|
|
args => {disallow_encodings=>['hex']}, |
177
|
|
|
|
|
|
|
input => <<'_', |
178
|
|
|
|
|
|
|
name=!json "1\n2" |
179
|
|
|
|
|
|
|
_ |
180
|
|
|
|
|
|
|
result => {GLOBAL=>{name=>"1\n2"}}, |
181
|
|
|
|
|
|
|
); |
182
|
1
|
|
|
|
|
2635
|
}; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
subtest "opt: allow_encodings + disallow_encodings" => sub { |
185
|
1
|
|
|
1
|
|
604
|
test_read_iod( |
186
|
|
|
|
|
|
|
args => { |
187
|
|
|
|
|
|
|
allow_encodings =>['json'], |
188
|
|
|
|
|
|
|
disallow_encodings=>['json'], |
189
|
|
|
|
|
|
|
}, |
190
|
|
|
|
|
|
|
input => <<'_', |
191
|
|
|
|
|
|
|
name=!json "1\n2" |
192
|
|
|
|
|
|
|
_ |
193
|
|
|
|
|
|
|
dies => 1, |
194
|
|
|
|
|
|
|
); |
195
|
1
|
|
|
|
|
2712
|
}; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
subtest "opt: allow_bang_only=0" => sub { |
198
|
1
|
|
|
1
|
|
585
|
test_read_iod( |
199
|
|
|
|
|
|
|
args => {allow_bang_only=>0}, |
200
|
|
|
|
|
|
|
input => <<'_', |
201
|
|
|
|
|
|
|
a=1 |
202
|
|
|
|
|
|
|
!noop |
203
|
|
|
|
|
|
|
_ |
204
|
|
|
|
|
|
|
dies => 1, |
205
|
|
|
|
|
|
|
); |
206
|
1
|
|
|
|
|
1949
|
}; |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
subtest "opt: allow_duplicate_key=0" => sub { |
209
|
1
|
|
|
1
|
|
584
|
test_read_iod( |
210
|
|
|
|
|
|
|
args => {allow_duplicate_key=>0}, |
211
|
|
|
|
|
|
|
input => <<'_', |
212
|
|
|
|
|
|
|
a=1 |
213
|
|
|
|
|
|
|
a=2 |
214
|
|
|
|
|
|
|
_ |
215
|
|
|
|
|
|
|
dies => 1, |
216
|
|
|
|
|
|
|
); |
217
|
1
|
|
|
|
|
1986
|
}; |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
subtest "opt: ignore_unknown_directive=1" => sub { |
220
|
1
|
|
|
1
|
|
594
|
test_read_iod( |
221
|
|
|
|
|
|
|
args => {ignore_unknown_directive=>1}, |
222
|
|
|
|
|
|
|
input => <<'_', |
223
|
|
|
|
|
|
|
;!foo bar |
224
|
|
|
|
|
|
|
_ |
225
|
|
|
|
|
|
|
result => {}, |
226
|
|
|
|
|
|
|
); |
227
|
1
|
|
|
|
|
1987
|
}; |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
# temporarily placed here |
230
|
|
|
|
|
|
|
subtest "expr" => sub { |
231
|
1
|
|
|
1
|
|
594
|
test_read_iod( |
232
|
|
|
|
|
|
|
name => "must be enabled first", |
233
|
|
|
|
|
|
|
args => {}, |
234
|
|
|
|
|
|
|
input => <<'_', |
235
|
|
|
|
|
|
|
a=!e 1+1 |
236
|
|
|
|
|
|
|
_ |
237
|
|
|
|
|
|
|
dies => 1, |
238
|
|
|
|
|
|
|
); |
239
|
1
|
|
|
|
|
1085
|
test_read_iod( |
240
|
|
|
|
|
|
|
name => "must be valid", |
241
|
|
|
|
|
|
|
args => {enable_expr=>1}, |
242
|
|
|
|
|
|
|
input => <<'_', |
243
|
|
|
|
|
|
|
a=!e 1+ |
244
|
|
|
|
|
|
|
_ |
245
|
|
|
|
|
|
|
dies => 1, |
246
|
|
|
|
|
|
|
); |
247
|
1
|
|
|
|
|
1244
|
test_read_iod( |
248
|
|
|
|
|
|
|
args => {enable_expr=>1}, |
249
|
|
|
|
|
|
|
input => <<'_', |
250
|
|
|
|
|
|
|
a=!e 1+1 |
251
|
|
|
|
|
|
|
[sect] |
252
|
|
|
|
|
|
|
b=!e val("GLOBAL.a")*3 |
253
|
|
|
|
|
|
|
c=!e val("b") x 3 |
254
|
|
|
|
|
|
|
_ |
255
|
|
|
|
|
|
|
result => {GLOBAL=>{a=>2}, sect=>{b=>6, c=>666}}, |
256
|
|
|
|
|
|
|
); |
257
|
1
|
|
|
|
|
2463
|
}; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
sub test_read_iod { |
261
|
24
|
|
|
24
|
0
|
80
|
my %args = @_; |
262
|
|
|
|
|
|
|
|
263
|
24
|
|
|
|
|
40
|
my $parser_args = $args{args}; |
264
|
|
|
|
|
|
|
my $test_name = $args{name} // |
265
|
|
|
|
|
|
|
"{". join(", ", |
266
|
24
|
|
66
|
|
|
99
|
(map {"$_=$parser_args->{$_}"} |
|
24
|
|
|
|
|
138
|
|
267
|
|
|
|
|
|
|
sort keys %$parser_args), |
268
|
|
|
|
|
|
|
) . "}"; |
269
|
|
|
|
|
|
|
subtest $test_name => sub { |
270
|
|
|
|
|
|
|
|
271
|
24
|
|
|
24
|
|
15799
|
my $parser = $CLASS->new(%$parser_args); |
272
|
|
|
|
|
|
|
|
273
|
24
|
|
|
|
|
33
|
my $res; |
274
|
24
|
|
|
|
|
35
|
eval { |
275
|
24
|
50
|
|
|
|
47
|
if ($CLASS eq 'Config::IOD') { |
276
|
0
|
|
|
|
|
0
|
$res = $parser->read_string($args{input})->dump; |
277
|
|
|
|
|
|
|
} else { |
278
|
24
|
|
|
|
|
58
|
$res = $parser->read_string($args{input}); |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
}; |
281
|
24
|
|
|
|
|
47
|
my $err = $@; |
282
|
24
|
100
|
|
|
|
43
|
if ($args{dies}) { |
283
|
12
|
50
|
|
|
|
27
|
ok($err, "dies") or diag explain $res; |
284
|
12
|
|
|
|
|
3871
|
return; |
285
|
|
|
|
|
|
|
} else { |
286
|
|
|
|
|
|
|
ok(!$err, "doesn't die") |
287
|
12
|
50
|
|
|
|
29
|
or do { diag explain "err=$err"; return }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
288
|
12
|
50
|
|
|
|
3831
|
is_deeply($res, $args{result}, 'result') |
289
|
|
|
|
|
|
|
or diag explain $res; |
290
|
|
|
|
|
|
|
} |
291
|
24
|
|
|
|
|
125
|
}; |
292
|
|
|
|
|
|
|
} |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
1; |
295
|
|
|
|
|
|
|
# ABSTRACT: Common tests for Config::IOD and Config::IOD::Reader |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
__END__ |