[Rt-commit] rt branch, 4.0/test-temp-file-cleanup, created. rt-4.0.2-56-g392e9a7

? sunnavy sunnavy at bestpractical.com
Tue Sep 6 23:51:14 EDT 2011


The branch, 4.0/test-temp-file-cleanup has been created
        at  392e9a72122a1c42aee02f872fb6daa5245b020d (commit)

- Log -----------------------------------------------------------------
commit 392e9a72122a1c42aee02f872fb6daa5245b020d
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Sep 7 10:46:08 2011 +0800

    create temp dirs/files consistently in tests
    
    1. make them all live under $RT::VarPath to avoid potential pullution.
    2. make paths contain test name info to help debugging.

diff --git a/t/ticket/linking.t b/t/ticket/linking.t
index dd499bf..ba236bc 100644
--- a/t/ticket/linking.t
+++ b/t/ticket/linking.t
@@ -14,7 +14,12 @@ use_ok('RT::Scrip');
 
 
 use File::Temp qw/tempfile/;
-my ($fh, $filename) = tempfile( UNLINK => 1, SUFFIX => '.rt');
+my ( $fh, $filename ) = tempfile(
+    'linking_XXXXXX',
+    UNLINK => 1,
+    SUFFIX => '.txt',
+    DIR    => $RT::VarPath,
+);
 my $link_scrips_orig = RT->Config->Get( 'LinkTransactionsRun1Scrip' );
 RT->Config->Set( 'LinkTransactionsRun1Scrip', 1 );
 
diff --git a/t/ticket/scrips_batch.t b/t/ticket/scrips_batch.t
index 1d28b67..722cd20 100644
--- a/t/ticket/scrips_batch.t
+++ b/t/ticket/scrips_batch.t
@@ -40,7 +40,12 @@ my $sid;
     is value_name($form, "Scrip-$sid-Stage"), 'TransactionBatch', 'correct stage';
 
     use File::Temp qw(tempfile);
-    my ($tmp_fh, $tmp_fn) = tempfile();
+    my ( $tmp_fh, $tmp_fn ) = tempfile(
+        'scrips_batch_XXXXXX',
+        UNLINK => 1,
+        SUFFIX => '.txt',
+        DIR    => $RT::VarPath,
+    );
 
     my $code = <<END;
 open( my \$fh, '>', '$tmp_fn' ) or die "Couldn't open '$tmp_fn':\$!";
diff --git a/t/web/attachment-with-name-0.t b/t/web/attachment-with-name-0.t
index a91db52..f8a020d 100644
--- a/t/web/attachment-with-name-0.t
+++ b/t/web/attachment-with-name-0.t
@@ -8,7 +8,7 @@ ok $m->login, 'logged in as root';
 use File::Spec;
 use File::Temp 'tempdir';
 
-my $tmpdir = tempdir( DIR => $RT::VarPath, CLEANUP => 1 );
+my $tmpdir = tempdir( 'attachment-with-name-0_XXXXXX', DIR => $RT::VarPath, CLEANUP => 1 );
 my $file = File::Spec->catfile( $tmpdir, 0 );
 open my $fh, '>', $file or die $!;
 print $fh 'foobar';
diff --git a/t/web/attachment_encoding.t b/t/web/attachment_encoding.t
index 5506bbd..52341b0 100644
--- a/t/web/attachment_encoding.t
+++ b/t/web/attachment_encoding.t
@@ -42,10 +42,13 @@ diag 'test without attachments' if $ENV{TEST_VERBOSE};
 
 diag 'test with attachemnts' if $ENV{TEST_VERBOSE};
 
-{
+use File::Temp 'tempdir';
+my $tmpdir =
+  tempdir( 'attachment_encoding_XXXXXX', DIR => $RT::VarPath, CLEANUP => 1 );
 
+{
     my $file =
-      File::Spec->catfile( File::Spec->tmpdir, encode_utf8 '附件.txt' );
+      File::Spec->catfile( $tmpdir, encode_utf8 '附件.txt' );
     open( my $fh, '>', $file ) or die $!;
     binmode $fh, ':utf8';
     print $fh '附件';
diff --git a/t/web/offline_messages_utf8.t b/t/web/offline_messages_utf8.t
index 582cc27..bf9cf39 100644
--- a/t/web/offline_messages_utf8.t
+++ b/t/web/offline_messages_utf8.t
@@ -3,7 +3,6 @@ use strict;
 use warnings;
 
 use RT::Test tests => 8;
-use File::Temp qw/tempfile/;
 use Encode;
 use RT::Ticket;
 
diff --git a/t/web/offline_utf8.t b/t/web/offline_utf8.t
index 4eb3953..7c219b5 100644
--- a/t/web/offline_utf8.t
+++ b/t/web/offline_utf8.t
@@ -9,7 +9,12 @@ use File::Temp qw/tempfile/;
 use Encode;
 
 use RT::Ticket;
-my ( $fh, $file ) = tempfile;
+my ( $fh, $file ) = tempfile(
+    'offline_utf8_XXXXXX',
+    SUFFIX   => '.txt',
+    UNLINK   => 1,
+    DIR      => $RT::VarPath,
+);
 my $template = <<EOF;
 ===Create-Ticket: ticket1
 Queue: General
diff --git a/t/web/ticket_forward.t b/t/web/ticket_forward.t
index c8205be..2fc9593 100644
--- a/t/web/ticket_forward.t
+++ b/t/web/ticket_forward.t
@@ -5,8 +5,12 @@ use warnings;
 use RT::Test tests => undef;
 use File::Temp 'tempfile';
 use File::Spec;
-my ( $att_fh, $att_file ) =
-  tempfile( 'rttestXXXXXX', SUFFIX => '.txt', UNLINK => 1, TMPDIR => 1 );
+my ( $att_fh, $att_file ) = tempfile(
+    'ticket_forward_XXXXXX',
+    SUFFIX => '.txt',
+    UNLINK => 1,
+    DIR    => $RT::VarPath,
+);
 print $att_fh "this is an attachment";
 close $att_fh;
 my $att_name = ( File::Spec->splitpath($att_file) )[-1];
diff --git a/t/web/ticket_txn_content.t b/t/web/ticket_txn_content.t
index 06ea7e7..3b84cb3 100644
--- a/t/web/ticket_txn_content.t
+++ b/t/web/ticket_txn_content.t
@@ -4,14 +4,22 @@ use strict;
 use RT::Test tests => 63;
 use File::Temp 'tempfile';
 use File::Spec;
-my ( $plain_fh, $plain_file ) =
-  tempfile( 'rttestXXXXXX', SUFFIX => '.txt', UNLINK => 1, TMPDIR => 1 );
+my ( $plain_fh, $plain_file ) = tempfile(
+    'ticket_txn_content_XXXXX',
+    SUFFIX => '.txt',
+    UNLINK => 1,
+    DIR    => $RT::VarPath,
+);
 print $plain_fh "this is plain content";
 close $plain_fh;
 my $plain_name = (File::Spec->splitpath($plain_file))[-1];
 
-my ( $html_fh, $html_file ) =
-  tempfile( 'rttestXXXXXX', SUFFIX => '.html', UNLINK => 1, TMPDIR => 1 );
+my ( $html_fh, $html_file ) = tempfile(
+    'ticket_txn_content_XXXXXX',
+    SUFFIX => '.html',
+    UNLINK => 1,
+    DIR    => $RT::VarPath,
+);
 print $html_fh "this is html content";
 close $html_fh;
 my $html_name = (File::Spec->splitpath($html_file))[-1];

-----------------------------------------------------------------------


More information about the Rt-commit mailing list