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";
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;
+ }
+}