Преглед на файлове

scripts/t: Make sure temporary files are always cleaned up

If the test suite is interrupted or it fails in the middle, the
temporary files will not be unlinked. Switch to use the native
File::Temp support for removal.
Guillem Jover преди 11 години
родител
ревизия
386e46306f
променени са 3 файла, в които са добавени 8 реда и са изтрити 10 реда
  1. 2 0
      debian/changelog
  2. 2 5
      scripts/t/Dpkg_IPC.t
  3. 4 5
      scripts/t/merge_changelogs.t

+ 2 - 0
debian/changelog

@@ -101,6 +101,8 @@ dpkg (1.17.14) UNRELEASED; urgency=low
     wildcard (-W), endianness (-E) or bits (-B). The restricting options can
     wildcard (-W), endianness (-E) or bits (-B). The restricting options can
     be combined, or omitted altogether. Closes: #762635
     be combined, or omitted altogether. Closes: #762635
   * Say arch-wildcard instead of arch-alias in dpkg-architecture --help output.
   * Say arch-wildcard instead of arch-alias in dpkg-architecture --help output.
+  * Test suite:
+    - Do not leave temporary files behind on failure or when interrupted.
 
 
   [ Raphaël Hertzog ]
   [ Raphaël Hertzog ]
   * Explain better in deb-triggers(5) why interest/activate-noawait should be
   * Explain better in deb-triggers(5) why interest/activate-noawait should be

+ 2 - 5
scripts/t/Dpkg_IPC.t

@@ -23,8 +23,8 @@ use_ok('Dpkg::IPC');
 
 
 $/ = undef;
 $/ = undef;
 
 
-my ($tmp1_fh, $tmp1_name) = tempfile;
-my ($tmp2_fh, $tmp2_name) = tempfile;
+my ($tmp1_fh, $tmp1_name) = tempfile(UNLINK => 1);
+my ($tmp2_fh, $tmp2_name) = tempfile(UNLINK => 1);
 my $tmp_fh;
 my $tmp_fh;
 
 
 my $string1 = "foo\nbar\n";
 my $string1 = "foo\nbar\n";
@@ -79,6 +79,3 @@ eval {
 	         timeout => 5);
 	         timeout => 5);
 };
 };
 ok($@, 'fails on timeout');
 ok($@, 'fails on timeout');
-
-unlink($tmp1_name);
-unlink($tmp2_name);

+ 4 - 5
scripts/t/merge_changelogs.t

@@ -21,7 +21,7 @@ use Test::More tests => 3;
 use Dpkg::IPC;
 use Dpkg::IPC;
 use File::Spec;
 use File::Spec;
 use File::Compare;
 use File::Compare;
-use File::Temp qw(tempfile);
+use File::Temp;
 
 
 my $srcdir = $ENV{srcdir} || '.';
 my $srcdir = $ENV{srcdir} || '.';
 my $datadir = "$srcdir/t/merge_changelogs";
 my $datadir = "$srcdir/t/merge_changelogs";
@@ -29,16 +29,15 @@ my $datadir = "$srcdir/t/merge_changelogs";
 my $res;
 my $res;
 sub test_merge {
 sub test_merge {
     my ($expected_file, @options) = @_;
     my ($expected_file, @options) = @_;
-    my ($fh, $filename) = tempfile();
+    my $fh = File::Temp->new();
     spawn(exec => ["$srcdir/dpkg-mergechangelogs.pl", @options],
     spawn(exec => ["$srcdir/dpkg-mergechangelogs.pl", @options],
 	  to_handle => $fh, error_to_file => '/dev/null',
 	  to_handle => $fh, error_to_file => '/dev/null',
 	  wait_child => 1, nocheck => 1);
 	  wait_child => 1, nocheck => 1);
-    my $res = compare($expected_file, $filename);
+    my $res = compare($expected_file, $fh->filename);
     if ($res) {
     if ($res) {
-	system("diff -u $expected_file $filename >&2");
+	system("diff -u $expected_file $fh->filename >&2");
     }
     }
     ok($res == 0, "merged changelog matches expected one ($expected_file)");
     ok($res == 0, "merged changelog matches expected one ($expected_file)");
-    unlink($filename);
 }
 }
 
 
 my $has_alg_merge = 1;
 my $has_alg_merge = 1;