[dpkg] 16/28: test: Infer automatically the unit test temp directory

Mattia Rizzolo mattia at debian.org
Mon Jan 22 17:11:24 UTC 2018


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

mattia pushed a commit to branch master
in repository dpkg.

commit 876855ff96f6dd72cbb92fa57bc316576f585737
Author: Guillem Jover <guillem at debian.org>
Date:   Sun Oct 29 18:40:54 2017 +0100

    test: Infer automatically the unit test temp directory
    
    Add new test_get_temp_path() function, and replace all hardcoded
    settings of the temporary directory and its creation.
---
 debian/changelog              |  1 +
 scripts/Test/Dpkg.pm          | 13 +++++++++++++
 scripts/t/Dpkg_Compression.t  |  4 ++--
 scripts/t/Dpkg_OpenPGP.t      |  4 +---
 scripts/t/Dpkg_Path.t         |  4 ++--
 scripts/t/Dpkg_Source_Patch.t |  2 +-
 scripts/t/dpkg_buildpackage.t |  6 ++----
 scripts/t/dpkg_source.t       |  6 ++----
 8 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 761acad..813b170 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -51,6 +51,7 @@ dpkg (1.19.1) UNRELEASED; urgency=medium
     - Check POD in all perl scripts.
     - Consider *.PL also to be perl files.
     - Infer automatically the unit test data directory.
+    - Infer automatically the unit test temp directory.
 
   [ Updated programs translations ]
   * Dutch (Frans Spiesschaert). Closes: #881401
diff --git a/scripts/Test/Dpkg.pm b/scripts/Test/Dpkg.pm
index 2a3fec2..5eea618 100644
--- a/scripts/Test/Dpkg.pm
+++ b/scripts/Test/Dpkg.pm
@@ -24,6 +24,7 @@ our @EXPORT_OK = qw(
     all_perl_modules
     test_get_perl_dirs
     test_get_data_path
+    test_get_temp_path
     test_needs_author
     test_needs_module
     test_needs_command
@@ -42,11 +43,14 @@ our %EXPORT_TAGS = (
         all_perl_modules
         test_get_perl_dirs
         test_get_data_path
+        test_get_temp_path
     ) ],
 );
 
 use Exporter qw(import);
 use File::Find;
+use File::Basename;
+use File::Path qw(make_path);
 use IPC::Cmd qw(can_run);
 use Test::More;
 
@@ -72,6 +76,15 @@ sub test_get_data_path
     }
 }
 
