This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=dc8f6ffc0e69fb21f9132e4255b5972440ced2f2

commit dc8f6ffc0e69fb21f9132e4255b5972440ced2f2
Author: Guillem Jover <[email protected]>
AuthorDate: Mon Jul 29 00:28:52 2024 +0200

    test: Unroll Dpkg::Changelog file tests loop
    
    The unit tests were using a loop, which had a tiny common part and the
    rest was specific logic for each individual file, which made reading
    the loop and following the code path more complex than needed.
    
    Unroll the loop, to have one section per file.
---
 scripts/t/Dpkg_Changelog.t | 452 ++++++++++++++++++++++++---------------------
 1 file changed, 237 insertions(+), 215 deletions(-)

diff --git a/scripts/t/Dpkg_Changelog.t b/scripts/t/Dpkg_Changelog.t
index 475577af1..c4cc8b7a1 100644
--- a/scripts/t/Dpkg_Changelog.t
+++ b/scripts/t/Dpkg_Changelog.t
@@ -35,7 +35,8 @@ my $vendor = get_current_vendor();
 
 sub setup_changelog
 {
-    my $file = shift;
+    my $name = shift;
+    my $file = "$datadir/$name";
 
     my $changes = Dpkg::Changelog::Debian->new(verbose => 0);
     $changes->load($file);
@@ -72,172 +73,180 @@ sub setup_changelog
 
 #########################
 
-foreach my $file ("$datadir/countme", "$datadir/shadow", "$datadir/fields",
-    "$datadir/regressions", "$datadir/date-format", "$datadir/stop-modeline") {
-
-    my $changes;
-    my $data;
-
-    ($changes, $data) = setup_changelog($file);
-
-    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
+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
@@ -274,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
@@ -307,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
@@ -341,46 +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 
<[email protected]>',
-           '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 <[email protected]>',
+        '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');
+
+
+## File: date-format
+
+($changes, $data) = setup_changelog('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');
+
+
+## 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 ])) {

-- 
Dpkg.Org's dpkg

Reply via email to