[Rt-commit] rt branch, 4.0/refactor-temp-dir-in-test, created. rt-4.0.2-180-gd91f69a
? sunnavy
sunnavy at bestpractical.com
Tue Oct 4 06:02:09 EDT 2011
The branch, 4.0/refactor-temp-dir-in-test has been created
at d91f69a645bee3f74b2e86e9f06648b1433b1c02 (commit)
- Log -----------------------------------------------------------------
commit 598ad557d870c03d837b839870f1caa5da12344d
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Oct 4 11:59:09 2011 +0800
use RT::Test->temp_directory as temp dir in tests.
it's consistent and easy to debug/cleanup in this way.
shredder tests still use tmpdir() in utils.pl though as it's a bit complex.
diff --git a/t/ticket/linking.t b/t/ticket/linking.t
index dd499bf..bf95efa 100644
--- a/t/ticket/linking.t
+++ b/t/ticket/linking.t
@@ -13,8 +13,10 @@ use_ok('RT::Scrips');
use_ok('RT::Scrip');
-use File::Temp qw/tempfile/;
-my ($fh, $filename) = tempfile( UNLINK => 1, SUFFIX => '.rt');
+my $filename = File::Spec->catfile( RT::Test->temp_directory, 'temp' );
+open my $fh, '>', $filename or die $!;
+close $fh;
+
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..8294cc4 100644
--- a/t/ticket/scrips_batch.t
+++ b/t/ticket/scrips_batch.t
@@ -39,8 +39,8 @@ my $sid;
is value_name($form, "Scrip-$sid-Template"), 'Global template: Blank', 'correct template';
is value_name($form, "Scrip-$sid-Stage"), 'TransactionBatch', 'correct stage';
- use File::Temp qw(tempfile);
- my ($tmp_fh, $tmp_fn) = tempfile();
+ my $tmp_fn = File::Spec->catfile( RT::Test->temp_directory, 'temp' );
+ open my $tmp_fh, '+>', $tmp_fn or die $!;
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..12a8dd5 100644
--- a/t/web/attachment-with-name-0.t
+++ b/t/web/attachment-with-name-0.t
@@ -6,10 +6,8 @@ my ( $baseurl, $m ) = RT::Test->started_ok;
ok $m->login, 'logged in as root';
use File::Spec;
-use File::Temp 'tempdir';
-my $tmpdir = tempdir( DIR => $RT::VarPath, CLEANUP => 1 );
-my $file = File::Spec->catfile( $tmpdir, 0 );
+my $file = File::Spec->catfile( RT::Test->temp_directory, 0 );
open my $fh, '>', $file or die $!;
print $fh 'foobar';
close $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..24795c0 100644
--- a/t/web/offline_utf8.t
+++ b/t/web/offline_utf8.t
@@ -5,11 +5,11 @@ use warnings;
use RT::Test tests => 9;
use utf8;
-use File::Temp qw/tempfile/;
use Encode;
use RT::Ticket;
-my ( $fh, $file ) = tempfile;
+my $file = File::Spec->catfile( RT::Test->temp_directory, 'template' );
+open my $fh, '>', $file or die $!;
my $template = <<EOF;
===Create-Ticket: ticket1
Queue: General
diff --git a/t/web/ticket_forward.t b/t/web/ticket_forward.t
index c8205be..be06ad9 100644
--- a/t/web/ticket_forward.t
+++ b/t/web/ticket_forward.t
@@ -3,10 +3,9 @@ use strict;
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_file = File::Spec->catfile( RT::Test->temp_directory, 'attachment' );
+open my $att_fh, '>', $att_file or die $!;
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..db47512 100644
--- a/t/web/ticket_txn_content.t
+++ b/t/web/ticket_txn_content.t
@@ -2,17 +2,15 @@
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_file = File::Spec->catfile( RT::Test->temp_directory, 'attachment.txt' );
+open my $plain_fh, '>', $plain_file or die $!;
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 );
-print $html_fh "this is html content";
+my $html_file = File::Spec->catfile( RT::Test->temp_directory, 'attachment.html' );
+open my $html_fh, '>', $html_file or die $!;
+print $html_fh "this is plain content";
close $html_fh;
my $html_name = (File::Spec->splitpath($html_file))[-1];
commit d91f69a645bee3f74b2e86e9f06648b1433b1c02
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Oct 4 17:54:10 2011 +0800
make shredder's tests use RT::Test->temp_directory too
diff --git a/t/shredder/utils.pl b/t/shredder/utils.pl
index b8409bf..5f5c182 100644
--- a/t/shredder/utils.pl
+++ b/t/shredder/utils.pl
@@ -3,20 +3,15 @@
use strict;
use warnings;
-use File::Spec;
-use File::Temp 0.19 ();
-require File::Path;
require File::Copy;
require Cwd;
+require RT::Test;
BEGIN {
### after: push @INC, qw(@RT_LIB_PATH@);
}
use RT::Shredder;
-# where to keep temporary generated test data
-my $tmpdir = '';
-
=head1 DESCRIPTION
RT::Shredder test suite utilities
@@ -94,7 +89,7 @@ sub rewrite_rtconfig
config_set( '$LogStackTraces' , 'crit' );
# logging to standalone file
config_set( '$LogToFile' , 'debug' );
- my $fname = File::Spec->catfile(create_tmpdir(), test_name() .".log");
+ my $fname = File::Spec->catfile(RT::Test->temp_directory(), test_name() .".log");
config_set( '$LogToFileNamed' , $fname );
config_set('@LexiconLanguages', qw(en));
}
@@ -127,7 +122,7 @@ in most situations.
sub init_db
{
- create_tmpdir();
+ RT::Test->bootstrap_tempdir() unless RT::Test->temp_directory();
RT::LoadConfig();
rewrite_rtconfig();
RT::InitLogging();
@@ -161,13 +156,13 @@ sub _init_db
=head3 db_name
Returns the absolute file path to the current DB.
-It is <$tmpdir . test_name() .'.db'>.
+It is <<RT::Test->temp_directory . test_name() .'.db'>>.
See also the C<test_name> function.
=cut
-sub db_name { return File::Spec->catfile(create_tmpdir(), test_name() .".db") }
+sub db_name { return File::Spec->catfile(RT::Test->temp_directory(), test_name() .".db") }
=head3 connect_sqlite
@@ -194,7 +189,7 @@ sub shredder_new
{
my $obj = RT::Shredder->new;
- my $file = File::Spec->catfile( create_tmpdir(), test_name() .'.XXXX.sql' );
+ my $file = File::Spec->catfile( RT::Test->temp_directory, test_name() .'.XXXX.sql' );
$obj->AddDumpPlugin( Arguments => {
file_name => $file,
from_storage => 0,
@@ -223,44 +218,6 @@ sub test_name
return $name;
}
-=head2 TEMPORARY DIRECTORY
-
-=head3 tmpdir
-
-Returns the absolute path to a tmp dir used in tests.
-
-=cut
-
-sub tmpdir {
- if (-d $tmpdir) {
- return $tmpdir;
- } else {
- $tmpdir = File::Temp->newdir(TEMPLATE => 'shredderXXXXX', CLEANUP => 0);
- return $tmpdir;
- }
-}
-
-=head2 create_tmpdir
-
-Creates a tmp dir if one doesn't exist already. Returns tmpdir path.
-
-=cut
-
-sub create_tmpdir { my $n = tmpdir(); File::Path::mkpath( [$n] ); return $n }
-
-=head3 cleanup_tmp
-
-Deletes all the tmp dir used in the tests.
-See also the C<test_name> function.
-
-=cut
-
-sub cleanup_tmp
-{
- my $dir = File::Spec->catdir(tmpdir(), test_name());
- return File::Path::rmtree( File::Spec->catdir( tmpdir(), test_name() ));
-}
-
=head2 SAVEPOINTS
=head3 savepoint_name
@@ -273,7 +230,7 @@ Takes one argument - savepoint name, by default C<sp>.
sub savepoint_name
{
my $name = shift || 'sp';
- return File::Spec->catfile( create_tmpdir(), test_name() .".$name.db" );
+ return File::Spec->catfile( RT::Test->temp_directory, test_name() .".$name.db" );
}
=head3 create_savepoint
@@ -412,7 +369,7 @@ Returns a note about debug info that you can display if tests fail.
sub note_on_fail
{
my $name = test_name();
- my $tmpdir = tmpdir();
+ my $tmpdir = RT::Test->temp_directory();
return <<END;
Some tests in '$0' file failed.
You can find debug info in '$tmpdir' dir.
@@ -424,27 +381,9 @@ See also perldoc t/shredder/utils.pl for how to use this info.
END
}
-=head2 OTHER
-
-=head3 all_were_successful
-
-Returns true if all tests that have already run were successful.
-
-=cut
-
-sub all_were_successful
-{
- use Test::Builder;
- my $Test = Test::Builder->new;
- return grep( !$_, $Test->summary )? 0: 1;
-}
-
END {
- return unless -e tmpdir();
- if ( all_were_successful() ) {
- cleanup_tmp();
- } else {
- diag( note_on_fail() );
+ if ( ! RT::Test->builder->is_passing ) {
+ diag( note_on_fail() );
}
}
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list