diff options
author | Guillem Jover <guillem@debian.org> | 2017-10-29 18:40:54 +0100 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2018-01-16 10:55:30 +0100 |
commit | 876855ff96f6dd72cbb92fa57bc316576f585737 (patch) | |
tree | b82cda0a0cf5df51976aa3815d7c428a09bed6d7 | |
parent | 33c866433dd4b186aae970e05c639b52ad5e7ece (diff) | |
download | dpkg-876855ff96f6dd72cbb92fa57bc316576f585737.tar.gz |
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.
-rw-r--r-- | debian/changelog | 1 | ||||
-rw-r--r-- | scripts/Test/Dpkg.pm | 13 | ||||
-rw-r--r-- | scripts/t/Dpkg_Compression.t | 4 | ||||
-rw-r--r-- | scripts/t/Dpkg_OpenPGP.t | 4 | ||||
-rw-r--r-- | scripts/t/Dpkg_Path.t | 4 | ||||
-rw-r--r-- | scripts/t/Dpkg_Source_Patch.t | 2 | ||||
-rw-r--r-- | scripts/t/dpkg_buildpackage.t | 6 | ||||
-rw-r--r-- | scripts/t/dpkg_source.t | 6 |
8 files changed, 24 insertions, 16 deletions
diff --git a/debian/changelog b/debian/changelog index 761acad10..813b17053 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 2a3fec219..5eea6184a 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 3a2be1107..3babe5fca 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 0d2e4afef..b39613149 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 deb63bab7..fbf883d64 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 d0e167dbd..f50f15be2 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 2b4345539..dd4f67a6f 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 cdbedceb3..a0c343846 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'; |