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

guillem pushed a commit to branch master
in repository dpkg.

commit 33c866433dd4b186aae970e05c639b52ad5e7ece
Author: Guillem Jover <guil...@debian.org>
Date:   Sun Oct 29 18:40:54 2017 +0100

    test: Infer automatically the unit test data directory
    
    We can easily know the name of the calling unit test, and can thus infer
    the pathname for the data directory, instead of having to duplicate the
    name, and potentially ending with it being out of sync.
---
 debian/changelog                |  1 +
 scripts/Test/Dpkg.pm            | 18 ++++++++++++++++--
 scripts/t/Dpkg_Changelog.t      |  2 +-
 scripts/t/Dpkg_Checksums.t      |  2 +-
 scripts/t/Dpkg_Conf.t           |  2 +-
 scripts/t/Dpkg_Control.t        |  2 +-
 scripts/t/Dpkg_Control_Fields.t |  2 +-
 scripts/t/Dpkg_Control_Tests.t  |  2 +-
 scripts/t/Dpkg_Dist_Files.t     |  2 +-
 scripts/t/Dpkg_OpenPGP.t        |  2 +-
 scripts/t/Dpkg_Shlibs.t         |  2 +-
 scripts/t/Dpkg_Source_Patch.t   |  2 +-
 scripts/t/Dpkg_Source_Quilt.t   |  2 +-
 scripts/t/Dpkg_Substvars.t      |  2 +-
 scripts/t/mk.t                  |  4 +++-
 15 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 96cb317..761acad 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -50,6 +50,7 @@ dpkg (1.19.1) UNRELEASED; urgency=medium
     - Skip Dpkg::OpenPGP test if gpg is not present.
     - Check POD in all perl scripts.
     - Consider *.PL also to be perl files.
+    - Infer automatically the unit test data directory.
 
   [ Updated programs translations ]
   * Dutch (Frans Spiesschaert). Closes: #881401
diff --git a/scripts/Test/Dpkg.pm b/scripts/Test/Dpkg.pm
index f0a73f8..2a3fec2 100644
--- a/scripts/Test/Dpkg.pm
+++ b/scripts/Test/Dpkg.pm
@@ -50,12 +50,26 @@ use File::Find;
 use IPC::Cmd qw(can_run);
 use Test::More;
 
+sub _test_get_caller_dir
+{
+    my (undef, $path, undef) = caller 1;
+
+    $path =~ s{\.t$}{};
+    $path =~ s{^\./}{};
+
+    return $path;
+}
+
 sub test_get_data_path
 {
     my $path = shift;
 
-    my $srcdir = $ENV{srcdir} || '.';
-    return "$srcdir/$path";
+    if (defined $path) {
+        my $srcdir = $ENV{srcdir} || '.';
+        return "$srcdir/$path";
+    } else {
+        return _test_get_caller_dir();
+    }
 }
 
 sub test_get_perl_dirs
diff --git a/scripts/t/Dpkg_Changelog.t b/scripts/t/Dpkg_Changelog.t
index 1ca238a..ed9f8a9 100644
--- a/scripts/t/Dpkg_Changelog.t
+++ b/scripts/t/Dpkg_Changelog.t
@@ -29,7 +29,7 @@ BEGIN {
     use_ok('Dpkg::Vendor', qw(get_current_vendor));
 };
 
-my $datadir = test_get_data_path('t/Dpkg_Changelog');
+my $datadir = test_get_data_path();
 
 my $vendor = get_current_vendor();
 
diff --git a/scripts/t/Dpkg_Checksums.t b/scripts/t/Dpkg_Checksums.t
index e549e64..82a45fe 100644
--- a/scripts/t/Dpkg_Checksums.t
+++ b/scripts/t/Dpkg_Checksums.t
@@ -23,7 +23,7 @@ BEGIN {
     use_ok('Dpkg::Checksums');
 }
 
