[dpkg] 118/200: test: Refactor unit test data path into test_get_data_path()
Ximin Luo
infinity0 at debian.org
Wed Apr 5 15:17:26 UTC 2017
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository dpkg.
commit 2f05b55f031371458f6903fae4bfebacc555bd07
Author: Guillem Jover <guillem at debian.org>
Date: Mon Jan 23 04:45:19 2017 +0100
test: Refactor unit test data path into test_get_data_path()
---
scripts/Test/Dpkg.pm | 14 ++++++++++++++
scripts/t/Dpkg_Changelog.t | 4 ++--
scripts/t/Dpkg_Changelog_Ubuntu.t | 8 ++++++--
scripts/t/Dpkg_Checksums.t | 4 ++--
scripts/t/Dpkg_Conf.t | 4 ++--
scripts/t/Dpkg_Control.t | 5 ++---
scripts/t/Dpkg_Control_Tests.t | 4 ++--
scripts/t/Dpkg_Dist_Files.t | 4 ++--
scripts/t/Dpkg_Shlibs.t | 7 +++----
scripts/t/Dpkg_Source_Patch.t | 4 ++--
scripts/t/Dpkg_Source_Quilt.t | 4 ++--
scripts/t/Dpkg_Substvars.t | 4 ++--
12 files changed, 41 insertions(+), 25 deletions(-)
diff --git a/scripts/Test/Dpkg.pm b/scripts/Test/Dpkg.pm
index e0395de..ba0f539 100644
--- a/scripts/Test/Dpkg.pm
+++ b/scripts/Test/Dpkg.pm
@@ -22,6 +22,7 @@ our $VERSION = '0.00';
our @EXPORT_OK = qw(
all_perl_files
test_get_perl_dirs
+ test_get_data_path
test_needs_author
test_needs_module
test_needs_command
@@ -35,6 +36,11 @@ our %EXPORT_TAGS = (
test_needs_command
test_needs_srcdir_switch
) ],
+ paths => [ qw(
+ all_perl_files
+ test_get_perl_dirs
+ test_get_data_path
+ ) ],
);
use Exporter qw(import);
@@ -42,6 +48,14 @@ use File::Find;
use IPC::Cmd qw(can_run);
use Test::More;
+sub test_get_data_path
+{
+ my $path = shift;
+
+ my $srcdir = $ENV{srcdir} || '.';
+ return "$srcdir/$path";
+}
+
sub test_get_perl_dirs
{
return qw(t src/t lib utils/t scripts dselect);
diff --git a/scripts/t/Dpkg_Changelog.t b/scripts/t/Dpkg_Changelog.t
index e64ec87..7535e24 100644
--- a/scripts/t/Dpkg_Changelog.t
+++ b/scripts/t/Dpkg_Changelog.t
@@ -17,6 +17,7 @@ use strict;
use warnings;
use Test::More tests => 94;
+use Test::Dpkg qw(:paths);
use File::Basename;
@@ -28,8 +29,7 @@ BEGIN {
use_ok('Dpkg::Vendor', qw(get_current_vendor));
};
-my $srcdir = $ENV{srcdir} || '.';
-my $datadir = $srcdir . '/t/Dpkg_Changelog';
+my $datadir = test_get_data_path('t/Dpkg_Changelog');
my $vendor = get_current_vendor();
diff --git a/scripts/t/Dpkg_Changelog_Ubuntu.t b/scripts/t/Dpkg_Changelog_Ubuntu.t
index b2e3783..1cd622d 100644
--- a/scripts/t/Dpkg_Changelog_Ubuntu.t
+++ b/scripts/t/Dpkg_Changelog_Ubuntu.t
@@ -16,6 +16,10 @@
use strict;
use warnings;
+use Test::Dpkg qw(:paths);
+
$ENV{DEB_VENDOR} = 'Ubuntu';
-my $srcdir = $ENV{srcdir} || '.';
-do "$srcdir/t/Dpkg_Changelog.t";
+
+my $datafile = test_get_data_path('t/Dpkg_Changelog.t');
+
+do "$datafile";
diff --git a/scripts/t/Dpkg_Checksums.t b/scripts/t/Dpkg_Checksums.t
index f157202..6c7dc80 100644
--- a/scripts/t/Dpkg_Checksums.t
+++ b/scripts/t/Dpkg_Checksums.t
@@ -17,13 +17,13 @@ use strict;
use warnings;
use Test::More tests => 44;
+use Test::Dpkg qw(:paths);
BEGIN {
use_ok('Dpkg::Checksums');
}
-my $srcdir = $ENV{srcdir} // '.';
-my $datadir = $srcdir . '/t/Dpkg_Checksums';
+my $datadir = test_get_data_path('t/Dpkg_Checksums');
my @data = (
{
diff --git a/scripts/t/Dpkg_Conf.t b/scripts/t/Dpkg_Conf.t
index c6f0510..2e55e3d 100644
--- a/scripts/t/Dpkg_Conf.t
+++ b/scripts/t/Dpkg_Conf.t
@@ -17,13 +17,13 @@ use strict;
use warnings;
use Test::More tests => 9;
+use Test::Dpkg qw(:paths);
BEGIN {
use_ok('Dpkg::Conf');
}
-my $srcdir = $ENV{srcdir} // '.';
-my $datadir = $srcdir . '/t/Dpkg_Conf';
+my $datadir = test_get_data_path('t/Dpkg_Conf');
my ($conf, $count, @opts);
diff --git a/scripts/t/Dpkg_Control.t b/scripts/t/Dpkg_Control.t
index 5fbb878..40b9d33 100644
--- a/scripts/t/Dpkg_Control.t
+++ b/scripts/t/Dpkg_Control.t
@@ -17,7 +17,7 @@ use strict;
use warnings;
use Test::More;
-use Test::Dpkg qw(:needs);
+use Test::Dpkg qw(:needs :paths);
BEGIN {
test_needs_module('IO::String');
@@ -28,8 +28,7 @@ BEGIN {
use_ok('Dpkg::Control::Info');
}
-my $srcdir = $ENV{srcdir} || '.';
-my $datadir = $srcdir . '/t/Dpkg_Control';
+my $datadir = test_get_data_path('t/Dpkg_Control');
sub parse_dsc {
my $path = shift;
diff --git a/scripts/t/Dpkg_Control_Tests.t b/scripts/t/Dpkg_Control_Tests.t
index b9905ba..9c14a2e 100644
--- a/scripts/t/Dpkg_Control_Tests.t
+++ b/scripts/t/Dpkg_Control_Tests.t
@@ -17,13 +17,13 @@ use strict;
use warnings;
use Test::More tests => 5;
+use Test::Dpkg qw(:paths);
BEGIN {
use_ok('Dpkg::Control::Tests');
}
-my $srcdir = $ENV{srcdir} || '.';
-my $datadir = $srcdir . '/t/Dpkg_Control_Tests';
+my $datadir = test_get_data_path('t/Dpkg_Control_Tests');
sub parse_tests {
my $path = shift;
diff --git a/scripts/t/Dpkg_Dist_Files.t b/scripts/t/Dpkg_Dist_Files.t
index 4dccffe..d43c224 100644
--- a/scripts/t/Dpkg_Dist_Files.t
+++ b/scripts/t/Dpkg_Dist_Files.t
@@ -17,11 +17,11 @@ use strict;
use warnings;
use Test::More tests => 26;
+use Test::Dpkg qw(:paths);
use_ok('Dpkg::Dist::Files');
-my $srcdir = $ENV{srcdir} // '.';
-my $datadir = $srcdir . '/t/Dpkg_Dist_Files';
+my $datadir = test_get_data_path('t/Dpkg_Dist_Files');
my $expected;
my %expected = (
diff --git a/scripts/t/Dpkg_Shlibs.t b/scripts/t/Dpkg_Shlibs.t
index 2e68f74..578e4e4 100644
--- a/scripts/t/Dpkg_Shlibs.t
+++ b/scripts/t/Dpkg_Shlibs.t
@@ -17,7 +17,7 @@ use strict;
use warnings;
use Test::More;
-use Test::Dpkg qw(:needs);
+use Test::Dpkg qw(:needs :paths);
use Cwd;
@@ -33,8 +33,7 @@ my $tmp;
my @tmp;
my %tmp;
-my $srcdir = $ENV{srcdir} || '.';
-my $datadir = $srcdir . '/t/Dpkg_Shlibs';
+my $datadir = test_get_data_path('t/Dpkg_Shlibs');
my @librarypaths;
@@ -58,7 +57,7 @@ Dpkg::Shlibs::blank_library_paths();
# is usually a relative path, so let's temporarily switch directory.
# XXX: An alternative would be to make parse_ldso_conf relative path aware.
my $cwd = cwd();
-chdir($srcdir);
+test_needs_srcdir_switch();
Dpkg::Shlibs::parse_ldso_conf('t/Dpkg_Shlibs/ld.so.conf');
chdir($cwd);
diff --git a/scripts/t/Dpkg_Source_Patch.t b/scripts/t/Dpkg_Source_Patch.t
index 258a9aa..8f382f5 100644
--- a/scripts/t/Dpkg_Source_Patch.t
+++ b/scripts/t/Dpkg_Source_Patch.t
@@ -17,6 +17,7 @@ use strict;
use warnings;
use Test::More tests => 9;
+use Test::Dpkg qw(:paths);
use File::Path qw(make_path);
@@ -24,8 +25,7 @@ BEGIN {
use_ok('Dpkg::Source::Patch');
}
-my $srcdir = $ENV{srcdir} || '.';
-my $datadir = $srcdir . '/t/Dpkg_Source_Patch';
+my $datadir = test_get_data_path('t/Dpkg_Source_Patch');
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 f8d82e0..af0071d 100644
--- a/scripts/t/Dpkg_Source_Quilt.t
+++ b/scripts/t/Dpkg_Source_Quilt.t
@@ -17,13 +17,13 @@ use strict;
use warnings;
use Test::More tests => 2;
+use Test::Dpkg qw(:paths);
BEGIN {
use_ok('Dpkg::Source::Quilt');
}
-my $srcdir = $ENV{srcdir} || '.';
-my $datadir = $srcdir . '/t/Dpkg_Source_Quilt';
+my $datadir = test_get_data_path('t/Dpkg_Source_Quilt');
my $quilt;
my (@series_got, @series_exp);
diff --git a/scripts/t/Dpkg_Substvars.t b/scripts/t/Dpkg_Substvars.t
index 0f6c3ce..ded25dd 100644
--- a/scripts/t/Dpkg_Substvars.t
+++ b/scripts/t/Dpkg_Substvars.t
@@ -17,14 +17,14 @@ use strict;
use warnings;
use Test::More tests => 37;
+use Test::Dpkg qw(:paths);
use Dpkg ();
use Dpkg::Arch qw(get_host_arch);
use_ok('Dpkg::Substvars');
-my $srcdir = $ENV{srcdir} || '.';
-my $datadir = $srcdir . '/t/Dpkg_Substvars';
+my $datadir = test_get_data_path('t/Dpkg_Substvars');
my $expected;
--
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