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('t/Dpkg_Dist_Files');
28 'pkg-src_4:2.0+1A~rc1-1.dsc' => {
29 filename => 'pkg-src_4:2.0+1A~rc1-1.dsc',
33 'pkg-src_4:2.0+1A~rc1-1.tar.xz' => {
34 filename => 'pkg-src_4:2.0+1A~rc1-1.tar.xz',
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',
45 priority => 'priority',
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',
54 priority => 'required',
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',
63 priority => 'standard',
66 filename => 'other_0.txt',
68 priority => 'optional',
71 filename => 'BY-HAND-file',
73 priority => 'optional',
75 'another:filename' => {
76 filename => 'another:filename',
80 'added-on-the-fly' => {
81 filename => 'added-on-the-fly',
87 my $dist = Dpkg::Dist::Files->new();
88 $dist->load("$datadir/files-byhand") or error('cannot parse file');
90 $expected = <<'FILES';
91 BY-HAND-file webdocs optional
92 other_0.txt text optional
93 pkg-arch_2.0.0_amd64.deb admin required
94 pkg-indep_0.0.1-2_all.deb net standard
95 pkg-templ_1.2.3_arch.type section priority
98 is($dist->output(), $expected, 'Parsed dist file');
99 foreach my $f ($dist->get_files()) {
100 my $filename = $f->{filename};
102 is_deeply($f, $expected{$filename},
103 "Detail for individual dist file $filename, via get_files()");
105 my $fs = $dist->get_file($filename);
106 is_deeply($fs, $expected{$filename},
107 "Detail for individual dist file $filename, via get_file()");
110 is($dist->parse_filename('file%invalid'), undef, 'invalid filename');
112 $expected = <<'FILES';
113 BY-HAND-file webdocs optional
114 added-on-the-fly void wish
115 other_0.txt text optional
116 pkg-arch_2.0.0_amd64.deb void imperative
117 pkg-templ_1.2.3_arch.type section priority
120 $dist->add_file('added-on-the-fly', 'void', 'wish');
121 is_deeply($dist->get_file('added-on-the-fly'), $expected{'added-on-the-fly'},
122 'Get added file added-on-the-fly');
124 $dist->add_file('pkg-arch_2.0.0_amd64.deb', 'void', 'imperative');
125 my %expected_pkg_arch = %{$expected{'pkg-arch_2.0.0_amd64.deb'}};
126 $expected_pkg_arch{section} = 'void';
127 $expected_pkg_arch{priority} = 'imperative';
128 is_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');
131 $dist->del_file('pkg-indep_0.0.1-2_all.deb');
132 is($dist->get_file('unknown'), undef, 'Get unknown file');
133 is($dist->get_file('pkg-indep_0.0.1-2_all.deb'), undef, 'Get deleted file');
134 is($dist->output(), $expected, 'Modified dist object');
136 $expected = <<'FILES';
137 another:filename by-hand extra
138 pkg-src_4:2.0+1A~rc1-1.dsc source extra
139 pkg-src_4:2.0+1A~rc1-1.tar.xz source extra
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');
147 is_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');
150 is_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');
153 is_deeply($dist->get_file('another:filename'),
154 $expected{'another:filename'},
155 'Get added file another:filename');
156 is($dist->output, $expected, 'Added source files');
158 $expected = <<'FILES';
159 BY-HAND-file webdocs optional
160 other_0.txt text optional
161 pkg-arch_2.0.0_amd64.deb admin required
162 pkg-frag-a_0.0_arch.type section priority
163 pkg-frag-b_0.0_arch.type section priority
164 pkg-indep_0.0.1-2_all.deb net standard
165 pkg-templ_1.2.3_arch.type section priority
169 $dist->load_dir($datadir) or error('cannot parse fragment files');
170 is($dist->output(), $expected, 'Parse fragment directory');
172 $expected = <<'FILES';
173 pkg-arch_2.0.0_amd64.deb admin required
174 pkg-indep_0.0.1-2_all.deb net standard
175 pkg-templ_1.2.3_arch.type section priority
179 $dist->load("$datadir/files-byhand") or error('cannot parse file');
180 $dist->filter(remove => sub { $_[0]->{priority} eq 'optional' });
181 is($dist->output(), $expected, 'Filter remove priority optional');
183 $expected = <<'FILES';
184 BY-HAND-file webdocs optional
185 other_0.txt text optional
189 $dist->load("$datadir/files-byhand") or error('cannot parse file');
190 $dist->filter(keep => sub { $_[0]->{priority} eq 'optional' });
191 is($dist->output(), $expected, 'Filter keep priority optional');
193 $expected = <<'FILES';
194 BY-HAND-file webdocs optional
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' });
201 is($dist->output(), $expected, 'Filter remove section text, keep priority optional');