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

guillem pushed a commit to branch master
in repository dpkg.

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

commit e596defa91399a04792c7b37a6eb74a67cd10661
Author: Guillem Jover <guil...@debian.org>
AuthorDate: Sat Aug 25 01:30:06 2018 +0200

    scripts/t: Improve coverage of unit tests
---
 debian/changelog                |  1 +
 scripts/t/Dpkg_Arch.t           |  9 +++++++--
 scripts/t/Dpkg_BuildFlags.t     | 42 ++++++++++++++++++++++++++++++++++++++++-
 scripts/t/Dpkg_Build_Types.t    | 25 +++++++++++++++++++++++-
 scripts/t/Dpkg_Checksums.t      | 30 ++++++++++++++++++++++++++++-
 scripts/t/Dpkg_Control_Fields.t |  5 ++++-
 scripts/t/Dpkg_OpenPGP.t        | 23 +++++++++++++---------
 scripts/t/Dpkg_Substvars.t      | 19 ++++++++++++++++++-
 8 files changed, 138 insertions(+), 16 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 3b883b060..97ed4d959 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -276,6 +276,7 @@ dpkg (1.19.1) UNRELEASED; urgency=medium
     - Add new cppcheck author test.
     - Add support for new test_get_srcdir() test_get_builddir().
     - Add new unit tests for namevalue, fsys-hash and pkg-hash libdpkg modules.
+    - Improve coverage of perl unit tests.
 
   [ Updated programs translations ]
   * Dutch (Frans Spiesschaert). Closes: #881401
diff --git a/scripts/t/Dpkg_Arch.t b/scripts/t/Dpkg_Arch.t
index 9d2aaf361..a3a9e6fee 100644
--- a/scripts/t/Dpkg_Arch.t
+++ b/scripts/t/Dpkg_Arch.t
@@ -16,12 +16,12 @@
 use strict;
 use warnings;
 
