X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Foptional%2Fapache-cgi.pl;h=a6cf88127f2015a72201d91bc931c33957fed22a;hb=496021a4740bcccf5b630f9fbd6f6bff0882dfc7;hp=7864b39e66012f52ffc93c4af9222c3e910e56c4;hpb=10bdcbe8078d0136e2bc53f47ea1f63e36c947a8;p=catagits%2FCatalyst-Runtime.git diff --git a/t/optional/apache-cgi.pl b/t/optional/apache-cgi.pl index 7864b39..a6cf881 100755 --- a/t/optional/apache-cgi.pl +++ b/t/optional/apache-cgi.pl @@ -16,6 +16,7 @@ use Apache::TestRun (); use File::Path; use File::Copy::Recursive; use FindBin; +use IO::Socket; # clean up rmtree "$FindBin::Bin/../../t/tmp" if -d "$FindBin::Bin/../../t/tmp"; @@ -34,5 +35,25 @@ $ENV{CATALYST_SERVER} = 'http://localhost:8529/cgi'; Apache::TestRun->new->run(@ARGV); -# clean up -rmtree "$FindBin::Bin/../../t/tmp" if -d "$FindBin::Bin/../../t/tmp"; +# clean up if the server has shut down +# this allows the test files to stay around if the user ran -start-httpd +if ( ! check_port( 'localhost', 8529 ) ) { + rmtree "$FindBin::Bin/../../t/tmp" if -d "$FindBin::Bin/../../t/tmp"; +} + +sub check_port { + my ( $host, $port ) = @_; + + my $remote = IO::Socket::INET->new( + Proto => "tcp", + PeerAddr => $host, + PeerPort => $port + ); + if ($remote) { + close $remote; + return 1; + } + else { + return 0; + } +}