Skip to content

Commit

Permalink
Item12189: Better control of temp files
Browse files Browse the repository at this point in the history
Test runner was trying to log to root.  This is also related to the
Logger changes.  It depended upon auto-switch to the Compatibility
logger, which only happens if PlainFile is enabled in the Local config.

Explicitly set the logger to Compatibility, and set a logging file path
so that nothing goes into the system log directory.

Added logdir to the cleanup routines, so the logs don't continue to grow
forever.  Also don't override / unlink log files in individual tests
since the log location is controlled.  Except for CommentPlugin which needs to
evaluate the logfile.

git-svn-id: http://svn.foswiki.org/trunk@15724 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Oct 25, 2012
1 parent 11bdf9b commit 6517a40
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
6 changes: 6 additions & 0 deletions UnitTestContrib/test/bin/TestRunner.pl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ BEGIN
File::Path::rmtree($x) if $x;
}
closedir $pubDir;

my $logDir = Cwd::getcwd() . '/testlogs';
if ( -d $logDir ) {
File::Path::rmtree($logDir);
}

}

if ( not $options{-worker} ) {
Expand Down
25 changes: 18 additions & 7 deletions UnitTestContrib/test/unit/FoswikiTestCase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -660,15 +660,26 @@ sub set_up {
mkdir("$Foswiki::cfg{WorkingDir}/tmp");
mkdir("$Foswiki::cfg{WorkingDir}/registration_approvals");
mkdir("$Foswiki::cfg{WorkingDir}/work_areas");
mkdir("$Foswiki::cfg{WorkingDir}/requestTmp");

# Note this does not do much, except for some tests that use it directly.
# The first call to File::Temp caches the temp directory name, so
# this value won't get used for anything created by File::Temp
$Foswiki::cfg{TempfileDir} = "$Foswiki::cfg{WorkingDir}/requestTmp";

# Move logging into a temporary directory
$Foswiki::cfg{LogFileName} =
"$Foswiki::cfg{TempfileDir}/FoswikiTestCase.log";
$Foswiki::cfg{WarningFileName} =
"$Foswiki::cfg{TempfileDir}/FoswikiTestCase.warn";
$Foswiki::cfg{AdminUserWikiName} = 'AdminUser';
$Foswiki::cfg{AdminUserLogin} = 'root';
$Foswiki::cfg{SuperAdminGroup} = 'AdminGroup';
my $logdir = Cwd::getcwd() . '/testlogs';
$logdir =~ m/^(.*)$/;
$logdir = $1;
$Foswiki::cfg{Log}{Dir} = $logdir;
mkdir($logdir) unless -d $logdir;
$Foswiki::cfg{Log}{Implementation} = 'Foswiki::Logger::Compatibility';
$Foswiki::cfg{LogFileName} = "$logdir/FoswikiTestCase.log";
$Foswiki::cfg{WarningFileName} = "$logdir/FoswikiTestCase.warn";
$Foswiki::cfg{DebugFileName} = "$logdir/FoswikiTestCase.debug";
$Foswiki::cfg{AdminUserWikiName} = 'AdminUser';
$Foswiki::cfg{AdminUserLogin} = 'root';
$Foswiki::cfg{SuperAdminGroup} = 'AdminGroup';

# This must be done *after* disabling/enabling the plugins
# so that tests derived from this class can enable additional plugins.
Expand Down
2 changes: 0 additions & 2 deletions UnitTestContrib/test/unit/RCSHandlerTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ sub set_up {
$Foswiki::Sandbox::REAL_SAFE_PIPE_OPEN = 0;
$Foswiki::Sandbox::EMULATED_SAFE_PIPE_OPEN = 0;

$Foswiki::cfg{WarningFileName} = "$Foswiki::cfg{TempfileDir}/junk";
File::Path::mkpath("$Foswiki::cfg{DataDir}/$testWeb");
File::Path::mkpath("$Foswiki::cfg{PubDir}/$testWeb");
$this->assert( open( F, ">$Foswiki::cfg{TempfileDir}/itme3122" ), $! );
Expand All @@ -115,7 +114,6 @@ sub tear_down {
# Restore the PIPE settings in Sandbox
$Foswiki::Sandbox::REAL_SAFE_PIPE_OPEN = 1;
$Foswiki::Sandbox::EMULATED_SAFE_PIPE_OPEN = 1;
unlink $Foswiki::cfg{WarningFileName};
unlink "$Foswiki::cfg{TempfileDir}/itme3122";
File::Path::rmtree("$Foswiki::cfg{DataDir}/$testWeb");
File::Path::rmtree("$Foswiki::cfg{PubDir}/$testWeb");
Expand Down
5 changes: 0 additions & 5 deletions UnitTestContrib/test/unit/VCMetaTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ sub set_up_for_verify {

$UI_FN ||= $this->getUIFn('save');

$Foswiki::cfg{WarningFileName} = "$Foswiki::cfg{TempfileDir}/junk";
$Foswiki::cfg{LogFileName} = "$Foswiki::cfg{TempfileDir}/junk";

$this->createNewFoswikiSession();

$testUser1 = "DummyUserOne";
Expand All @@ -42,8 +39,6 @@ sub set_up_for_verify {

sub tear_down {
my $this = shift;
unlink $Foswiki::cfg{WarningFileName};
unlink $Foswiki::cfg{LogFileName};
$this->SUPER::tear_down();

return;
Expand Down
3 changes: 2 additions & 1 deletion core/lib/Foswiki.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,8 @@ sub new {
ASSERT( !$query || UNIVERSAL::isa( $query, 'Foswiki::Request' ) )
if DEBUG;

unless ( defined $Foswiki::cfg{TempfileDir} ) {
unless ( defined $Foswiki::cfg{TempfileDir} && $Foswiki::cfg{TempfileDir} )
{

# Give it a sane default.
if ( $^O eq 'MSWin32' ) {
Expand Down

0 comments on commit 6517a40

Please sign in to comment.