diff options
Diffstat (limited to 'scripts/t/Dpkg_Changelog.t')
-rw-r--r-- | scripts/t/Dpkg_Changelog.t | 486 |
1 files changed, 260 insertions, 226 deletions
diff --git a/scripts/t/Dpkg_Changelog.t b/scripts/t/Dpkg_Changelog.t index c3e7413..c4cc8b7 100644 --- a/scripts/t/Dpkg_Changelog.t +++ b/scripts/t/Dpkg_Changelog.t @@ -33,10 +33,10 @@ my $datadir = test_get_data_path(); my $vendor = get_current_vendor(); -######################### - -foreach my $file ("$datadir/countme", "$datadir/shadow", "$datadir/fields", - "$datadir/regressions", "$datadir/date-format", "$datadir/stop-modeline") { +sub setup_changelog +{ + my $name = shift; + my $file = "$datadir/$name"; my $changes = Dpkg::Changelog::Debian->new(verbose => 0); $changes->load($file); @@ -45,170 +45,208 @@ foreach my $file ("$datadir/countme", "$datadir/shadow", "$datadir/fields", cmp_ok($content, 'eq', "$changes", "string output of Dpkg::Changelog on $file"); my $errors = $changes->get_parse_errors(); - my $basename = basename( $file ); - is($errors, '', "Parse example changelog $file without errors" ); + my $basename = basename($file); + is($errors, '', "Parse example changelog $file without errors"); my @data = @$changes; - ok(@data, 'data is not empty'); - - if ($file eq "$datadir/countme") { - # test range options - cmp_ok(@data, '==', 7, 'no options -> count'); - my $all_versions = join( '/', map { $_->get_version() } @data); - - sub check_options { - my (%opts) = @_; - - my @cnt = $changes->get_range($opts{range}); - cmp_ok(@cnt, '==', $opts{count}, "$opts{name} -> count"); - if ($opts{count} == @{$opts{data}}) { - is_deeply(\@cnt, $opts{data}, "$opts{name} -> returns all"); - } else { - is_deeply([ map { $_->get_version() } @cnt ], - $opts{versions}, "$opts{name} -> versions" ); - } - } - - my %ref = ( - changes => $changes, - data => \@data, - ); - - check_options(%ref, range => { count => 3 }, - count => 3, - versions => [ '2:2.0-1', '1:2.0~rc2-3', '1:2.0~rc2-2' ], - name => 'positive count'); - check_options(%ref, range => { count => 3, reverse => 1 }, - count => 3, - versions => [ '1:2.0~rc2-2', '1:2.0~rc2-3', '2:2.0-1' ], - name => 'positive reverse count'); - check_options(%ref, range => { count => -3 }, - count => 3, - versions => [ - '1:2.0~rc2-1sarge2', - '1:2.0~rc2-1sarge1', - '1.5-1', - ], - name => 'negative count'); - check_options(%ref, range => { count => 1 }, - count => 1, - versions => [ '2:2.0-1' ], - name => 'count 1'); - check_options(%ref, range => { count => 1, default_all => 1 }, - count => 1, - versions => [ '2:2.0-1' ], - name => 'count 1 (d_a 1)'); - check_options(%ref, range => { count => -1 }, - count => 1, - versions => [ '1.5-1' ], - name => 'count -1'); - - check_options(%ref, range => { count => 3, offset => 2 }, - count => 3, - versions => [ - '1:2.0~rc2-2', - '1:2.0~rc2-1sarge3', - '1:2.0~rc2-1sarge2', - ], - name => 'positive count + positive offset'); - check_options(%ref, range => { count => -3, offset => 4 }, - count => 3, - versions => [ - '1:2.0~rc2-3', - '1:2.0~rc2-2', - '1:2.0~rc2-1sarge3', - ], - name => 'negative count + positive offset'); - - check_options(%ref, range => { count => 4, offset => 5 }, - count => 2, - versions => [ '1:2.0~rc2-1sarge1', '1.5-1' ], - name => 'positive count + positive offset (>max)'); - check_options(%ref, range => { count => -4, offset => 2 }, - count => 2, - versions => [ '2:2.0-1', '1:2.0~rc2-3' ], - name => 'negative count + positive offset (<0)'); - - check_options(%ref, range => { count => 3, offset => -4 }, - count => 3, - versions => [ - '1:2.0~rc2-1sarge3', - '1:2.0~rc2-1sarge2', - '1:2.0~rc2-1sarge1', - ], - name => 'positive count + negative offset'); - check_options(%ref, range => { count => -3, offset => -3 }, - count => 3, - versions => [ - '1:2.0~rc2-3', - '1:2.0~rc2-2', - '1:2.0~rc2-1sarge3', - ], - name => 'negative count + negative offset'); - - check_options(%ref, range => { count => 5, offset => -2 }, - count => 2, - versions => [ '1:2.0~rc2-1sarge1', '1.5-1' ], - name => 'positive count + negative offset (>max)'); - check_options(%ref, range => { count => -5, offset => -4 }, - count => 3, - versions => [ '2:2.0-1', '1:2.0~rc2-3', '1:2.0~rc2-2' ], - name => 'negative count + negative offset (<0)'); - - check_options(%ref, range => { count => 7 }, - count => 7, - name => 'count 7 (max)'); - check_options(%ref, range => { count => -7 }, - count => 7, - name => 'count -7 (-max)'); - check_options(%ref, range => { count => 10 }, - count => 7, - name => 'count 10 (>max)'); - check_options(%ref, range => { count => -10 }, - count => 7, - name => 'count -10 (<-max)'); - - check_options(%ref, range => { from => '1:2.0~rc2-1sarge3' }, - count => 4, - versions => [ - '2:2.0-1', - '1:2.0~rc2-3', - '1:2.0~rc2-2', - '1:2.0~rc2-1sarge3', - ], - name => 'from => "1:2.0~rc2-1sarge3"'); - check_options(%ref, range => { since => '1:2.0~rc2-1sarge3' }, - count => 3, - versions => [ - '2:2.0-1', - '1:2.0~rc2-3', - '1:2.0~rc2-2', - ], - name => 'since => "1:2.0~rc2-1sarge3"'); - $SIG{__WARN__} = sub {}; - check_options(%ref, range => { since => 0 }, - count => 7, - name => 'since => 0 returns all'); - delete $SIG{__WARN__}; - check_options(%ref, range => { to => '1:2.0~rc2-1sarge2' }, - count => 3, - versions => [ - '1:2.0~rc2-1sarge2', - '1:2.0~rc2-1sarge1', - '1.5-1', - ], - name => 'to => "1:2.0~rc2-1sarge2"'); - ## no critic (ControlStructures::ProhibitUntilBlocks) - check_options(%ref, range => { until => '1:2.0~rc2-1sarge2' }, - count => 2, - versions => [ '1:2.0~rc2-1sarge1', '1.5-1' ], - name => 'until => "1:2.0~rc2-1sarge2"'); - ## use critic - #TODO: test combinations + ok(@data, "data from $file is not empty"); + + SKIP: { + skip('avoid spurious warning with only one entry', 2) + if @data == 1; + + my $str; + my $oldest_version = $data[-1]->{Version}; + $str = $changes->format_range('dpkg', { since => $oldest_version }); + + $str = $changes->format_range('rfc822'); + + ok(1, 'TODO check rfc822 output'); + + $str = $changes->format_range('rfc822', { since => $oldest_version }); + + ok(1, 'TODO check rfc822 output with ranges'); + } + + return ($changes, \@data); +} + +######################### + +my $changes; +my $data; + + +## File: countme + +($changes, $data) = setup_changelog('countme'); + +# Test range options. +cmp_ok(@{$data}, '==', 7, 'no options -> count'); +my $all_versions = join('/', map { $_->get_version() } @{$data}); + +sub check_options { + my (%opts) = @_; + + my @cnt = $changes->get_range($opts{range}); + cmp_ok(@cnt, '==', $opts{count}, "$opts{name} -> count"); + if ($opts{count} == @{$opts{data}}) { + is_deeply(\@cnt, $opts{data}, "$opts{name} -> returns all"); + } else { + is_deeply([ map { $_->get_version() } @cnt ], + $opts{versions}, "$opts{name} -> versions"); } - if ($file eq "$datadir/fields") { - my $str = $changes->format_range('dpkg', { all => 1 }); - my $expected = 'Source: fields +} + +my %ref = ( + changes => $changes, + data => $data, +); + +check_options(%ref, range => { count => 3 }, + count => 3, + versions => [ '2:2.0-1', '1:2.0~rc2-3', '1:2.0~rc2-2' ], + name => 'positive count'); +check_options(%ref, range => { count => 3, reverse => 1 }, + count => 3, + versions => [ '1:2.0~rc2-2', '1:2.0~rc2-3', '2:2.0-1' ], + name => 'positive reverse count'); +check_options(%ref, range => { count => -3 }, + count => 3, + versions => [ + '1:2.0~rc2-1sarge2', + '1:2.0~rc2-1sarge1', + '1.5-1', + ], + name => 'negative count'); +check_options(%ref, range => { count => 1 }, + count => 1, + versions => [ '2:2.0-1' ], + name => 'count 1'); +check_options(%ref, range => { count => 1, default_all => 1 }, + count => 1, + versions => [ '2:2.0-1' ], + name => 'count 1 (d_a 1)'); +check_options(%ref, range => { count => -1 }, + count => 1, + versions => [ '1.5-1' ], + name => 'count -1'); + +check_options(%ref, range => { count => 3, offset => 2 }, + count => 3, + versions => [ + '1:2.0~rc2-2', + '1:2.0~rc2-1sarge3', + '1:2.0~rc2-1sarge2', + ], + name => 'positive count + positive offset'); +check_options(%ref, range => { count => -3, offset => 4 }, + count => 3, + versions => [ + '1:2.0~rc2-3', + '1:2.0~rc2-2', + '1:2.0~rc2-1sarge3', + ], + name => 'negative count + positive offset'); + +check_options(%ref, range => { count => 4, offset => 5 }, + count => 2, + versions => [ '1:2.0~rc2-1sarge1', '1.5-1' ], + name => 'positive count + positive offset (>max)'); +check_options(%ref, range => { count => -4, offset => 2 }, + count => 2, + versions => [ '2:2.0-1', '1:2.0~rc2-3' ], + name => 'negative count + positive offset (<0)'); + +check_options(%ref, range => { count => 3, offset => -4 }, + count => 3, + versions => [ + '1:2.0~rc2-1sarge3', + '1:2.0~rc2-1sarge2', + '1:2.0~rc2-1sarge1', + ], + name => 'positive count + negative offset'); +check_options(%ref, range => { count => -3, offset => -3 }, + count => 3, + versions => [ + '1:2.0~rc2-3', + '1:2.0~rc2-2', + '1:2.0~rc2-1sarge3', + ], + name => 'negative count + negative offset'); + +check_options(%ref, range => { count => 5, offset => -2 }, + count => 2, + versions => [ '1:2.0~rc2-1sarge1', '1.5-1' ], + name => 'positive count + negative offset (>max)'); +check_options(%ref, range => { count => -5, offset => -4 }, + count => 3, + versions => [ '2:2.0-1', '1:2.0~rc2-3', '1:2.0~rc2-2' ], + name => 'negative count + negative offset (<0)'); + +check_options(%ref, range => { count => 7 }, + count => 7, + name => 'count 7 (max)'); +check_options(%ref, range => { count => -7 }, + count => 7, + name => 'count -7 (-max)'); +check_options(%ref, range => { count => 10 }, + count => 7, + name => 'count 10 (>max)'); +check_options(%ref, range => { count => -10 }, + count => 7, + name => 'count -10 (<-max)'); + +check_options(%ref, range => { from => '1:2.0~rc2-1sarge3' }, + count => 4, + versions => [ + '2:2.0-1', + '1:2.0~rc2-3', + '1:2.0~rc2-2', + '1:2.0~rc2-1sarge3', + ], + name => 'from => "1:2.0~rc2-1sarge3"'); +check_options(%ref, range => { since => '1:2.0~rc2-1sarge3' }, + count => 3, + versions => [ + '2:2.0-1', + '1:2.0~rc2-3', + '1:2.0~rc2-2', + ], + name => 'since => "1:2.0~rc2-1sarge3"'); +$SIG{__WARN__} = sub {}; +check_options(%ref, range => { since => 0 }, + count => 7, + name => 'since => 0 returns all'); +delete $SIG{__WARN__}; +check_options(%ref, range => { to => '1:2.0~rc2-1sarge2' }, + count => 3, + versions => [ + '1:2.0~rc2-1sarge2', + '1:2.0~rc2-1sarge1', + '1.5-1', + ], + name => 'to => "1:2.0~rc2-1sarge2"'); +## no critic (ControlStructures::ProhibitUntilBlocks) +check_options(%ref, range => { until => '1:2.0~rc2-1sarge2' }, + count => 2, + versions => [ '1:2.0~rc2-1sarge1', '1.5-1' ], + name => 'until => "1:2.0~rc2-1sarge2"'); +## use critic +#TODO: test combinations + + +## File: shadow + +($changes, $data) = setup_changelog('shadow'); + + +## File: fields + +($changes, $data) = setup_changelog('fields'); + + my $str = $changes->format_range('dpkg', { all => 1 }); + my $expected = 'Source: fields Version: 2.0-0etch1 Distribution: stable Urgency: high @@ -245,13 +283,13 @@ Xb-Userfield2: foobar Xc-Userfield: foobar '; - if ($vendor eq 'Ubuntu') { - $expected =~ s/^(Closes:.*)/$1\nLaunchpad-Bugs-Fixed: 12345 54321 424242 2424242/m; - } - cmp_ok($str, 'eq', $expected, 'fields handling'); + if ($vendor eq 'Ubuntu') { + $expected =~ s/^(Closes:.*)/$1\nLaunchpad-Bugs-Fixed: 12345 54321 424242 2424242/m; + } + cmp_ok($str, 'eq', $expected, 'fields handling'); - $str = $changes->format_range('dpkg', { offset => 1, count => 2 }); - $expected = 'Source: fields + $str = $changes->format_range('dpkg', { offset => 1, count => 2 }); + $expected = 'Source: fields Version: 2.0-1 Distribution: unstable frozen Urgency: medium @@ -278,13 +316,13 @@ Changes: Xc-Userfield: foobar '; - if ($vendor eq 'Ubuntu') { - $expected =~ s/^(Closes:.*)/$1\nLaunchpad-Bugs-Fixed: 12345 424242/m; - } - cmp_ok($str, 'eq', $expected, 'fields handling 2'); + if ($vendor eq 'Ubuntu') { + $expected =~ s/^(Closes:.*)/$1\nLaunchpad-Bugs-Fixed: 12345 424242/m; + } + cmp_ok($str, 'eq', $expected, 'fields handling 2'); - $str = $changes->format_range('rfc822', { offset => 2, count => 2 }); - $expected = 'Source: fields + $str = $changes->format_range('rfc822', { offset => 2, count => 2 }); + $expected = 'Source: fields Version: 2.0~b1-1 Distribution: unstable Urgency: low @@ -312,63 +350,59 @@ Changes: Xb-Userfield2: foobar '; - cmp_ok($str, 'eq', $expected, 'fields handling 3'); - - # Test Dpkg::Changelog::Entry methods - is($data[1]->get_version(), '2.0-1', 'get_version'); - is($data[1]->get_source(), 'fields', 'get_source'); - is(scalar $data[1]->get_distributions(), 'unstable', 'get_distribution'); - is(join('|', $data[1]->get_distributions()), 'unstable|frozen', - 'get_distributions'); - is($data[3]->get_optional_fields(), - "Urgency: high\nCloses: 1000000\nXb-Userfield2: foobar\n", - 'get_optional_fields'); - is($data[1]->get_maintainer(), 'Frank Lichtenheld <djpig@debian.org>', - 'get_maintainer'); - is($data[1]->get_timestamp(), 'Sun, 12 Jan 2008 15:49:19 +0100', - 'get_timestamp'); - my @items = $data[1]->get_change_items(); - is($items[0], " [ Frank Lichtenheld ]\n", 'change items 1'); - is($items[4], ' * New upstream release. + cmp_ok($str, 'eq', $expected, 'fields handling 3'); + + # Test Dpkg::Changelog::Entry methods + is($data->[1]->get_version(), '2.0-1', 'get_version'); + is($data->[1]->get_source(), 'fields', 'get_source'); + is(scalar $data->[1]->get_distributions(), 'unstable', 'get_distribution'); + is(join('|', $data->[1]->get_distributions()), 'unstable|frozen', + 'get_distributions'); + is($data->[3]->get_optional_fields(), + "Urgency: high\nCloses: 1000000\nXb-Userfield2: foobar\n", + 'get_optional_fields'); + is($data->[1]->get_maintainer(), 'Frank Lichtenheld <djpig@debian.org>', + 'get_maintainer'); + is($data->[1]->get_timestamp(), 'Sun, 12 Jan 2008 15:49:19 +0100', + 'get_timestamp'); + my @items = $data->[1]->get_change_items(); + is($items[0], " [ Frank Lichtenheld ]\n", 'change items 1'); + is($items[4], ' * New upstream release. - implements a - implements b ', 'change items 2'); - is($items[5], " * Update S-V.\n", 'change items 3'); - } - if ($file eq "$datadir/date-format") { - is($data[0]->get_timestamp(), '01 Jul 2100 23:59:59 -1200', - 'get date w/o DoW, and negative timezone offset'); - is($data[1]->get_timestamp(), 'Tue, 27 Feb 2050 12:00:00 +1245', - 'get date w/ DoW, and positive timezone offset'); - is($data[2]->get_timestamp(), 'Mon, 01 Jan 2000 00:00:00 +0000', - 'get date w/ DoW, and zero timezone offset'); - } - if ($file eq "$datadir/stop-modeline") { - is($changes->get_unparsed_tail(), "vim: et\n", - 'get unparsed modeline at EOF'); - } - if ($file eq "$datadir/regressions") { - my $f = ($changes->format_range('dpkg'))[0]; - is("$f->{Version}", '0', 'version 0 correctly parsed'); - } + is($items[5], " * Update S-V.\n", 'change items 3'); - SKIP: { - skip('avoid spurious warning with only one entry', 2) - if @data == 1; - my $str; - my $oldest_version = $data[-1]->{Version}; - $str = $changes->format_range('dpkg', { since => $oldest_version }); +## File: date-format - $str = $changes->format_range('rfc822'); +($changes, $data) = setup_changelog('date-format'); - ok(1, 'TODO check rfc822 output'); +is($data->[0]->get_timestamp(), '01 Jul 2100 23:59:59 -1200', + 'get date w/o DoW, and negative timezone offset'); +is($data->[1]->get_timestamp(), 'Tue, 27 Feb 2050 12:00:00 +1245', + 'get date w/ DoW, and positive timezone offset'); +is($data->[2]->get_timestamp(), 'Mon, 01 Jan 2000 00:00:00 +0000', + 'get date w/ DoW, and zero timezone offset'); - $str = $changes->format_range('rfc822', { since => $oldest_version }); - ok(1, 'TODO check rfc822 output with ranges'); - } -} +## File: stop-modeline + +($changes, $data) = setup_changelog('stop-modeline'); + +is($changes->get_unparsed_tail(), "vim: et\n", + 'get unparsed modeline at EOF'); + + +## File: regressions + +($changes, $data) = setup_changelog('regressions'); + +my $f = ($changes->format_range('dpkg'))[0]; +is("$f->{Version}", '0', 'version 0 correctly parsed'); + + +## Files foreach my $test (([ "$datadir/misplaced-tz", 6 ], [ "$datadir/unreleased", 5, 7 ])) { @@ -379,5 +413,5 @@ foreach my $test (([ "$datadir/misplaced-tz", 6 ], my @errors = $changes->get_parse_errors(); ok(@errors, 'errors occured'); - is_deeply( [ map { $_->[1] } @errors ], $test, 'check line numbers' ); + is_deeply([ map { $_->[1] } @errors ], $test, 'check line numbers'); } |