4 use Test::More tests => 1;
12 use Catalyst::Devel 1.0;
13 use File::Copy::Recursive;
15 # Run a single test by providing it as the first arg
16 my $single_test = shift;
18 my $tmpdir = "$FindBin::Bin/../../t/tmp";
21 rmtree $tmpdir if -d $tmpdir;
23 # create a TestApp and copy the test libs into it
26 system( $^X, "-I$FindBin::Bin/../../lib", "$FindBin::Bin/../../script/catalyst.pl", 'TestApp' );
27 chdir "$FindBin::Bin/..";
28 File::Copy::Recursive::dircopy( '../t/lib', '../t/tmp/TestApp/lib' ) or die;
30 # remove TestApp's tests
31 rmtree '../t/tmp/TestApp/t' or die;
33 # spawn the standalone HTTP server
34 my $port = empty_port;
39 print "Waiting for server to start...\n";
40 wait_port_timeout($port, 30);
43 unshift @INC, "$tmpdir/TestApp/lib", "$FindBin::Bin/../../lib";
46 my $psgi_app = TestApp->apply_default_middlewares(TestApp->psgi_app);
47 Plack::Loader->auto(port => $port)->run(builder {
48 mount '/test_prefix' => $psgi_app;
50 return [501, ['Content-Type' => 'text/plain'], ['broken tests']];
56 die "fork failed: $!";
59 # run the testsuite against the HTTP server
60 $ENV{CATALYST_SERVER} = "http://localhost:$port/test_prefix";
66 $return = system( "$^X -Ilib/ $single_test" );
69 $return = prove(grep { $_ ne '..' } glob('t/aggregate/live_*.t'));
76 rmtree "$FindBin::Bin/../../t/tmp" if -d "$FindBin::Bin/../../t/tmp";
78 is( $return, 0, 'live tests' );
80 sub wait_port_timeout {
81 my ($port, $timeout) = @_;
83 # wait_port waits for 10 seconds
84 for (1 .. int($timeout / 10)) { # meh, good enough.
85 try { wait_port $port; 1 } and return;
88 die "Server did not start within $timeout seconds";
93 if (!(my $pid = fork)) {
96 my $aggr = -e '.aggregating';
97 my $harness = TAP::Harness->new({
98 ($aggr ? (test_args => \@tests) : ()),
102 my $aggregator = $aggr
103 ? $harness->runtests('t/aggregate.t')
104 : $harness->runtests(@tests);
106 exit $aggregator->has_errors ? 1 : 0;