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 # kill 'INT' doesn't exist in Windows, so to prevent child hanging,
81 # this process will need to commit seppuku to clean up the children.
82 if ($^O eq 'MSWin32') {
83 # Furthermore, it needs to do it 'politely' so that TAP doesn't
84 # smell anything 'dubious'.
85 require Win32::Process; # core in all versions of Win32 Perl
86 Win32::Process::KillProcess($$, $return);
89 sub wait_port_timeout {
90 my ($port, $timeout) = @_;
92 # wait_port waits for 10 seconds
93 for (1 .. int($timeout / 10)) { # meh, good enough.
94 try { wait_port $port; 1 } and return;
97 die "Server did not start within $timeout seconds";
102 if (!(my $pid = fork)) {
103 require TAP::Harness;
105 my $aggr = -e '.aggregating';
106 my $harness = TAP::Harness->new({
107 ($aggr ? (test_args => \@tests) : ()),
111 my $aggregator = $aggr
112 ? $harness->runtests('t/aggregate.t')
113 : $harness->runtests(@tests);
115 exit $aggregator->has_errors ? 1 : 0;