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