4 use Test::More tests => 1;
9 use Net::EmptyPort qw(wait_port empty_port);
15 # Run a single test by providing it as the first arg
16 my $single_test = shift;
18 my $test_app_dir = make_test_app;
20 # spawn the standalone HTTP server
21 my $port = empty_port;
26 print "Waiting for server to start...\n";
27 wait_port_timeout($port, 30);
30 unshift @INC, "$test_app_dir/lib", "$FindBin::Bin/../../lib";
33 my $psgi_app = TestApp->apply_default_middlewares(TestApp->psgi_app);
34 Plack::Loader->auto(port => $port)->run(builder {
35 mount '/test_prefix' => $psgi_app;
37 return [501, ['Content-Type' => 'text/plain'], ['broken tests']];
43 die "fork failed: $!";
46 # run the testsuite against the HTTP server
47 $ENV{CATALYST_SERVER} = "http://localhost:$port/test_prefix";
53 $return = system( "$^X -Ilib/ $single_test" );
56 $return = prove(grep { $_ ne '..' } glob('t/aggregate/live_*.t'));
63 rmtree "$FindBin::Bin/../../t/tmp" if -d "$FindBin::Bin/../../t/tmp";
65 is( $return, 0, 'live tests' );
67 # kill 'INT' doesn't exist in Windows, so to prevent child hanging,
68 # this process will need to commit seppuku to clean up the children.
69 if ($^O eq 'MSWin32') {
70 # Furthermore, it needs to do it 'politely' so that TAP doesn't
71 # smell anything 'dubious'.
72 require Win32::Process; # core in all versions of Win32 Perl
73 Win32::Process::KillProcess($$, $return);
76 sub wait_port_timeout {
77 my ($port, $timeout) = @_;
79 wait_port($port, $timeout * 10) and return;
81 die "Server did not start within $timeout seconds";
86 if (!(my $pid = fork)) {
89 my $harness = TAP::Harness->new({
93 my $aggregator = $harness->runtests(@tests);
95 exit $aggregator->has_errors ? 1 : 0;