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
=> 102;
20 use Test
::Dpkg
qw(:paths);
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
();
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");
52 ok
(@data, "data from $file is not empty");
55 skip
('avoid spurious warning with only one entry', 2)
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 #########################
82 ($changes, $data) = setup_changelog
('countme');
85 cmp_ok
(@
{$data}, '==', 7, 'no options -> count');
86 my $all_versions = join('/', map { $_->get_version() } @
{$data});
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");
96 is_deeply
([ map { $_->get_version() } @cnt ],
97 $opts{versions
}, "$opts{name} -> versions");
106 check_options
(%ref, range
=> { 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 },
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 },
121 name
=> 'negative count');
122 check_options
(%ref, range
=> { count
=> 1 },
124 versions
=> [ '2:2.0-1' ],
126 check_options
(%ref, range
=> { count
=> 1, default_all
=> 1 },
128 versions
=> [ '2:2.0-1' ],
129 name
=> 'count 1 (d_a 1)');
130 check_options
(%ref, range
=> { count
=> -1 },
132 versions
=> [ '1.5-1' ],
135 check_options
(%ref, range
=> { count
=> 3, offset
=> 2 },
142 name
=> 'positive count + positive offset');
143 check_options
(%ref, range
=> { count
=> -3, offset
=> 4 },
150 name
=> 'negative count + positive offset');
152 check_options
(%ref, range
=> { count
=> 4, offset
=> 5 },
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 },
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 },
168 name
=> 'positive count + negative offset');
169 check_options
(%ref, range
=> { count
=> -3, offset
=> -3 },
176 name
=> 'negative count + negative offset');
178 check_options
(%ref, range
=> { count
=> 5, offset
=> -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 },
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 },
189 name
=> 'count 7 (max)');
190 check_options
(%ref, range
=> { count
=> -7 },
192 name
=> 'count -7 (-max)');
193 check_options
(%ref, range
=> { count
=> 10 },
195 name
=> 'count 10 (>max)');
196 check_options
(%ref, range
=> { count
=> -10 },
198 name
=> 'count -10 (<-max)');
200 check_options
(%ref, range
=> { from
=> '1:2.0~rc2-1sarge3' },
208 name
=> 'from => "1:2.0~rc2-1sarge3"');
209 check_options
(%ref, range
=> { since
=> '1:2.0~rc2-1sarge3' },
216 name
=> 'since => "1:2.0~rc2-1sarge3"');
217 $SIG{__WARN__
} = sub {};
218 check_options
(%ref, range
=> { since
=> 0 },
220 name
=> 'since => 0 returns all');
221 delete $SIG{__WARN__
};
222 check_options
(%ref, range
=> { to
=> '1:2.0~rc2-1sarge2' },
229 name
=> 'to => "1:2.0~rc2-1sarge2"');
230 ## no critic (ControlStructures::ProhibitUntilBlocks)
231 check_options
(%ref, range
=> { until => '1:2.0~rc2-1sarge2' },
233 versions
=> [ '1:2.0~rc2-1sarge1', '1.5-1' ],
234 name
=> 'until => "1:2.0~rc2-1sarge2"');
236 #TODO: test combinations
241 ($changes, $data) = setup_changelog
('shadow');
246 ($changes, $data) = setup_changelog
('fields');
248 my $str = $changes->format_range('dpkg', { all
=> 1 });
249 my $expected = 'Source: fields
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
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)
270 * New upstream release.
275 fields (2.0~b1-1) unstable; urgency=low,xc-userfield=foobar
279 fields (1.0) experimental; urgency=high,xb-userfield2=foobar
281 * First upload (Closes: #1000000)
282 Xb-Userfield2: 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
294 Distribution: unstable frozen
296 Maintainer: Frank Lichtenheld <djpig@debian.org>
297 Timestamp: 1200149359
298 Date: Sun, 12 Jan 2008 15:49:19 +0100
299 Closes: 1111111 2222222
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)
308 * New upstream release.
313 fields (2.0~b1-1) unstable; urgency=low,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
327 Distribution: unstable
329 Maintainer: Frank Lichtenheld <frank@lichtenheld.de>
330 Timestamp: 1200062959
331 Date: Sun, 11 Jan 2008 15:49:19 +0100
333 fields (2.0~b1-1) unstable; urgency=low,xc-userfield=foobar
340 Distribution: experimental
342 Maintainer: Frank Lichtenheld <djpig@debian.org>
343 Timestamp: 1199976559
344 Date: Sun, 10 Jan 2008 15:49:19 +0100
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>',
366 is
($data->[1]->get_timestamp(), 'Sun, 12 Jan 2008 15:49:19 +0100',
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.
373 ', 'change items 2');
374 is
($items[5], " * Update S-V.\n", 'change items 3');
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');
399 ($changes, $data) = setup_changelog
('regressions');
401 my $f = ($changes->format_range('dpkg'))[0];
402 is
("$f->{Version}", '0', 'version 0 correctly parsed');
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');