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/>.
19 use Test
::More tests
=> 26;
20 use Test
::Dpkg
qw(:paths);
22 use_ok
('Dpkg::Dist::Files');
24 my $datadir = test_get_data_path
();
28 'pkg-src_4:2.0+1A~rc1-1.dsc' => {
29 filename
=> 'pkg-src_4:2.0+1A~rc1-1.dsc',
34 'pkg-src_4:2.0+1A~rc1-1.tar.xz' => {
35 filename
=> 'pkg-src_4:2.0+1A~rc1-1.tar.xz',
40 'pkg-templ_1.2.3_arch.type' => {
41 filename
=> 'pkg-templ_1.2.3_arch.type',
42 package => 'pkg-templ',
43 package_type
=> 'type',
47 priority
=> 'priority',
50 'pkg-arch_2.0.0_amd64.deb' => {
51 filename
=> 'pkg-arch_2.0.0_amd64.deb',
52 package => 'pkg-arch',
53 package_type
=> 'deb',
57 priority
=> 'required',
60 'pkg-indep_0.0.1-2_all.deb' => {
61 filename
=> 'pkg-indep_0.0.1-2_all.deb',
62 package => 'pkg-indep',
63 package_type
=> 'deb',
67 priority
=> 'standard',
71 filename
=> 'other_0.txt',
73 priority
=> 'optional',
75 'mime-type' => 'text/plain',
79 filename
=> 'BY-HAND-file',
81 priority
=> 'optional',
86 'another:filename' => {
87 filename
=> 'another:filename',
92 'added-on-the-fly' => {
93 filename
=> 'added-on-the-fly',
100 my $dist = Dpkg
::Dist
::Files
->new();
101 $dist->load("$datadir/files-byhand") or error
('cannot parse file');
103 $expected = <<'FILES';
104 BY-HAND-file webdocs optional by-hand=true
105 other_0.txt text optional mime-type=text/plain
106 pkg-arch_2.0.0_amd64.deb admin required
107 pkg-indep_0.0.1-2_all.deb net standard
108 pkg-templ_1.2.3_arch.type section priority
111 is
($dist->output(), $expected, 'Parsed dist file');
112 foreach my $f ($dist->get_files()) {
113 my $filename = $f->{filename
};
115 is_deeply
($f, $expected{$filename},
116 "Detail for individual dist file $filename, via get_files()");
118 my $fs = $dist->get_file($filename);
119 is_deeply
($fs, $expected{$filename},
120 "Detail for individual dist file $filename, via get_file()");
123 is
($dist->parse_filename('file%invalid'), undef, 'invalid filename');
125 $expected = <<'FILES';
126 BY-HAND-file webdocs optional by-hand=true
127 added-on-the-fly void wish
128 other_0.txt text optional mime-type=text/plain
129 pkg-arch_2.0.0_amd64.deb void imperative
130 pkg-templ_1.2.3_arch.type section priority
133 $dist->add_file('added-on-the-fly', 'void', 'wish');
134 is_deeply
($dist->get_file('added-on-the-fly'), $expected{'added-on-the-fly'},
135 'Get added file added-on-the-fly');
137 $dist->add_file('pkg-arch_2.0.0_amd64.deb', 'void', 'imperative');
138 my %expected_pkg_arch = %{$expected{'pkg-arch_2.0.0_amd64.deb'}};
139 $expected_pkg_arch{section
} = 'void';
140 $expected_pkg_arch{priority
} = 'imperative';
141 is_deeply
($dist->get_file('pkg-arch_2.0.0_amd64.deb'), \
%expected_pkg_arch,
142 'Get modified file pkg-arch_2.0.0_amd64.deb');
144 $dist->del_file('pkg-indep_0.0.1-2_all.deb');
145 is
($dist->get_file('unknown'), undef, 'Get unknown file');
146 is
($dist->get_file('pkg-indep_0.0.1-2_all.deb'), undef, 'Get deleted file');
147 is
($dist->output(), $expected, 'Modified dist object');
149 $expected = <<'FILES';
150 another:filename by-hand extra
151 pkg-src_4:2.0+1A~rc1-1.dsc source extra
152 pkg-src_4:2.0+1A~rc1-1.tar.xz source extra
156 $dist->add_file('pkg-src_4:2.0+1A~rc1-1.dsc', 'source', 'extra');
157 $dist->add_file('pkg-src_4:2.0+1A~rc1-1.tar.xz', 'source', 'extra');
158 $dist->add_file('another:filename', 'by-hand', 'extra');
160 is_deeply
($dist->get_file('pkg-src_4:2.0+1A~rc1-1.dsc'),
161 $expected{'pkg-src_4:2.0+1A~rc1-1.dsc'},
162 'Get added file pkg-src_4:2.0+1A~rc1-1.dsc');
163 is_deeply
($dist->get_file('pkg-src_4:2.0+1A~rc1-1.tar.xz'),
164 $expected{'pkg-src_4:2.0+1A~rc1-1.tar.xz'},
165 'Get added file pkg-src_4:2.0+1A~rc1-1.tar.xz');
166 is_deeply
($dist->get_file('another:filename'),
167 $expected{'another:filename'},
168 'Get added file another:filename');
169 is
($dist->output, $expected, 'Added source files');
171 $expected = <<'FILES';
172 BY-HAND-file webdocs optional by-hand=true
173 other_0.txt text optional mime-type=text/plain
174 pkg-arch_2.0.0_amd64.deb admin required
175 pkg-frag-a_0.0_arch.type section priority
176 pkg-frag-b_0.0_arch.type section priority
177 pkg-indep_0.0.1-2_all.deb net standard
178 pkg-templ_1.2.3_arch.type section priority
182 $dist->load_dir($datadir) or error
('cannot parse fragment files');
183 is
($dist->output(), $expected, 'Parse fragment directory');
185 $expected = <<'FILES';
186 pkg-arch_2.0.0_amd64.deb admin required
187 pkg-indep_0.0.1-2_all.deb net standard
188 pkg-templ_1.2.3_arch.type section priority
192 $dist->load("$datadir/files-byhand") or error
('cannot parse file');
193 $dist->filter(remove
=> sub { $_[0]->{priority
} eq 'optional' });
194 is
($dist->output(), $expected, 'Filter remove priority optional');
196 $expected = <<'FILES';
197 BY-HAND-file webdocs optional by-hand=true
198 other_0.txt text optional mime-type=text/plain
202 $dist->load("$datadir/files-byhand") or error
('cannot parse file');
203 $dist->filter(keep
=> sub { $_[0]->{priority
} eq 'optional' });
204 is
($dist->output(), $expected, 'Filter keep priority optional');
206 $expected = <<'FILES';
207 BY-HAND-file webdocs optional by-hand=true
211 $dist->load("$datadir/files-byhand") or error
('cannot parse file');
212 $dist->filter(remove
=> sub { $_[0]->{section
} eq 'text' },
213 keep
=> sub { $_[0]->{priority
} eq 'optional' });
214 is
($dist->output(), $expected, 'Filter remove section text, keep priority optional');