chiark / gitweb /
lib/dpkg/tarfn.c: Kludge `tar_header_decode' to handle spurious `errno'.
[dpkg] / scripts / t / Dpkg_Dist_Files.t
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
16 use strict;
17 use warnings;
18
19 use Test::More tests => 26;
20 use Test::Dpkg qw(:paths);
21
22 use_ok('Dpkg::Dist::Files');
23
24 my $datadir = test_get_data_path('t/Dpkg_Dist_Files');
25
26 my $expected;
27 my %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
87 my $dist = Dpkg::Dist::Files->new();
88 $dist->load("$datadir/files-byhand") or error('cannot parse file');
89
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
96 FILES
97
98 is($dist->output(), $expected, 'Parsed dist file');
99 foreach 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
110 is($dist->parse_filename('file%invalid'), undef, 'invalid filename');
111
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
118 FILES
119
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');
123
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');
130
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');
135
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
140 FILES
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
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');
157
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
166 FILES
167
168 $dist->reset();
169 $dist->load_dir($datadir) or error('cannot parse fragment files');
170 is($dist->output(), $expected, 'Parse fragment directory');
171
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
176 FILES
177
178 $dist->reset();
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');
182
183 $expected = <<'FILES';
184 BY-HAND-file webdocs optional
185 other_0.txt text optional
186 FILES
187
188 $dist->reset();
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');
192
193 $expected = <<'FILES';
194 BY-HAND-file webdocs optional
195 FILES
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' });
201 is($dist->output(), $expected, 'Filter remove section text, keep priority optional');
202
203 1;