+sub test_get_temp_path
+{
+    my $path = shift // _test_get_caller_dir();
+    $path = 't.tmp/' . fileparse($path);
+
+    make_path($path);
+    return $path;
+}
+
 sub test_get_perl_dirs
 {
     return qw(t src/t lib utils/t scripts dselect);
diff --git a/scripts/t/Dpkg_Compression.t b/scripts/t/Dpkg_Compression.t
index 3a2be11..3babe5f 100644
--- a/scripts/t/Dpkg_Compression.t
+++ b/scripts/t/Dpkg_Compression.t
@@ -17,12 +17,12 @@ use strict;
 use warnings;
 
 use Test::More tests => 13;
+use Test::Dpkg qw(:paths);
 
 use_ok('Dpkg::Compression');
 use_ok('Dpkg::Compression::FileHandle');
 
-my $tmpdir = 't.tmp/Dpkg_Compression';
-mkdir $tmpdir;
+my $tmpdir = test_get_temp_path();
 my @lines = ("One\n", "Two\n", "Three\n");
 my $fh;
 
diff --git a/scripts/t/Dpkg_OpenPGP.t b/scripts/t/Dpkg_OpenPGP.t
index 0d2e4af..b396131 100644
--- a/scripts/t/Dpkg_OpenPGP.t
+++ b/scripts/t/Dpkg_OpenPGP.t
@@ -32,9 +32,7 @@ use_ok('Dpkg::OpenPGP');
 report_options(quiet_warnings => 1);
 
 my $datadir = test_get_data_path();
-my $tmpdir = 't.tmp/Dpkg_OpenPGP';
-
-mkdir $tmpdir;
+my $tmpdir = test_get_temp_path();
 
 openpgp_sig_to_asc("$datadir/package_1.0.orig.tar.sig",
                    "$tmpdir/package_1.0.orig.tar.sig2asc");
diff --git a/scripts/t/Dpkg_Path.t b/scripts/t/Dpkg_Path.t
index deb63ba..fbf883d 100644
--- a/scripts/t/Dpkg_Path.t
+++ b/scripts/t/Dpkg_Path.t
@@ -17,14 +17,14 @@ use strict;
 use warnings;
 
 use Test::More tests => 16;
+use Test::Dpkg qw(:paths);
 
 use_ok('Dpkg::Path', 'canonpath', 'resolve_symlink',
        'check_files_are_the_same', 'get_pkg_root_dir',
        'guess_pkg_root_dir', 'relative_to_pkg_root');
 
-my $tmpdir = 't.tmp/Dpkg_Path';
+my $tmpdir = test_get_temp_path();
 
-mkdir $tmpdir;
 mkdir "$tmpdir/a";
 mkdir "$tmpdir/a/b";
 mkdir "$tmpdir/a/b/c";
diff --git a/scripts/t/Dpkg_Source_Patch.t b/scripts/t/Dpkg_Source_Patch.t
index d0e167d..f50f15b 100644
--- a/scripts/t/Dpkg_Source_Patch.t
+++ b/scripts/t/Dpkg_Source_Patch.t
@@ -26,7 +26,7 @@ BEGIN {
 }
 
 my $datadir = test_get_data_path();
-my $tmpdir = 't.tmp/Dpkg_Source_Patch';
+my $tmpdir = test_get_temp_path();
 
 sub test_patch_escape {
     my ($name, $symlink, $patchname, $desc) = @_;
diff --git a/scripts/t/dpkg_buildpackage.t b/scripts/t/dpkg_buildpackage.t
index 2b43455..dd4f67a 100644
--- a/scripts/t/dpkg_buildpackage.t
+++ b/scripts/t/dpkg_buildpackage.t
@@ -17,7 +17,7 @@ use strict;
 use warnings;
 
 use Test::More;
-use Test::Dpkg qw(:needs test_neutralize_checksums);
+use Test::Dpkg qw(:needs :paths test_neutralize_checksums);
 
 use File::Spec::Functions qw(rel2abs);
 use File::Compare;
@@ -34,7 +34,7 @@ plan tests => 12;
 
 my $srcdir = rel2abs($ENV{srcdir} || '.');
 my $datadir = "$srcdir/t/dpkg_buildpackage";
-my $tmpdir = 't.tmp/dpkg_buildpackage';
+my $tmpdir = test_get_temp_path();
 
 $ENV{$_} = rel2abs($ENV{$_}) foreach qw(DPKG_DATADIR DPKG_ORIGINS_DIR);
 
@@ -48,8 +48,6 @@ delete $ENV{SOURCE_DATE_EPOCH};
 # Delete other variables that can affect the tests.
 delete $ENV{$_} foreach grep { m/^DEB_/ } keys %ENV;
 
-make_path($tmpdir);
-
 chdir $tmpdir;
 
 my $tmpl_format = <<'TMPL_FORMAT';
diff --git a/scripts/t/dpkg_source.t b/scripts/t/dpkg_source.t
index cdbedce..a0c3438 100644
--- a/scripts/t/dpkg_source.t
+++ b/scripts/t/dpkg_source.t
@@ -17,7 +17,7 @@ use strict;
 use warnings;
 
 use Test::More tests => 8;
-use Test::Dpkg qw(test_neutralize_checksums);
+use Test::Dpkg qw(:paths test_neutralize_checksums);
 
 use File::Spec::Functions qw(rel2abs);
 use File::Compare;
@@ -28,15 +28,13 @@ use Dpkg::Substvars;
 
 my $srcdir = rel2abs($ENV{srcdir} || '.');
 my $datadir = "$srcdir/t/dpkg_source";
-my $tmpdir = 't.tmp/dpkg_source';
+my $tmpdir = test_get_temp_path();
 
 $ENV{$_} = rel2abs($ENV{$_}) foreach qw(DPKG_DATADIR DPKG_ORIGINS_DIR);
 
 # Delete variables that can affect the tests.
 delete $ENV{SOURCE_DATE_EPOCH};
 
-make_path($tmpdir);
-
 chdir $tmpdir;
 
 my $tmpl_format = <<'TMPL_FORMAT';

-- 
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