Permalink
Browse files

try to find start_server from $PATH and $^X, or skip most tests (but …

…not all) if not found
  • Loading branch information...
1 parent 483960c commit 1a1209f91d1b16fc5e467864df8e9394690812e5 @kazuho committed Jan 6, 2010
Showing with 32 additions and 22 deletions.
  1. +2 −1 Makefile.PL
  2. +30 −21 t/00base.t
View
@@ -7,6 +7,7 @@ requires 'Plack' => 0.9020;
requires 'Parallel::Prefork' => 0.05; # since Plack does not intentionally requires P::Prefork required by Standalone::Prefork
requires 'Server::Starter' => 0.05;
-test_requires 'Test::TCP' => 0.15;
+test_requires 'Test::More' => 0.88;
+test_requires 'Test::TCP' => 0.15;
WriteAll;
View
@@ -1,34 +1,43 @@
use strict;
use warnings;
+use File::Basename ();
use LWP::Simple ();
use Test::TCP ();
-use Test::More tests => 2;
+use Test::More;
BEGIN {
use_ok('Server::Starter');
};
-my $port = Test::TCP::empty_port();
-
-my $server_pid = fork();
-die "fork failed:$!"
- unless defined $server_pid;
-if ($server_pid == 0) {
- # child == server
- exec(
- "start_server",
- "--port=$port",
- qw(-- plackup -s Standalone::Prefork::Server::Starter t/00base-hello.psgi),
- );
- die "failed to launch server using start_server:$!";
+my ($start_server) = grep { -x $_ } map { "$_/start_server" } (
+ File::Basename::dirname($^X),
+ split /:/, $ENV{PATH},
+);
+
+if ($start_server) {
+ my $port = Test::TCP::empty_port();
+ my $server_pid = fork();
+ die "fork failed:$!"
+ unless defined $server_pid;
+ if ($server_pid == 0) {
+ # child == server
+ exec(
+ $start_server,
+ "--port=$port",
+ qw(-- plackup -s Standalone::Prefork::Server::Starter t/00base-hello.psgi),
+ );
+ die "failed to launch server using start_server:$!";
+ }
+ sleep 1;
+
+ is(LWP::Simple::get("http://127.0.0.1:$port/"), 'hello');
+
+ kill 'TERM', $server_pid;
+ while (wait == -1) {}
+} else {
+ warn "could not find `start_server' next to $^X nor from \$PATH, skipping tests";
}
-sleep 1;
-
-is(LWP::Simple::get("http://127.0.0.1:$port/"), 'hello');
-
-kill 'TERM', $server_pid;
-
-while (wait == -1) {}
+done_testing;

0 comments on commit 1a1209f

Please sign in to comment.