4 use Test::More tests => 1;
11 use Catalyst::Devel 1.0;
12 use File::Copy::Recursive;
14 # Run a single test by providing it as the first arg
15 my $single_test = shift;
17 my $tmpdir = "$FindBin::Bin/../../t/tmp";
20 rmtree $tmpdir if -d $tmpdir;
22 # create a TestApp and copy the test libs into it
25 system( $^X, "-I$FindBin::Bin/../../lib", "$FindBin::Bin/../../script/catalyst.pl", 'TestApp' );
26 chdir "$FindBin::Bin/..";
27 File::Copy::Recursive::dircopy( '../t/lib', '../t/tmp/TestApp/lib' ) or die;
29 # remove TestApp's tests
30 rmtree '../t/tmp/TestApp/t' or die;
32 # spawn the standalone HTTP server
33 my $port = empty_port;
38 print "Waiting for server to start...\n";
39 wait_port_timeout($port, 30);
42 unshift @INC, "$tmpdir/TestApp/lib", "$FindBin::Bin/../../lib";
45 my $psgi_app = TestApp->_wrapped_legacy_psgi_app(TestApp->psgi_app);
46 Plack::Loader->auto(port => $port)->run($psgi_app);
50 die "fork failed: $!";
53 # run the testsuite against the HTTP server
54 $ENV{CATALYST_SERVER} = "http://localhost:$port";
60 $return = system( "$^X -Ilib/ $single_test" );
63 $return = prove(grep { $_ ne '..' } glob('t/aggregate/live_*.t'));
70 rmtree "$FindBin::Bin/../../t/tmp" if -d "$FindBin::Bin/../../t/tmp";
72 is( $return, 0, 'live tests' );
74 sub wait_port_timeout {
75 my ($port, $timeout) = @_;
77 # wait_port waits for 10 seconds
78 for (1 .. int($timeout / 10)) { # meh, good enough.
79 try { wait_port $port; 1 } and return;
82 die "Server did not start within $timeout seconds";
87 if (!(my $pid = fork)) {
90 my $aggr = -e '.aggregating';
91 my $harness = TAP::Harness->new({
92 ($aggr ? (test_args => \@tests) : ()),
96 my $aggregator = $aggr
97 ? $harness->runtests('t/aggregate.t')
98 : $harness->runtests(@tests);
100 exit $aggregator->has_errors ? 1 : 0;