dpkg (1.18.25) stretch; urgency=medium
[dpkg] / scripts / t / Dpkg_Dist_Files.t
CommitLineData
1479465f
GJ
1#!/usr/bin/perl
2#
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.
7#
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.
12#
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/>.
15
16use strict;
17use warnings;
18
19use Test::More tests => 26;
20use Test::Dpkg qw(:paths);
21
22use_ok('Dpkg::Dist::Files');
23
24my $datadir = test_get_data_path('t/Dpkg_Dist_Files');
25
26my $expected;
27my %expected = (
28 'pkg-src_4:2.0+1A~rc1-1.dsc' => {
29 filename => 'pkg-src_4:2.0+1A~rc1-1.dsc',
30 section => 'source',
31 priority => 'extra',
32 },
33 'pkg-src_4:2.0+1A~rc1-1.tar.xz' => {
34 filename => 'pkg-src_4:2.0+1A~rc1-1.tar.xz',
35 section => 'source',
36 priority => 'extra',
37 },
38 'pkg-templ_1.2.3_arch.type' => {
39 filename => 'pkg-templ_1.2.3_arch.type',
40 package => 'pkg-templ',
41 package_type => 'type',
42 version => '1.2.3',
43 arch => 'arch',
44 section => 'section',
45 priority => 'priority',
46 },
47 'pkg-arch_2.0.0_amd64.deb' => {
48 filename => 'pkg-arch_2.0.0_amd64.deb',
49 package => 'pkg-arch',
50 package_type => 'deb',
51 version => '2.0.0',
52 arch => 'amd64',
53 section => 'admin',
54 priority => 'required',
55 },
56 'pkg-indep_0.0.1-2_all.deb' => {
57 filename => 'pkg-indep_0.0.1-2_all.deb',
58 package => 'pkg-indep',
59 package_type => 'deb',
60 version => '0.0.1-2',
61 arch => 'all',
62 section => 'net',
63 priority => 'standard',
64 },
65 'other_0.txt' => {
66 filename => 'other_0.txt',
67 section => 'text',
68 priority => 'optional',
69 },
70 'BY-HAND-file' => {
71 filename => 'BY-HAND-file',
72 section => 'webdocs',
73 priority => 'optional',
74 },
75 'another:filename' => {
76 filename => 'another:filename',
77 section => 'by-hand',
78 priority => 'extra',
79 },
80 'added-on-the-fly' => {
81 filename => 'added-on-the-fly',
82 section => 'void',
83 priority => 'wish',
84 },
85);
86
87my $dist = Dpkg::Dist::Files->new();
88$dist->load("$datadir/files-byhand") or error('cannot parse file');
89
90$expected = <<'FILES';
91BY-HAND-file webdocs optional
92other_0.txt text optional
93pkg-arch_2.0.0_amd64.deb admin required
94pkg-indep_0.0.1-2_all.deb net standard
95pkg-templ_1.2.3_arch.type section priority
96FILES
97
98is($dist->output(), $expected, 'Parsed dist file');
99foreach my $f ($dist->get_files()) {
100 my $filename = $f->{filename};
101
102 is_deeply($f, $expected{$filename},
103 "Detail for individual dist file $filename, via get_files()");
104
105 my $fs = $dist->get_file($filename);
106 is_deeply($fs, $expected{$filename},
107 "Detail for individual dist file $filename, via get_file()");
108}
109
110is($dist->parse_filename('file%invalid'), undef, 'invalid filename');
111
112$expected = <<'FILES';
113BY-HAND-file webdocs optional
114added-on-the-fly void wish
115other_0.txt text optional
116pkg-arch_2.0.0_amd64.deb void imperative
117pkg-templ_1.2.3_arch.type section priority
118FILES
119
120$dist->add_file('added-on-the-fly', 'void', 'wish');
121is_deeply($dist->get_file('added-on-the-fly'), $expected{'added-on-the-fly'},
122 'Get added file added-on-the-fly');
123
124$dist->add_file('pkg-arch_2.0.0_amd64.deb', 'void', 'imperative');
125my %expected_pkg_arch = %{$expected{'pkg-arch_2.0.0_amd64.deb'}};
126$expected_pkg_arch{section} = 'void';
127$expected_pkg_arch{priority} = 'imperative';
128is_deeply($dist->get_file('pkg-arch_2.0.0_amd64.deb'), \%expected_pkg_arch,
129 'Get modified file pkg-arch_2.0.0_amd64.deb');
130
131$dist->del_file('pkg-indep_0.0.1-2_all.deb');
132is($dist->get_file('unknown'), undef, 'Get unknown file');
133is($dist->get_file('pkg-indep_0.0.1-2_all.deb'), undef, 'Get deleted file');
134is($dist->output(), $expected, 'Modified dist object');
135
136$expected = <<'FILES';
137another:filename by-hand extra
138pkg-src_4:2.0+1A~rc1-1.dsc source extra
139pkg-src_4:2.0+1A~rc1-1.tar.xz source extra
140FILES
141
142$dist->reset();
143$dist->add_file('pkg-src_4:2.0+1A~rc1-1.dsc', 'source', 'extra');
144$dist->add_file('pkg-src_4:2.0+1A~rc1-1.tar.xz', 'source', 'extra');
145$dist->add_file('another:filename', 'by-hand', 'extra');
146
147is_deeply($dist->get_file('pkg-src_4:2.0+1A~rc1-1.dsc'),
148 $expected{'pkg-src_4:2.0+1A~rc1-1.dsc'},
149 'Get added file pkg-src_4:2.0+1A~rc1-1.dsc');
150is_deeply($dist->get_file('pkg-src_4:2.0+1A~rc1-1.tar.xz'),
151 $expected{'pkg-src_4:2.0+1A~rc1-1.tar.xz'},
152 'Get added file pkg-src_4:2.0+1A~rc1-1.tar.xz');
153is_deeply($dist->get_file('another:filename'),
154 $expected{'another:filename'},
155 'Get added file another:filename');
156is($dist->output, $expected, 'Added source files');
157
158$expected = <<'FILES';
159BY-HAND-file webdocs optional
160other_0.txt text optional
161pkg-arch_2.0.0_amd64.deb admin required
162pkg-frag-a_0.0_arch.type section priority
163pkg-frag-b_0.0_arch.type section priority
164pkg-indep_0.0.1-2_all.deb net standard
165pkg-templ_1.2.3_arch.type section priority
166FILES
167
168$dist->reset();
169$dist->load_dir($datadir) or error('cannot parse fragment files');
170is($dist->output(), $expected, 'Parse fragment directory');
171
172$expected = <<'FILES';
173pkg-arch_2.0.0_amd64.deb admin required
174pkg-indep_0.0.1-2_all.deb net standard
175pkg-templ_1.2.3_arch.type section priority
176FILES
177
178$dist->reset();
179$dist->load("$datadir/files-byhand") or error('cannot parse file');
180$dist->filter(remove => sub { $_[0]->{priority} eq 'optional' });
181is($dist->output(), $expected, 'Filter remove priority optional');
182
183$expected = <<'FILES';
184BY-HAND-file webdocs optional
185other_0.txt text optional
186FILES
187
188$dist->reset();
189$dist->load("$datadir/files-byhand") or error('cannot parse file');
190$dist->filter(keep => sub { $_[0]->{priority} eq 'optional' });
191is($dist->output(), $expected, 'Filter keep priority optional');
192
193$expected = <<'FILES';
194BY-HAND-file webdocs optional
195FILES
196
197$dist->reset();
198$dist->load("$datadir/files-byhand") or error('cannot parse file');
199$dist->filter(remove => sub { $_[0]->{section} eq 'text' },
200 keep => sub { $_[0]->{priority} eq 'optional' });
201is($dist->output(), $expected, 'Filter remove section text, keep priority optional');
202
2031;