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
();
36 #########################
38 foreach my $file ("$datadir/countme", "$datadir/shadow", "$datadir/fields",
39 "$datadir/regressions", "$datadir/date-format", "$datadir/stop-modeline") {
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 is not empty');
54 if ($file eq "$datadir/countme") {
56 cmp_ok
(@data, '==', 7, 'no options -> count');
57 my $all_versions = join( '/', map { $_->get_version() } @data);
62 my @cnt = $changes->get_range($opts{range
});
63 cmp_ok
(@cnt, '==', $opts{count
}, "$opts{name} -> count");
64 if ($opts{count
} == @
{$opts{data
}}) {
65 is_deeply
(\
@cnt, $opts{data
}, "$opts{name} -> returns all");
67 is_deeply
([ map { $_->get_version() } @cnt ],
68 $opts{versions
}, "$opts{name} -> versions" );
77 check_options
(%ref, range
=> { count
=> 3 },
79 versions
=> [ '2:2.0-1', '1:2.0~rc2-3', '1:2.0~rc2-2' ],
80 name
=> 'positive count');
81 check_options
(%ref, range
=> { count
=> 3, reverse => 1 },
83 versions
=> [ '1:2.0~rc2-2', '1:2.0~rc2-3', '2:2.0-1' ],
84 name
=> 'positive reverse count');
85 check_options
(%ref, range
=> { count
=> -3 },
92 name
=> 'negative count');
93 check_options
(%ref, range
=> { count
=> 1 },
95 versions
=> [ '2:2.0-1' ],
97 check_options
(%ref, range
=> { count
=> 1, default_all
=> 1 },
99 versions
=> [ '2:2.0-1' ],
100 name
=> 'count 1 (d_a 1)');
101 check_options
(%ref, range
=> { count
=> -1 },
103 versions
=> [ '1.5-1' ],
106 check_options
(%ref, range
=> { count
=> 3, offset
=> 2 },
113 name
=> 'positive count + positive offset');
114 check_options
(%ref, range
=> { count
=> -3, offset
=> 4 },
121 name
=> 'negative count + positive offset');
123 check_options
(%ref, range
=> { count
=> 4, offset
=> 5 },
125 versions
=> [ '1:2.0~rc2-1sarge1', '1.5-1' ],
126 name
=> 'positive count + positive offset (>max)');
127 check_options
(%ref, range
=> { count
=> -4, offset
=> 2 },
129 versions
=> [ '2:2.0-1', '1:2.0~rc2-3' ],
130 name
=> 'negative count + positive offset (<0)');
132 check_options
(%ref, range
=> { count
=> 3, offset
=> -4 },
139 name
=> 'positive count + negative offset');
140 check_options
(%ref, range
=> { count
=> -3, offset
=> -3 },
147 name
=> 'negative count + negative offset');
149 check_options
(%ref, range
=> { count
=> 5, offset
=> -2 },
151 versions
=> [ '1:2.0~rc2-1sarge1', '1.5-1' ],
152 name
=> 'positive count + negative offset (>max)');
153 check_options
(%ref, range
=> { count
=> -5, offset
=> -4 },
155 versions
=> [ '2:2.0-1', '1:2.0~rc2-3', '1:2.0~rc2-2' ],
156 name
=> 'negative count + negative offset (<0)');
158 check_options
(%ref, range
=> { count
=> 7 },
160 name
=> 'count 7 (max)');
161 check_options
(%ref, range
=> { count
=> -7 },
163 name
=> 'count -7 (-max)');
164 check_options
(%ref, range
=> { count
=> 10 },
166 name
=> 'count 10 (>max)');
167 check_options
(%ref, range
=> { count
=> -10 },
169 name
=> 'count -10 (<-max)');
171 check_options
(%ref, range
=> { from
=> '1:2.0~rc2-1sarge3' },
179 name
=> 'from => "1:2.0~rc2-1sarge3"');
180 check_options
(%ref, range
=> { since
=> '1:2.0~rc2-1sarge3' },
187 name
=> 'since => "1:2.0~rc2-1sarge3"');
188 $SIG{__WARN__
} = sub {};
189 check_options
(%ref, range
=> { since
=> 0 },
191 name
=> 'since => 0 returns all');
192 delete $SIG{__WARN__
};
193 check_options
(%ref, range
=> { to
=> '1:2.0~rc2-1sarge2' },
200 name
=> 'to => "1:2.0~rc2-1sarge2"');
201 ## no critic (ControlStructures::ProhibitUntilBlocks)
202 check_options
(%ref, range
=> { until => '1:2.0~rc2-1sarge2' },
204 versions
=> [ '1:2.0~rc2-1sarge1', '1.5-1' ],
205 name
=> 'until => "1:2.0~rc2-1sarge2"');
207 #TODO: test combinations
209 if ($file eq "$datadir/fields") {
210 my $str = $changes->format_range('dpkg', { all
=> 1 });
211 my $expected = 'Source: fields
215 Maintainer: Frank Lichtenheld <frank@lichtenheld.de>
216 Timestamp: 1200235759
217 Date: Sun, 13 Jan 2008 15:49:19 +0100
218 Closes: 1000000 1111111 2222222
220 fields (2.0-0etch1) stable; urgency=low
222 * Upload to stable (Closes: #1111111, #2222222)
223 * Fix more stuff. (LP: #54321, #2424242)
225 fields (2.0-1) unstable frozen; urgency=medium
227 [ Frank Lichtenheld ]
228 * Upload to unstable (Closes: #1111111, #2222222)
229 * Fix stuff. (LP: #12345, #424242)
232 * New upstream release.
237 fields (2.0~b1-1) unstable; urgency=low,xc-userfield=foobar
241 fields (1.0) experimental; urgency=high,xb-userfield2=foobar
243 * First upload (Closes: #1000000)
244 Xb-Userfield2: foobar
248 if ($vendor eq 'Ubuntu') {
249 $expected =~ s/^(Closes:.*)/$1\nLaunchpad-Bugs-Fixed: 12345 54321 424242 2424242/m;
251 cmp_ok
($str, 'eq', $expected, 'fields handling');
253 $str = $changes->format_range('dpkg', { offset
=> 1, count
=> 2 });
254 $expected = 'Source: fields
256 Distribution: unstable frozen
258 Maintainer: Frank Lichtenheld <djpig@debian.org>
259 Timestamp: 1200149359
260 Date: Sun, 12 Jan 2008 15:49:19 +0100
261 Closes: 1111111 2222222
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
281 if ($vendor eq 'Ubuntu') {
282 $expected =~ s/^(Closes:.*)/$1\nLaunchpad-Bugs-Fixed: 12345 424242/m;
284 cmp_ok
($str, 'eq', $expected, 'fields handling 2');
286 $str = $changes->format_range('rfc822', { offset
=> 2, count
=> 2 });
287 $expected = 'Source: fields
289 Distribution: unstable
291 Maintainer: Frank Lichtenheld <frank@lichtenheld.de>
292 Timestamp: 1200062959
293 Date: Sun, 11 Jan 2008 15:49:19 +0100
295 fields (2.0~b1-1) unstable; urgency=low,xc-userfield=foobar
302 Distribution: experimental
304 Maintainer: Frank Lichtenheld <djpig@debian.org>
305 Timestamp: 1199976559
306 Date: Sun, 10 Jan 2008 15:49:19 +0100
309 fields (1.0) experimental; urgency=high,xb-userfield2=foobar
311 * First upload (Closes: #1000000)
312 Xb-Userfield2: foobar
315 cmp_ok
($str, 'eq', $expected, 'fields handling 3');
317 # Test Dpkg::Changelog::Entry methods
318 is
($data[1]->get_version(), '2.0-1', 'get_version');
319 is
($data[1]->get_source(), 'fields', 'get_source');
320 is
(scalar $data[1]->get_distributions(), 'unstable', 'get_distribution');
321 is
(join('|', $data[1]->get_distributions()), 'unstable|frozen',
322 'get_distributions');
323 is
($data[3]->get_optional_fields(),
324 "Urgency: high\nCloses: 1000000\nXb-Userfield2: foobar\n",
325 'get_optional_fields');
326 is
($data[1]->get_maintainer(), 'Frank Lichtenheld <djpig@debian.org>',
328 is
($data[1]->get_timestamp(), 'Sun, 12 Jan 2008 15:49:19 +0100',
330 my @items = $data[1]->get_change_items();
331 is
($items[0], " [ Frank Lichtenheld ]\n", 'change items 1');
332 is
($items[4], ' * New upstream release.
335 ', 'change items 2');
336 is
($items[5], " * Update S-V.\n", 'change items 3');
338 if ($file eq "$datadir/date-format") {
339 is
($data[0]->get_timestamp(), '01 Jul 2100 23:59:59 -1200',
340 'get date w/o DoW, and negative timezone offset');
341 is
($data[1]->get_timestamp(), 'Tue, 27 Feb 2050 12:00:00 +1245',
342 'get date w/ DoW, and positive timezone offset');
343 is
($data[2]->get_timestamp(), 'Mon, 01 Jan 2000 00:00:00 +0000',
344 'get date w/ DoW, and zero timezone offset');
346 if ($file eq "$datadir/stop-modeline") {
347 is
($changes->get_unparsed_tail(), "vim: et\n",
348 'get unparsed modeline at EOF');
350 if ($file eq "$datadir/regressions") {
351 my $f = ($changes->format_range('dpkg'))[0];
352 is
("$f->{Version}", '0', 'version 0 correctly parsed');
356 skip
('avoid spurious warning with only one entry', 2)
360 my $oldest_version = $data[-1]->{Version
};
361 $str = $changes->format_range('dpkg', { since
=> $oldest_version });
363 $str = $changes->format_range('rfc822');
365 ok
(1, 'TODO check rfc822 output');
367 $str = $changes->format_range('rfc822', { since
=> $oldest_version });
369 ok
(1, 'TODO check rfc822 output with ranges');
373 foreach my $test (([ "$datadir/misplaced-tz", 6 ],
374 [ "$datadir/unreleased", 5, 7 ])) {
376 my $file = shift @
$test;
377 my $changes = Dpkg
::Changelog
::Debian
->new(verbose
=> 0);
378 $changes->load($file);
379 my @errors = $changes->get_parse_errors();
381 ok
(@errors, 'errors occured');
382 is_deeply
( [ map { $_->[1] } @errors ], $test, 'check line numbers' );