-use Test::More tests => 16832;
+use Test::More tests => 16836;
 
 use_ok('Dpkg::Arch', qw(debarch_to_debtuple debarch_to_multiarch
                         debarch_eq debarch_is debarch_is_wildcard
                         debarch_is_illegal
-                        debarch_to_abiattrs
+                        debarch_to_abiattrs debarch_to_cpubits
                         debarch_list_parse
                         debtuple_to_debarch gnutriplet_to_debarch
                         get_host_gnu_type
@@ -160,6 +160,11 @@ ok($@, 'parse disallowed negated arches failed');
 
 is(debarch_to_abiattrs(undef), undef, 'undef ABI attrs');
 is_deeply([ debarch_to_abiattrs('amd64') ], [ qw(64 little) ], 'amd64 ABI 
attrs');
+is_deeply([ debarch_to_abiattrs('x32') ], [ qw(32 little) ], 'x32 ABI attrs');
+
+is(debarch_to_cpubits(undef), undef, 'undef CPU bits');
+is(debarch_to_cpubits('i386'), 32, 'i386 CPU bits');
+is(debarch_to_cpubits('amd64'), 64, 'amd64 CPU bits');
 
 is(debtuple_to_debarch(undef, undef, undef, undef), undef, 'undef debtuple');
 is(debtuple_to_debarch('base', 'gnu', 'linux', 'amd64'), 'amd64', 'known 
debtuple');
diff --git a/scripts/t/Dpkg_BuildFlags.t b/scripts/t/Dpkg_BuildFlags.t
index 0ebf878b8..776fdf1a4 100644
--- a/scripts/t/Dpkg_BuildFlags.t
+++ b/scripts/t/Dpkg_BuildFlags.t
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 15;
+use Test::More tests => 26;
 
 BEGIN {
     use_ok('Dpkg::BuildFlags');
@@ -47,6 +47,46 @@ is($bf->get('DPKGFLAGS'), '-Idir -Wflag -fsome -Wl,other', 
'get prepended flag')
 is($bf->get_origin('DPKGFLAGS'), 'env', 'flag has an env origin');
 ok($bf->is_maintainer_modified('DPKGFLAGS'), 'prepend marked flag as maint 
modified');
 
+my %known_features = (
+    future => [ qw(
+        lfs
+    ) ],
+    hardening => [ qw(
+        bindnow
+        format
+        fortify
+        pie
+        relro
+        stackprotector
+        stackprotectorstrong
+    ) ],
+    qa => [ qw(
+        bug
+        canary
+    ) ],
+    reproducible => [ qw(
+        fixdebugpath
+        timeless
+    ) ],
+    sanitize => [ qw(
+        address
+        leak
+        thread
+        undefined
+    ) ],
+);
+
+is_deeply([ sort $bf->get_feature_areas() ], [ sort keys %known_features ],
+          'supported feature areas');
+
+foreach my $area (sort keys %known_features) {
+    ok($bf->has_features($area), "has feature area $area");
+    my %features = $bf->get_features($area);
+    is_deeply([ sort keys %features ],
+              $known_features{$area},
+              "supported features for area $area");
+}
+
 # TODO: Add more test cases.
 
 1;
diff --git a/scripts/t/Dpkg_Build_Types.t b/scripts/t/Dpkg_Build_Types.t
index 7fa70ccf9..03c7055b3 100644
--- a/scripts/t/Dpkg_Build_Types.t
+++ b/scripts/t/Dpkg_Build_Types.t
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 26;
+use Test::More tests => 39;
 
 BEGIN {
     use_ok('Dpkg::Build::Types');
@@ -52,6 +52,29 @@ ok(!build_has_all(BUILD_SOURCE | BUILD_ARCH_DEP),
    'build source,all not has_all source,any');
 ok(!build_has_all(BUILD_FULL), 'build source,all has_all full');
 
+set_build_type_from_targets('build-arch,build-indep',
+                            '--targets=build-arch,build-indep', nocheck => 1);
+is(get_build_options_from_type(), 'binary',
+                                  'build is binary from 
build-arch,build-indep');
+ok(build_is(BUILD_BINARY), 'build is binary from build-arch,build-indep');
+
+set_build_type_from_targets('binary', '--targets=binary', nocheck => 1);
+is(get_build_options_from_type(), 'binary', 'build is binary from binary');
+ok(build_is(BUILD_BINARY), 'build is binary from binary');
+
+set_build_type_from_targets('clean,binary-indep',
+                            '--targets=clean,binary-indep', nocheck => 1);
+ok(build_is(BUILD_SOURCE | BUILD_ARCH_INDEP), 'build source,all is 
source,all');
+ok(!build_is(BUILD_SOURCE | BUILD_ARCH_DEP), 'build source,all is not 
source,any');
+ok(build_has_any(BUILD_SOURCE), 'build source,all has_any source');
+ok(build_has_any(BUILD_ARCH_INDEP), 'build source,all has_any any');
+ok(build_has_none(BUILD_DEFAULT), 'build source,all has_none default');
+ok(build_has_none(BUILD_ARCH_DEP), 'build source,all has_none any');
+ok(!build_has_all(BUILD_BINARY), 'build source,all not has_all binary');
+ok(!build_has_all(BUILD_SOURCE | BUILD_ARCH_DEP),
+   'build source,all not has_all source,any');
+ok(!build_has_all(BUILD_FULL), 'build source,all has_all full');
+
 set_build_type(BUILD_BINARY, '--build=binary', nocheck => 1);
 ok(build_is(BUILD_BINARY), 'build binary is binary');
 ok(build_has_any(BUILD_ARCH_DEP), 'build binary has_any any');
diff --git a/scripts/t/Dpkg_Checksums.t b/scripts/t/Dpkg_Checksums.t
index 82a45fe31..33e2587e1 100644
--- a/scripts/t/Dpkg_Checksums.t
+++ b/scripts/t/Dpkg_Checksums.t
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 44;
+use Test::More tests => 59;
 use Test::Dpkg qw(:paths);
 
 BEGIN {
@@ -120,4 +120,32 @@ foreach my $alg (keys %str_checksum) {
 
 test_checksums($ck);
 
+# Check remove_file()
+
+ok($ck->has_file('data-2'), 'To be removed file is present');
+$ck->remove_file('data-2');
+ok(!$ck->has_file('data-2'), 'Remove file is not present');
+
+# Check add_from_control()
+my $ctrl;
+foreach my $f (@data) {
+    next if $f->{file} ne 'data-2';
+    foreach my $alg (keys %{$f->{sums}}) {
+        $ctrl->{"Checksums-$alg"} = "\n$f->{sums}->{$alg} $f->{size} 
$f->{file}";
+    }
+}
+$ck->add_from_control($ctrl);
+
+test_checksums($ck);
+
+# Check export_to_control()
+
+my $ctrl_export = {};
+$ck->export_to_control($ctrl_export);
+
+foreach my $alg (keys %str_checksum) {
+    is($ctrl_export->{"Checksums-$alg"}, $str_checksum{$alg},
+       "Export checksum $alg to a control object");
+}
+
 1;
diff --git a/scripts/t/Dpkg_Control_Fields.t b/scripts/t/Dpkg_Control_Fields.t
index c83efed96..00f951052 100644
--- a/scripts/t/Dpkg_Control_Fields.t
+++ b/scripts/t/Dpkg_Control_Fields.t
@@ -32,10 +32,13 @@ my @src_dep_fields = qw(
     Build-Depends Build-Depends-Arch Build-Depends-Indep
     Build-Conflicts Build-Conflicts-Arch Build-Conflicts-Indep
 );
-my @bin_dep_fields = qw(
+my @bin_dep_normal_fields = qw(
     Pre-Depends Depends Recommends Suggests Enhances
+);
+my @bin_dep_union_fields = qw(
     Conflicts Breaks Replaces Provides Built-Using
 );
+my @bin_dep_fields = (@bin_dep_normal_fields, @bin_dep_union_fields);
 my @src_checksums = qw(
     Checksums-Md5 Checksums-Sha1 Checksums-Sha256
 );
diff --git a/scripts/t/Dpkg_OpenPGP.t b/scripts/t/Dpkg_OpenPGP.t
index b39613149..164395117 100644
--- a/scripts/t/Dpkg_OpenPGP.t
+++ b/scripts/t/Dpkg_OpenPGP.t
@@ -25,7 +25,7 @@ use Dpkg::ErrorHandling;
 
 test_needs_command('gpg');
 
-plan tests => 3;
+plan tests => 6;
 
 use_ok('Dpkg::OpenPGP');
 
@@ -33,22 +33,27 @@ report_options(quiet_warnings => 1);
 
 my $datadir = test_get_data_path();
 my $tmpdir = test_get_temp_path();
+my $ascfile;
 
-openpgp_sig_to_asc("$datadir/package_1.0.orig.tar.sig",
-                   "$tmpdir/package_1.0.orig.tar.sig2asc");
+$ascfile = "$tmpdir/package_1.0.orig.tar.enoent";
+is(openpgp_sig_to_asc("$datadir/nonexistent", $ascfile),
+   undef, 'no conversion of inexistent file');
 
-ok(compare("$tmpdir/package_1.0.orig.tar.sig2asc",
-           "$datadir/package_1.0.orig.tar.asc") == 0,
+$ascfile = "$tmpdir/package_1.0.orig.tar.sig2asc";
+is(openpgp_sig_to_asc("$datadir/package_1.0.orig.tar.sig", $ascfile),
+   $ascfile, 'conversion from binary sig to armored asc');
+
+ok(compare($ascfile, "$datadir/package_1.0.orig.tar.asc") == 0,
    'binary signature converted to OpenPGP ASCII Armor');
 
 # Grab the output messages.
 eval {
-    openpgp_sig_to_asc("$datadir/package_1.0.orig.tar.asc",
-                       "$tmpdir/package_1.0.orig.tar.asc2asc");
+    $ascfile = "$tmpdir/package_1.0.orig.tar.asc2asc";
+    is(openpgp_sig_to_asc("$datadir/package_1.0.orig.tar.asc", $ascfile),
+       $ascfile, 'copy instead of converting already armored input');
 };
 
-ok(compare("$tmpdir/package_1.0.orig.tar.asc2asc",
-           "$datadir/package_1.0.orig.tar.asc") == 0,
+ok(compare($ascfile, "$datadir/package_1.0.orig.tar.asc") == 0,
    'OpenPGP ASCII Armor copied to destination');
 
 # TODO: Add actual test cases.
diff --git a/scripts/t/Dpkg_Substvars.t b/scripts/t/Dpkg_Substvars.t
index 6c7be24f2..35ffd0ca5 100644
--- a/scripts/t/Dpkg_Substvars.t
+++ b/scripts/t/Dpkg_Substvars.t
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 37;
+use Test::More tests => 47;
 use Test::Dpkg qw(:paths);
 
 use Dpkg ();
@@ -82,6 +82,23 @@ is($s->get('binary:Version'), '1:2.3.4~5-6.7.8~nmu9+b0', 
'binary:Version');
 is($s->get('source:Version'), '1:2.3.4~5-6.7.8~nmu9', 'source:Version');
 is($s->get('source:Upstream-Version'), '1:2.3.4~5', 'source:Upstream-Version');
 
+is($s->get($_), undef, 'no ' . $_) foreach qw(source:Synopsis 
source:Extended-Description);
+$s->set_desc_substvars("short synopsis\nthis is the long\nextended text\n");
+is($s->get('source:Synopsis'), 'short synopsis', 'contents of 
source:Synopsis');
+is($s->get('source:Extended-Description'), "this is the long\nextended text\n",
+    'contents of source:Extended-Description');
+
+my %ctrl_fields = (
+    'Some-Field' => 'some-value',
+    'Other-Field' => 'other-value',
+    'Alter-Field' => 'alter-value',
+);
+is($s->get($_), undef, 'no ' . $_) foreach sort keys %ctrl_fields;
+$s->set_field_substvars(\%ctrl_fields, 'ctrl');
+is($s->get('ctrl:Some-Field'), 'some-value', 'contents of ctrl:Some-Field');
+is($s->get('ctrl:Other-Field'), 'other-value', 'contents of ctrl:Other-Field');
+is($s->get('ctrl:Alter-Field'), 'alter-value', 'contents of ctrl:Alter-Field');
+
 # Replace stuff
 is($s->substvars('This is a string ${var1} with variables ${binary:Version}'),
                  'This is a string New value with variables 
1:2.3.4~5-6.7.8~nmu9+b0',

-- 
Dpkg.Org's dpkg

Reply via email to