po: Update German man pages translation
[dpkg.git] / scripts / t / Dpkg_Changelog.t
blobc4cc8b7a10d2ab2604b8387a438792e7971aca91
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 tests => 102;
20 use Test::Dpkg qw(:paths);
22 use File::Basename;
24 use Dpkg::File;
26 BEGIN {
27 use_ok('Dpkg::Changelog');
28 use_ok('Dpkg::Changelog::Debian');
29 use_ok('Dpkg::Vendor', qw(get_current_vendor));
32 my $datadir = test_get_data_path();
34 my $vendor = get_current_vendor();
36 sub setup_changelog
38 my $name = shift;
39 my $file = "$datadir/$name";
41 my $changes = Dpkg::Changelog::Debian->new(verbose => 0);
42 $changes->load($file);
44 my $content = file_slurp($file);
45 cmp_ok($content, 'eq', "$changes", "string output of Dpkg::Changelog on $file");
47 my $errors = $changes->get_parse_errors();
48 my $basename = basename($file);
49 is($errors, '', "Parse example changelog $file without errors");
51 my @data = @$changes;
52 ok(@data, "data from $file is not empty");
54 SKIP: {
55 skip('avoid spurious warning with only one entry', 2)
56 if @data == 1;
58 my $str;
59 my $oldest_version = $data[-1]->{Version};
60 $str = $changes->format_range('dpkg', { since => $oldest_version });
62 $str = $changes->format_range('rfc822');
64 ok(1, 'TODO check rfc822 output');
66 $str = $changes->format_range('rfc822', { since => $oldest_version });
68 ok(1, 'TODO check rfc822 output with ranges');
71 return ($changes, \@data);
74 #########################
76 my $changes;
77 my $data;
80 ## File: countme
82 ($changes, $data) = setup_changelog('countme');
84 # Test range options.
85 cmp_ok(@{$data}, '==', 7, 'no options -> count');
86 my $all_versions = join('/', map { $_->get_version() } @{$data});
88 sub check_options {
89 my (%opts) = @_;
91 my @cnt = $changes->get_range($opts{range});
92 cmp_ok(@cnt, '==', $opts{count}, "$opts{name} -> count");
93 if ($opts{count} == @{$opts{data}}) {
94 is_deeply(\@cnt, $opts{data}, "$opts{name} -> returns all");
95 } else {
96 is_deeply([ map { $_->get_version() } @cnt ],
97 $opts{versions}, "$opts{name} -> versions");
101 my %ref = (
102 changes => $changes,
103 data => $data,
106 check_options(%ref, range => { count => 3 },
107 count => 3,
108 versions => [ '2:2.0-1', '1:2.0~rc2-3', '1:2.0~rc2-2' ],
109 name => 'positive count');
110 check_options(%ref, range => { count => 3, reverse => 1 },
111 count => 3,
112 versions => [ '1:2.0~rc2-2', '1:2.0~rc2-3', '2:2.0-1' ],
113 name => 'positive reverse count');
114 check_options(%ref, range => { count => -3 },
115 count => 3,
116 versions => [
117 '1:2.0~rc2-1sarge2',
118 '1:2.0~rc2-1sarge1',
119 '1.5-1',
121 name => 'negative count');
122 check_options(%ref, range => { count => 1 },
123 count => 1,
124 versions => [ '2:2.0-1' ],
125 name => 'count 1');
126 check_options(%ref, range => { count => 1, default_all => 1 },
127 count => 1,
128 versions => [ '2:2.0-1' ],
129 name => 'count 1 (d_a 1)');
130 check_options(%ref, range => { count => -1 },
131 count => 1,
132 versions => [ '1.5-1' ],
133 name => 'count -1');
135 check_options(%ref, range => { count => 3, offset => 2 },
136 count => 3,
137 versions => [
138 '1:2.0~rc2-2',
139 '1:2.0~rc2-1sarge3',
140 '1:2.0~rc2-1sarge2',
142 name => 'positive count + positive offset');
143 check_options(%ref, range => { count => -3, offset => 4 },
144 count => 3,
145 versions => [
146 '1:2.0~rc2-3',
147 '1:2.0~rc2-2',
148 '1:2.0~rc2-1sarge3',
150 name => 'negative count + positive offset');
152 check_options(%ref, range => { count => 4, offset => 5 },
153 count => 2,
154 versions => [ '1:2.0~rc2-1sarge1', '1.5-1' ],
155 name => 'positive count + positive offset (>max)');
156 check_options(%ref, range => { count => -4, offset => 2 },
157 count => 2,
158 versions => [ '2:2.0-1', '1:2.0~rc2-3' ],
159 name => 'negative count + positive offset (<0)');
161 check_options(%ref, range => { count => 3, offset => -4 },
162 count => 3,
163 versions => [
164 '1:2.0~rc2-1sarge3',
165 '1:2.0~rc2-1sarge2',
166 '1:2.0~rc2-1sarge1',
168 name => 'positive count + negative offset');
169 check_options(%ref, range => { count => -3, offset => -3 },
170 count => 3,
171 versions => [
172 '1:2.0~rc2-3',
173 '1:2.0~rc2-2',
174 '1:2.0~rc2-1sarge3',
176 name => 'negative count + negative offset');
178 check_options(%ref, range => { count => 5, offset => -2 },
179 count => 2,
180 versions => [ '1:2.0~rc2-1sarge1', '1.5-1' ],
181 name => 'positive count + negative offset (>max)');
182 check_options(%ref, range => { count => -5, offset => -4 },
183 count => 3,
184 versions => [ '2:2.0-1', '1:2.0~rc2-3', '1:2.0~rc2-2' ],
185 name => 'negative count + negative offset (<0)');
187 check_options(%ref, range => { count => 7 },
188 count => 7,
189 name => 'count 7 (max)');
190 check_options(%ref, range => { count => -7 },
191 count => 7,
192 name => 'count -7 (-max)');
193 check_options(%ref, range => { count => 10 },
194 count => 7,
195 name => 'count 10 (>max)');
196 check_options(%ref, range => { count => -10 },
197 count => 7,
198 name => 'count -10 (<-max)');
200 check_options(%ref, range => { from => '1:2.0~rc2-1sarge3' },
201 count => 4,
202 versions => [
203 '2:2.0-1',
204 '1:2.0~rc2-3',
205 '1:2.0~rc2-2',
206 '1:2.0~rc2-1sarge3',
208 name => 'from => "1:2.0~rc2-1sarge3"');
209 check_options(%ref, range => { since => '1:2.0~rc2-1sarge3' },
210 count => 3,
211 versions => [
212 '2:2.0-1',
213 '1:2.0~rc2-3',
214 '1:2.0~rc2-2',
216 name => 'since => "1:2.0~rc2-1sarge3"');
217 $SIG{__WARN__} = sub {};
218 check_options(%ref, range => { since => 0 },
219 count => 7,
220 name => 'since => 0 returns all');
221 delete $SIG{__WARN__};
222 check_options(%ref, range => { to => '1:2.0~rc2-1sarge2' },
223 count => 3,
224 versions => [
225 '1:2.0~rc2-1sarge2',
226 '1:2.0~rc2-1sarge1',
227 '1.5-1',
229 name => 'to => "1:2.0~rc2-1sarge2"');
230 ## no critic (ControlStructures::ProhibitUntilBlocks)
231 check_options(%ref, range => { until => '1:2.0~rc2-1sarge2' },
232 count => 2,
233 versions => [ '1:2.0~rc2-1sarge1', '1.5-1' ],
234 name => 'until => "1:2.0~rc2-1sarge2"');
235 ## use critic
236 #TODO: test combinations
239 ## File: shadow
241 ($changes, $data) = setup_changelog('shadow');
244 ## File: fields
246 ($changes, $data) = setup_changelog('fields');
248 my $str = $changes->format_range('dpkg', { all => 1 });
249 my $expected = 'Source: fields
250 Version: 2.0-0etch1
251 Distribution: stable
252 Urgency: high
253 Maintainer: Frank Lichtenheld <frank@lichtenheld.de>
254 Timestamp: 1200235759
255 Date: Sun, 13 Jan 2008 15:49:19 +0100
256 Closes: 1000000 1111111 2222222
257 Changes:
258 fields (2.0-0etch1) stable; urgency=low
260 * Upload to stable (Closes: #1111111, #2222222)
261 * Fix more stuff. (LP: #54321, #2424242)
263 fields (2.0-1) unstable frozen; urgency=medium
265 [ Frank Lichtenheld ]
266 * Upload to unstable (Closes: #1111111, #2222222)
267 * Fix stuff. (LP: #12345, #424242)
269 [ Raphaël Hertzog ]
270 * New upstream release.
271 - implements a
272 - implements b
273 * Update S-V.
275 fields (2.0~b1-1) unstable; urgency=low,xc-userfield=foobar
277 * Beta
279 fields (1.0) experimental; urgency=high,xb-userfield2=foobar
281 * First upload (Closes: #1000000)
282 Xb-Userfield2: foobar
283 Xc-Userfield: foobar
286 if ($vendor eq 'Ubuntu') {
287 $expected =~ s/^(Closes:.*)/$1\nLaunchpad-Bugs-Fixed: 12345 54321 424242 2424242/m;
289 cmp_ok($str, 'eq', $expected, 'fields handling');
291 $str = $changes->format_range('dpkg', { offset => 1, count => 2 });
292 $expected = 'Source: fields
293 Version: 2.0-1
294 Distribution: unstable frozen
295 Urgency: medium
296 Maintainer: Frank Lichtenheld <djpig@debian.org>
297 Timestamp: 1200149359
298 Date: Sun, 12 Jan 2008 15:49:19 +0100
299 Closes: 1111111 2222222
300 Changes:
301 fields (2.0-1) unstable frozen; urgency=medium
303 [ Frank Lichtenheld ]
304 * Upload to unstable (Closes: #1111111, #2222222)
305 * Fix stuff. (LP: #12345, #424242)
307 [ Raphaël Hertzog ]
308 * New upstream release.
309 - implements a
310 - implements b
311 * Update S-V.
313 fields (2.0~b1-1) unstable; urgency=low,xc-userfield=foobar
315 * Beta
316 Xc-Userfield: foobar
319 if ($vendor eq 'Ubuntu') {
320 $expected =~ s/^(Closes:.*)/$1\nLaunchpad-Bugs-Fixed: 12345 424242/m;
322 cmp_ok($str, 'eq', $expected, 'fields handling 2');
324 $str = $changes->format_range('rfc822', { offset => 2, count => 2 });
325 $expected = 'Source: fields
326 Version: 2.0~b1-1
327 Distribution: unstable
328 Urgency: low
329 Maintainer: Frank Lichtenheld <frank@lichtenheld.de>
330 Timestamp: 1200062959
331 Date: Sun, 11 Jan 2008 15:49:19 +0100
332 Changes:
333 fields (2.0~b1-1) unstable; urgency=low,xc-userfield=foobar
335 * Beta
336 Xc-Userfield: foobar
338 Source: fields
339 Version: 1.0
340 Distribution: experimental
341 Urgency: high
342 Maintainer: Frank Lichtenheld <djpig@debian.org>
343 Timestamp: 1199976559
344 Date: Sun, 10 Jan 2008 15:49:19 +0100
345 Closes: 1000000
346 Changes:
347 fields (1.0) experimental; urgency=high,xb-userfield2=foobar
349 * First upload (Closes: #1000000)
350 Xb-Userfield2: foobar
353 cmp_ok($str, 'eq', $expected, 'fields handling 3');
355 # Test Dpkg::Changelog::Entry methods
356 is($data->[1]->get_version(), '2.0-1', 'get_version');
357 is($data->[1]->get_source(), 'fields', 'get_source');
358 is(scalar $data->[1]->get_distributions(), 'unstable', 'get_distribution');
359 is(join('|', $data->[1]->get_distributions()), 'unstable|frozen',
360 'get_distributions');
361 is($data->[3]->get_optional_fields(),
362 "Urgency: high\nCloses: 1000000\nXb-Userfield2: foobar\n",
363 'get_optional_fields');
364 is($data->[1]->get_maintainer(), 'Frank Lichtenheld <djpig@debian.org>',
365 'get_maintainer');
366 is($data->[1]->get_timestamp(), 'Sun, 12 Jan 2008 15:49:19 +0100',
367 'get_timestamp');
368 my @items = $data->[1]->get_change_items();
369 is($items[0], " [ Frank Lichtenheld ]\n", 'change items 1');
370 is($items[4], ' * New upstream release.
371 - implements a
372 - implements b
373 ', 'change items 2');
374 is($items[5], " * Update S-V.\n", 'change items 3');
377 ## File: date-format
379 ($changes, $data) = setup_changelog('date-format');
381 is($data->[0]->get_timestamp(), '01 Jul 2100 23:59:59 -1200',
382 'get date w/o DoW, and negative timezone offset');
383 is($data->[1]->get_timestamp(), 'Tue, 27 Feb 2050 12:00:00 +1245',
384 'get date w/ DoW, and positive timezone offset');
385 is($data->[2]->get_timestamp(), 'Mon, 01 Jan 2000 00:00:00 +0000',
386 'get date w/ DoW, and zero timezone offset');
389 ## File: stop-modeline
391 ($changes, $data) = setup_changelog('stop-modeline');
393 is($changes->get_unparsed_tail(), "vim: et\n",
394 'get unparsed modeline at EOF');
397 ## File: regressions
399 ($changes, $data) = setup_changelog('regressions');
401 my $f = ($changes->format_range('dpkg'))[0];
402 is("$f->{Version}", '0', 'version 0 correctly parsed');
405 ## Files
407 foreach my $test (([ "$datadir/misplaced-tz", 6 ],
408 [ "$datadir/unreleased", 5, 7 ])) {
410 my $file = shift @$test;
411 my $changes = Dpkg::Changelog::Debian->new(verbose => 0);
412 $changes->load($file);
413 my @errors = $changes->get_parse_errors();
415 ok(@errors, 'errors occured');
416 is_deeply([ map { $_->[1] } @errors ], $test, 'check line numbers');