Browse Source

test: Refactor unit test data path into test_get_data_path()

Guillem Jover 7 years ago
parent
commit
2f05b55f03

+ 14 - 0
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);

+ 2 - 2
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();
 

+ 6 - 2
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";

+ 2 - 2
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 = (
     {

+ 2 - 2
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);
 

+ 2 - 3
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;

+ 2 - 2
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;

+ 2 - 2
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 = (

+ 3 - 4
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);
 

+ 2 - 2
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 {

+ 2 - 2
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);

+ 2 - 2
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;