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