[dpkg] 111/192: scripts/t: Avoid many function arguments in check_options()
Ximin Luo
infinity0 at debian.org
Tue Oct 17 11:04:06 UTC 2017
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch pu/reproducible_builds
in repository dpkg.
commit 47ccfd91e707720aa05296463673ed78c3e2e512
Author: Guillem Jover <guillem at debian.org>
Date: Thu Aug 31 10:30:40 2017 +0200
scripts/t: Avoid many function arguments in check_options()
Fixes: Subroutines::ProhibitManyArgs
Warned-by: perlcritic
---
debian/changelog | 1 +
scripts/t/Dpkg_Changelog.t | 234 ++++++++++++++++++++++++++-------------------
t/critic.t | 1 +
3 files changed, 139 insertions(+), 97 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index cbfa61f..3e68bfd 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -90,6 +90,7 @@ dpkg (1.19.0) UNRELEASED; urgency=medium
- Add a new module-version unit test to check that module $VERSION
matches the newest entry in the CHANGES section.
- Use Module::Metadata instead of grepping for $VERSION in pod-coverage.
+ - Avoid many function arguments in Dpkg_Changelog.t check_options().
[ Updated programs translations ]
* German (Sven Joachim).
diff --git a/scripts/t/Dpkg_Changelog.t b/scripts/t/Dpkg_Changelog.t
index 1369aef..1ca238a 100644
--- a/scripts/t/Dpkg_Changelog.t
+++ b/scripts/t/Dpkg_Changelog.t
@@ -60,110 +60,150 @@ foreach my $file ("$datadir/countme", "$datadir/shadow", "$datadir/fields",
my $all_versions = join( '/', map { $_->get_version() } @data);
sub check_options {
- my ($changes, $data, $options, $count, $versions,
- $check_name) = @_;
-
- my @cnt = $changes->get_range($options);
- cmp_ok( @cnt, '==', $count, "$check_name -> count" );
- if ($count == @$data) {
- is_deeply( \@cnt, $data, "$check_name -> returns all" );
+ 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( join( '/', map { $_->get_version() } @cnt),
- $versions, "$check_name -> versions" );
+ is_deeply([ map { $_->get_version() } @cnt ],
+ $opts{versions}, "$opts{name} -> versions" );
}
}
- check_options( $changes, \@data,
- { count => 3 }, 3, '2:2.0-1/1:2.0~rc2-3/1:2.0~rc2-2',
- 'positive count' );
- check_options( $changes, \@data,
- { count => -3 }, 3,
- '1:2.0~rc2-1sarge2/1:2.0~rc2-1sarge1/1.5-1',
- 'negative count' );
- check_options( $changes, \@data,
- { count => 1 }, 1, '2:2.0-1',
- 'count 1' );
- check_options( $changes, \@data,
- { count => 1, default_all => 1 }, 1, '2:2.0-1',
- 'count 1 (d_a 1)' );
- check_options( $changes, \@data,
- { count => -1 }, 1, '1.5-1',
- 'count -1' );
-
- check_options( $changes, \@data,
- { count => 3, offset => 2 }, 3,
- '1:2.0~rc2-2/1:2.0~rc2-1sarge3/1:2.0~rc2-1sarge2',
- 'positive count + positive offset' );
- check_options( $changes, \@data,
- { count => -3, offset => 4 }, 3,
- '1:2.0~rc2-3/1:2.0~rc2-2/1:2.0~rc2-1sarge3',
- 'negative count + positive offset' );
-
- check_options( $changes, \@data,
- { count => 4, offset => 5 }, 2,
- '1:2.0~rc2-1sarge1/1.5-1',
- 'positive count + positive offset (>max)' );
- check_options( $changes, \@data,
- { count => -4, offset => 2 }, 2,
- '2:2.0-1/1:2.0~rc2-3',
- 'negative count + positive offset (<0)' );
-
- check_options( $changes, \@data,
- { count => 3, offset => -4 }, 3,
- '1:2.0~rc2-1sarge3/1:2.0~rc2-1sarge2/1:2.0~rc2-1sarge1',
- 'positive count + negative offset' );
- check_options( $changes, \@data,
- { count => -3, offset => -3 }, 3,
- '1:2.0~rc2-3/1:2.0~rc2-2/1:2.0~rc2-1sarge3',
- 'negative count + negative offset' );
-
- check_options( $changes, \@data,
- { count => 5, offset => -2 }, 2,
- '1:2.0~rc2-1sarge1/1.5-1',
- 'positive count + negative offset (>max)' );
- check_options( $changes, \@data,
- { count => -5, offset => -4 }, 3,
- '2:2.0-1/1:2.0~rc2-3/1:2.0~rc2-2',
- 'negative count + negative offset (<0)' );
-
- check_options( $changes, \@data,
- { count => 7 }, 7, '',
- 'count 7 (max)' );
- check_options( $changes, \@data,
- { count => -7 }, 7, '',
- 'count -7 (-max)' );
- check_options( $changes, \@data,
- { count => 10 }, 7, '',
- 'count 10 (>max)' );
- check_options( $changes, \@data,
- { count => -10 }, 7, '',
- 'count -10 (<-max)' );
-
- check_options( $changes, \@data,
- { from => '1:2.0~rc2-1sarge3' }, 4,
- '2:2.0-1/1:2.0~rc2-3/1:2.0~rc2-2/1:2.0~rc2-1sarge3',
- 'from => "1:2.0~rc2-1sarge3"' );
- check_options( $changes, \@data,
- { since => '1:2.0~rc2-1sarge3' }, 3,
- '2:2.0-1/1:2.0~rc2-3/1:2.0~rc2-2',
- 'since => "1:2.0~rc2-1sarge3"' );
+ 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 },
+ 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( $changes, \@data,
- { since => 0 }, 7, '',
- 'since => 0 returns all');
+ check_options(%ref, range => { since => 0 },
+ count => 7,
+ name => 'since => 0 returns all');
delete $SIG{__WARN__};
- check_options( $changes, \@data,
- { to => '1:2.0~rc2-1sarge2' }, 3,
- '1:2.0~rc2-1sarge2/1:2.0~rc2-1sarge1/1.5-1',
- 'to => "1:2.0~rc2-1sarge2"' );
- ## no critic (ControlStructures::ProhibitUntilBlocks)
- check_options( $changes, \@data,
- { until => '1:2.0~rc2-1sarge2' }, 2,
- '1:2.0~rc2-1sarge1/1.5-1',
- 'until => "1:2.0~rc2-1sarge2"' );
- ## use critic
- #TODO: test combinations
+ 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
}
if ($file eq "$datadir/fields") {
my $str = $changes->format_range('dpkg', { all => 1 });
diff --git a/t/critic.t b/t/critic.t
index 7cc4c9e..0221c1b 100644
--- a/t/critic.t
+++ b/t/critic.t
@@ -80,6 +80,7 @@ my @policies = qw(
RegularExpressions::RequireBracesForMultiline
RegularExpressions::RequireExtendedFormatting
Subroutines::ProhibitExplicitReturnUndef
+ Subroutines::ProhibitManyArgs
Subroutines::ProhibitNestedSubs
Subroutines::ProhibitReturnSort
Subroutines::ProhibitUnusedPrivateSubroutines
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git
More information about the Reproducible-commits
mailing list