4 use Test::More tests => 1;
12 eval { require Catalyst::Devel; Catalyst::Devel->VERSION(1.0); 1; } || do {
13 fail("Could not load Catalyst::Devel: $@");
17 eval { require File::Copy::Recursive; 1 } || do {
18 fail("Could not load File::Copy::Recursive: $@");
22 # Run a single test by providing it as the first arg
23 my $single_test = shift;
25 my $tmpdir = "$FindBin::Bin/../../t/tmp";
28 rmtree $tmpdir if -d $tmpdir;
30 # create a TestApp and copy the test libs into it
33 system( $^X, "-I$FindBin::Bin/../../lib", "$FindBin::Bin/../../script/catalyst.pl", 'TestApp' );
34 chdir "$FindBin::Bin/..";
35 File::Copy::Recursive::dircopy( '../t/lib', '../t/tmp/TestApp/lib' ) or die;
37 # remove TestApp's tests
38 rmtree '../t/tmp/TestApp/t' or die;
40 # spawn the standalone HTTP server
41 my $port = empty_port;
46 print "Waiting for server to start...\n";
47 wait_port_timeout($port, 30);
50 unshift @INC, "$tmpdir/TestApp/lib", "$FindBin::Bin/../../lib";
53 my $psgi_app = TestApp->apply_default_middlewares(TestApp->psgi_app);
54 Plack::Loader->auto(port => $port)->run(builder {
55 mount '/test_prefix' => $psgi_app;
57 return [501, ['Content-Type' => 'text/plain'], ['broken tests']];
63 die "fork failed: $!";
66 # run the testsuite against the HTTP server
67 $ENV{CATALYST_SERVER} = "http://localhost:$port/test_prefix";
73 $return = system( "$^X -Ilib/ $single_test" );
76 $return = prove(grep { $_ ne '..' } glob('t/aggregate/live_*.t'));
83 rmtree "$FindBin::Bin/../../t/tmp" if -d "$FindBin::Bin/../../t/tmp";
85 is( $return, 0, 'live tests' );
87 # kill 'INT' doesn't exist in Windows, so to prevent child hanging,
88 # this process will need to commit seppuku to clean up the children.
89 if ($^O eq 'MSWin32') {
90 # Furthermore, it needs to do it 'politely' so that TAP doesn't
91 # smell anything 'dubious'.
92 require Win32::Process; # core in all versions of Win32 Perl
93 Win32::Process::KillProcess($$, $return);
96 sub wait_port_timeout {
97 my ($port, $timeout) = @_;
99 # wait_port waits for 10 seconds
100 for (1 .. int($timeout / 10)) { # meh, good enough.
101 try { wait_port $port; 1 } and return;
104 die "Server did not start within $timeout seconds";
109 if (!(my $pid = fork)) {
110 require TAP::Harness;
112 my $aggr = -e '.aggregating';
113 my $harness = TAP::Harness->new({
114 ($aggr ? (test_args => \@tests) : ()),
118 my $aggregator = $aggr
119 ? $harness->runtests('t/aggregate.t')
120 : $harness->runtests(@tests);
122 exit $aggregator->has_errors ? 1 : 0;