Permalink
Browse files

cleanup after tests

these three tests start servers and then kill process.
killing a process leaves tempdirs. Instead we create tempdir
in the main test program and cleanup it there
  • Loading branch information...
1 parent ab48b2a commit 4a150599c0b18d9f767776efa045b78345687c6d @ruz ruz committed Oct 2, 2009
Showing with 30 additions and 13 deletions.
  1. +12 −7 t/01live.t
  2. +9 −3 t/04unhandlederrors.t
  3. +9 −3 t/05handlederrors.t
View
@@ -8,9 +8,11 @@ BEGIN {
}
}
-use_ok( HTTP::Server::Simple::Mason);
+use_ok(HTTP::Server::Simple::Mason);
-my $s=MyApp::Server->new(13432);
+use File::Temp qw/tempdir/;
+my $mason_root = tempdir( CLEANUP => 1 );
+my $s=MyApp::Server->new(13432, $mason_root);
is($s->port(),13432,"Constructor set port correctly");
my $pid=$s->background();
like($pid, qr/^-?\d+$/,'pid is numeric');
@@ -20,16 +22,19 @@ like($content,qr/2$/,"Returns a page containing only 2");
is(kill(9,$pid),1,'Signaled 1 process successfully');
-
-
package MyApp::Server;
use base qw/HTTP::Server::Simple::Mason/;
use File::Spec;
-use File::Temp qw/tempdir/;
+my $root;
+sub new {
+ $root = $_[2];
+ return shift->SUPER::new( @_ );
+}
+
sub mason_config {
- my $root = tempdir( CLEANUP => 1 );
- open (PAGE, '>', File::Spec->catfile($root, 'index.html')) or die $!;
+ open (PAGE, '>', File::Spec->catfile($root, 'index.html'))
+ or die $!;
print PAGE '<%1+1%>';
close (PAGE);
return ( comp_root => $root );
View
@@ -10,7 +10,9 @@ BEGIN {
use_ok( HTTP::Server::Simple::Mason);
-my $s=MyApp::Server->new(13432);
+use File::Temp qw/tempdir/;
+my $mason_root = tempdir( CLEANUP => 1 );
+my $s=MyApp::Server->new(13432, $mason_root);
is($s->port(),13432,"Constructor set port correctly");
my $pid=$s->background();
like($pid, qr/^-?\d+$/,'pid is numeric');
@@ -25,10 +27,14 @@ is(kill(9,$pid),1,'Signaled 1 process successfully');
package MyApp::Server;
use base qw/HTTP::Server::Simple::Mason/;
use File::Spec;
-use File::Temp qw/tempdir/;
+
+my $root;
+sub new {
+ $root = $_[2];
+ return shift->SUPER::new( @_ );
+}
sub mason_config {
- my $root = tempdir( CLEANUP => 1 );
open (PAGE, '>', File::Spec->catfile($root, 'index.html')) or die $!;
print PAGE '<%die%>';
close (PAGE);
View
@@ -10,7 +10,9 @@ BEGIN {
use_ok( HTTP::Server::Simple::Mason);
-my $s=MyApp::Server->new(13432);
+use File::Temp qw/tempdir/;
+my $mason_root = tempdir( CLEANUP => 1 );
+my $s=MyApp::Server->new(13432, $mason_root);
is($s->port(),13432,"Constructor set port correctly");
my $pid=$s->background();
like($pid, qr/^-?\d+$/,'pid is numeric');
@@ -25,10 +27,14 @@ is(kill(9,$pid),1,'Signaled 1 process successfully');
package MyApp::Server;
use base qw/HTTP::Server::Simple::Mason/;
use File::Spec;
-use File::Temp qw/tempdir/;
+
+my $root;
+sub new {
+ $root = $_[2];
+ return shift->SUPER::new( @_ );
+}
sub mason_config {
- my $root = tempdir(CLEANUP => 1);
open (PAGE, '>', File::Spec->catfile($root, 'index.html')) or die $!;
print PAGE '<%die%>';
close (PAGE);

0 comments on commit 4a15059

Please sign in to comment.