4 use Test::More tests => 1;
9 use Net::EmptyPort qw(wait_port empty_port);
13 eval { require Catalyst::Devel; Catalyst::Devel->VERSION(1.0); 1; } || do {
14 fail("Could not load Catalyst::Devel: $@");
18 eval { require File::Copy::Recursive; 1 } || do {
19 fail("Could not load File::Copy::Recursive: $@");
23 # Run a single test by providing it as the first arg
24 my $single_test = shift;
26 my $tmpdir = "$FindBin::Bin/../../t/tmp";
29 rmtree $tmpdir if -d $tmpdir;
31 # create a TestApp and copy the test libs into it
34 system( $^X, "-I$FindBin::Bin/../../lib", "$FindBin::Bin/../../script/catalyst.pl", 'TestApp' );
35 chdir "$FindBin::Bin/..";
36 File::Copy::Recursive::dircopy( '../t/lib', '../t/tmp/TestApp/lib' ) or die;
38 # remove TestApp's tests
39 rmtree '../t/tmp/TestApp/t' or die;
41 # spawn the standalone HTTP server
42 my $port = empty_port;
47 print "Waiting for server to start...\n";
48 wait_port_timeout($port, 30);
51 unshift @INC, "$tmpdir/TestApp/lib", "$FindBin::Bin/../../lib";
54 my $psgi_app = TestApp->apply_default_middlewares(TestApp->psgi_app);
55 Plack::Loader->auto(port => $port)->run(builder {
56 mount '/test_prefix' => $psgi_app;
58 return [501, ['Content-Type' => 'text/plain'], ['broken tests']];
64 die "fork failed: $!";
67 # run the testsuite against the HTTP server
68 $ENV{CATALYST_SERVER} = "http://localhost:$port/test_prefix";
74 $return = system( "$^X -Ilib/ $single_test" );
77 $return = prove(grep { $_ ne '..' } glob('t/aggregate/live_*.t'));
84 rmtree "$FindBin::Bin/../../t/tmp" if -d "$FindBin::Bin/../../t/tmp";
86 is( $return, 0, 'live tests' );
88 # kill 'INT' doesn't exist in Windows, so to prevent child hanging,
89 # this process will need to commit seppuku to clean up the children.
90 if ($^O eq 'MSWin32') {
91 # Furthermore, it needs to do it 'politely' so that TAP doesn't
92 # smell anything 'dubious'.
93 require Win32::Process; # core in all versions of Win32 Perl
94 Win32::Process::KillProcess($$, $return);
97 sub wait_port_timeout {
98 my ($port, $timeout) = @_;
100 wait_port($port, $timeout * 10) and return;
102 die "Server did not start within $timeout seconds";
107 if (!(my $pid = fork)) {
108 require TAP::Harness;
110 my $aggr = -e '.aggregating';
111 my $harness = TAP::Harness->new({
112 ($aggr ? (test_args => \@tests) : ()),
116 my $aggregator = $aggr
117 ? $harness->runtests('t/aggregate.t')
118 : $harness->runtests(@tests);
120 exit $aggregator->has_errors ? 1 : 0;