-my $datadir = test_get_data_path('t/Dpkg_Checksums');
+my $datadir = test_get_data_path();
 
 my @data = (
     {
diff --git a/scripts/t/Dpkg_Conf.t b/scripts/t/Dpkg_Conf.t
index 2e55e3d..940d18d 100644
--- a/scripts/t/Dpkg_Conf.t
+++ b/scripts/t/Dpkg_Conf.t
@@ -23,7 +23,7 @@ BEGIN {
     use_ok('Dpkg::Conf');
 }
 
-my $datadir = test_get_data_path('t/Dpkg_Conf');
+my $datadir = test_get_data_path();
 
 my ($conf, $count, @opts);
 
diff --git a/scripts/t/Dpkg_Control.t b/scripts/t/Dpkg_Control.t
index 0f808fb..057cb21 100644
--- a/scripts/t/Dpkg_Control.t
+++ b/scripts/t/Dpkg_Control.t
@@ -26,7 +26,7 @@ BEGIN {
     use_ok('Dpkg::Control::Info');
 }
 
-my $datadir = test_get_data_path('t/Dpkg_Control');
+my $datadir = test_get_data_path();
 
 sub parse_dsc {
     my $path = shift;
diff --git a/scripts/t/Dpkg_Control_Fields.t b/scripts/t/Dpkg_Control_Fields.t
index 7a65822..c83efed 100644
--- a/scripts/t/Dpkg_Control_Fields.t
+++ b/scripts/t/Dpkg_Control_Fields.t
@@ -26,7 +26,7 @@ BEGIN {
     use_ok('Dpkg::Control::FieldsCore');
 }
 
-#my $datadir = test_get_data_path('t/Dpkg_Control_Fields');
+#my $datadir = test_get_data_path();
 
 my @src_dep_fields = qw(
     Build-Depends Build-Depends-Arch Build-Depends-Indep
diff --git a/scripts/t/Dpkg_Control_Tests.t b/scripts/t/Dpkg_Control_Tests.t
index 9c14a2e..27042dc 100644
--- a/scripts/t/Dpkg_Control_Tests.t
+++ b/scripts/t/Dpkg_Control_Tests.t
@@ -23,7 +23,7 @@ BEGIN {
     use_ok('Dpkg::Control::Tests');
 }
 
-my $datadir = test_get_data_path('t/Dpkg_Control_Tests');
+my $datadir = test_get_data_path();
 
 sub parse_tests {
     my $path = shift;
diff --git a/scripts/t/Dpkg_Dist_Files.t b/scripts/t/Dpkg_Dist_Files.t
index b29973d..44d42d0 100644
--- a/scripts/t/Dpkg_Dist_Files.t
+++ b/scripts/t/Dpkg_Dist_Files.t
@@ -21,7 +21,7 @@ use Test::Dpkg qw(:paths);
 
 use_ok('Dpkg::Dist::Files');
 
-my $datadir = test_get_data_path('t/Dpkg_Dist_Files');
+my $datadir = test_get_data_path();
 
 my $expected;
 my %expected = (
diff --git a/scripts/t/Dpkg_OpenPGP.t b/scripts/t/Dpkg_OpenPGP.t
index 84b8401..0d2e4af 100644
--- a/scripts/t/Dpkg_OpenPGP.t
+++ b/scripts/t/Dpkg_OpenPGP.t
@@ -31,7 +31,7 @@ use_ok('Dpkg::OpenPGP');
 
 report_options(quiet_warnings => 1);
 
-my $datadir = test_get_data_path('t/Dpkg_OpenPGP');
+my $datadir = test_get_data_path();
 my $tmpdir = 't.tmp/Dpkg_OpenPGP';
 
 mkdir $tmpdir;
diff --git a/scripts/t/Dpkg_Shlibs.t b/scripts/t/Dpkg_Shlibs.t
index 39163d7..2310f4f 100644
--- a/scripts/t/Dpkg_Shlibs.t
+++ b/scripts/t/Dpkg_Shlibs.t
@@ -31,7 +31,7 @@ my $tmp;
 my @tmp;
 my %tmp;
 
-my $datadir = test_get_data_path('t/Dpkg_Shlibs');
+my $datadir = test_get_data_path();
 
 my @librarypaths;
 
diff --git a/scripts/t/Dpkg_Source_Patch.t b/scripts/t/Dpkg_Source_Patch.t
index d81a1a3..d0e167d 100644
--- a/scripts/t/Dpkg_Source_Patch.t
+++ b/scripts/t/Dpkg_Source_Patch.t
@@ -25,7 +25,7 @@ BEGIN {
     use_ok('Dpkg::Source::Patch');
 }
 
-my $datadir = test_get_data_path('t/Dpkg_Source_Patch');
+my $datadir = test_get_data_path();
 my $tmpdir = 't.tmp/Dpkg_Source_Patch';
 
 sub test_patch_escape {
diff --git a/scripts/t/Dpkg_Source_Quilt.t b/scripts/t/Dpkg_Source_Quilt.t
index af0071d..96c3be0 100644
--- a/scripts/t/Dpkg_Source_Quilt.t
+++ b/scripts/t/Dpkg_Source_Quilt.t
@@ -23,7 +23,7 @@ BEGIN {
     use_ok('Dpkg::Source::Quilt');
 }
 
-my $datadir = test_get_data_path('t/Dpkg_Source_Quilt');
+my $datadir = test_get_data_path();
 
 my $quilt;
 my (@series_got, @series_exp);
diff --git a/scripts/t/Dpkg_Substvars.t b/scripts/t/Dpkg_Substvars.t
index ded25dd..bb8e140 100644
--- a/scripts/t/Dpkg_Substvars.t
+++ b/scripts/t/Dpkg_Substvars.t
@@ -24,7 +24,7 @@ use Dpkg::Arch qw(get_host_arch);
 
 use_ok('Dpkg::Substvars');
 
-my $datadir = test_get_data_path('t/Dpkg_Substvars');
+my $datadir = test_get_data_path();
 
 my $expected;
 
diff --git a/scripts/t/mk.t b/scripts/t/mk.t
index e711270..7eaf40c 100644
--- a/scripts/t/mk.t
+++ b/scripts/t/mk.t
@@ -17,6 +17,8 @@ use strict;
 use warnings;
 
 use Test::More tests => 6;
+use Test::Dpkg qw(:paths);
+
 use File::Spec::Functions qw(rel2abs);
 
 use Dpkg ();
@@ -25,7 +27,7 @@ use Dpkg::IPC;
 use Dpkg::Vendor;
 
 my $srcdir = $ENV{srcdir} || '.';
-my $datadir = "$srcdir/t/mk";
+my $datadir = test_get_data_path();
 
 # Turn these into absolute names so that we can safely switch to the test
 # directory with «make -C».

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/dpkg/dpkg.git

Reply via email to