1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
|
#!/usr/bin/perl
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
use strict;
use warnings;
use Test::More;
use Test::Dpkg qw(:paths);
BEGIN {
plan tests => 2603;
use_ok('Dpkg::Control::Types');
use_ok('Dpkg::Control::FieldsCore');
use_ok('Dpkg::Control');
}
#my $datadir = test_get_data_path();
my @src_dep_fields = qw(
Build-Depends
Build-Depends-Arch
Build-Depends-Indep
Build-Conflicts
Build-Conflicts-Arch
Build-Conflicts-Indep
);
my @bin_dep_normal_fields = qw(
Pre-Depends
Depends
Recommends
Suggests
Enhances
);
my @bin_dep_union_fields = qw(
Conflicts
Breaks
Replaces
Provides
Built-Using
Static-Built-Using
);
my @bin_dep_fields = (
@bin_dep_normal_fields,
@bin_dep_union_fields,
);
my @src_checksums = qw(
Checksums-Md5
Checksums-Sha1
Checksums-Sha256
);
my @bin_checksums = qw(
MD5sum
SHA1
SHA256
);
my @src_files = (
@src_checksums,
qw(
Files
),
);
my @bin_files = (
qw(
Filename
Size
),
@bin_checksums,
);
my @vcs_fields = qw(
Vcs-Browser
Vcs-Arch
Vcs-Bzr
Vcs-Cvs
Vcs-Darcs
Vcs-Git
Vcs-Hg
Vcs-Mtn
Vcs-Svn
);
my @test_fields = qw(
Testsuite
Testsuite-Triggers
);
my %fields = (
CTRL_INFO_SRC() => {
name => 'debian/control source stanza',
fields => [
qw(
Source
Section
Priority
Maintainer
Uploaders
Origin
Bugs
),
@vcs_fields,
qw(
Homepage
Standards-Version
Rules-Requires-Root
),
@src_dep_fields,
@test_fields,
qw(
Description
),
],
},
CTRL_INFO_PKG() => {
name => 'debian/control binary stanza',
fields => [
qw(
Package
Package-Type
Section
Priority
Architecture
Subarchitecture
Multi-Arch
Essential
Protected
Build-Essential
Build-Profiles
Built-For-Profiles
Kernel-Version
),
@bin_dep_fields,
qw(
Homepage
Installer-Menu-Item
Task
Tag
Description
),
],
},
CTRL_PKG_SRC() => {
name => '.dsc',
fields => [
qw(
Format
Source
Binary
Architecture
Version
Origin
Maintainer
Uploaders
Homepage
Description
Standards-Version
),
@vcs_fields,
@test_fields,
@src_dep_fields,
qw(
Package-List
),
@src_files,
],
},
CTRL_PKG_DEB() => {
name => 'DEBIAN/control',
fields => [
qw(
Package
Package-Type
Source
Version
Kernel-Version
Built-For-Profiles
Auto-Built-Package
Architecture
Subarchitecture
Installer-Menu-Item
Build-Essential
Essential
Protected
Origin
Bugs
Maintainer
Installed-Size
),
@bin_dep_fields,
qw(
Section
Priority
Multi-Arch
Homepage
Description
Tag
Task
),
],
},
CTRL_INDEX_SRC() => {
name => 'Sources',
fields => [
qw(
Format
Package
Binary
Architecture
Version
Priority
Section
Origin
Maintainer
Uploaders
Homepage
Description
Standards-Version
),
@vcs_fields,
@test_fields,
@src_dep_fields,
qw(
Package-List
Directory
),
@src_files,
],
},
CTRL_INDEX_PKG() => {
name => 'Packages',
fields => [
qw(
Package
Package-Type
Source
Version
Kernel-Version
Built-For-Profiles
Auto-Built-Package
Architecture
Subarchitecture
Installer-Menu-Item
Build-Essential
Essential
Protected
Origin
Bugs
Maintainer
Installed-Size
),
@bin_dep_fields,
@bin_files,
qw(
Section
Priority
Multi-Arch
Homepage
Description
Tag
Task
),
],
},
CTRL_REPO_RELEASE() => {
name => 'Release',
fields => [
qw(
Origin
Label
Suite
Version
Codename
Changelogs
Date
Valid-Until
NotAutomatic
ButAutomaticUpgrades
Acquire-By-Hash
No-Support-for-Architecture-all
Architectures
Components
Description
),
@bin_checksums,
],
},
CTRL_CHANGELOG() => {
name => 'debian/changelog',
fields => [
qw(
Source
Binary-Only
Version
Distribution
Urgency
Maintainer
Timestamp
Date
Closes
Changes
),
],
},
CTRL_COPYRIGHT_HEADER() => {
name => 'debian/copyright Format stanza',
fields => [
qw(
Format
Upstream-Name
Upstream-Contact
Source
Disclaimer
Comment
License
Copyright
),
],
},
CTRL_COPYRIGHT_FILES() => {
name => 'debian/copyright Files stanza',
fields => [
qw(
Files
Copyright
License
Comment
),
],
},
CTRL_COPYRIGHT_LICENSE() => {
name => 'debian/copyright License stanza',
fields => [
qw(
License
Comment
),
],
},
CTRL_TESTS() => {
name => 'debian/tests/control',
fields => [
qw(
Test-Command
Tests
Tests-Directory
Architecture
Restrictions
Features
Classes
Depends
),
],
},
CTRL_FILE_BUILDINFO() => {
name => '.buildinfo',
fields => [
qw(
Format
Source
Binary
Architecture
Version
Binary-Only-Changes
),
@src_checksums,
qw(
Build-Origin
Build-Architecture
Build-Kernel-Version
Build-Date
Build-Path
Build-Tainted-By
Installed-Build-Depends
Environment
),
],
},
CTRL_FILE_CHANGES() => {
name => '.changes',
fields => [
qw(
Format
Date
Source
Binary
Binary-Only
Built-For-Profiles
Architecture
Version
Distribution
Urgency
Maintainer
Changed-By
Description
Closes
Changes
),
@src_files,
],
},
CTRL_FILE_VENDOR() => {
name => 'dpkg origin',
fields => [
qw(
Vendor
Vendor-Url
Bugs
Parent
),
],
},
CTRL_FILE_STATUS() => {
name => 'dpkg status',
fields => [
qw(
Package
Essential
Protected
Status
Priority
Section
Installed-Size
Origin
Maintainer
Bugs
Architecture
Multi-Arch
Source
Version
Config-Version
Replaces
Provides
Depends
Pre-Depends
Recommends
Suggests
Breaks
Conflicts
Enhances
Conffiles
Description
Triggers-Pending
Triggers-Awaited
Auto-Built-Package
Build-Essential
Built-For-Profiles
Built-Using
Static-Built-Using
Homepage
Installer-Menu-Item
Kernel-Version
Package-Type
Subarchitecture
Tag
Task
),
],
},
);
is_deeply([ field_list_src_dep() ],
[ @src_dep_fields ],
'List of build dependencies');
is_deeply([ field_list_pkg_dep() ],
[ @bin_dep_fields ],
'List of build dependencies');
is(field_capitalize('invented-field'), 'Invented-Field',
'Field Invented-Field capitalization');
ok(!field_is_official('invented-field'),
'Field Invented-Field is not official');
my %known_fields;
foreach my $type (sort keys %fields) {
if (not $fields{$type}->{unordered}) {
is_deeply([ field_ordered_list($type) ], $fields{$type}->{fields},
"List of $fields{$type}->{name} fields");
}
foreach my $field (@{$fields{$type}->{fields}}) {
$known_fields{$field} = 1;
}
}
foreach my $field (sort keys %known_fields) {
is(field_capitalize($field), $field, "Field $field capitalization");
is(field_capitalize(lc $field), $field, "Field lc($field) capitalization");
is(field_capitalize(uc $field), $field, "Field uc($field) capitalization");
ok(field_is_official($field), "Field $field is official");
ok(field_is_official(lc $field), "Field lc($field) is official");
ok(field_is_official(uc $field), "Field uc($field) is official");
}
foreach my $type (sort keys %fields) {
my %allowed_fields = map { $_ => 1 } @{$fields{$type}->{fields}};
foreach my $field (sort keys %known_fields) {
if ($allowed_fields{$field}) {
ok(field_is_allowed_in($field, $type),
"Field $field allowed for type $fields{$type}->{name}");
} else {
ok(!field_is_allowed_in($field, $type),
"Field $field not allowed for type $fields{$type}->{name}");
}
}
}
# Check deb822 field parsers
my $ctrl = Dpkg::Control->new(type => CTRL_PKG_DEB);
my ($source, $version);
$ctrl->{Package} = 'test-binary';
$ctrl->{Version} = '2.0-1';
$ctrl->{Source} = 'test-source (1.0)';
($source, $version) = field_parse_binary_source($ctrl);
is($source, 'test-source', 'Source package from binary w/ Source field');
is($version, '1.0', 'Source version from binary w/ Source field');
$ctrl->{Source} = 'test-source';
($source, $version) = field_parse_binary_source($ctrl);
is($source, 'test-source', 'Source package from binary w/ Source field w/o version');
is($version, '2.0-1', 'Source version from binary w/ Source field w/o version');
delete $ctrl->{Source};
($source, $version) = field_parse_binary_source($ctrl);
is($source, 'test-binary', 'Source package from binary w/o Source field');
is($version, '2.0-1', 'Source version from binary w/o Source field');
|