10 use Catalyst
::ScriptRunner
;
13 use SGN
::Devel
::MyDevLibs
;
17 "carpalways" => \
( my $carpalways = 0 ),
18 "verbose" => \
$verbose ,
21 require Carp
::Always
if $carpalways;
23 my @prove_args = @ARGV;
24 @prove_args = ( 't' ) unless @prove_args;
26 my $parallel = (grep /^-j\d*$/, @ARGV) ?
1 : 0;
28 $ENV{SGN_CONFIG_LOCAL_SUFFIX
} = 'testing';
30 my $server_pid = fork;
31 unless( $server_pid ) {
34 $ENV{SGN_TEST_MODE
} = 1;
37 ( $parallel ?
('--fork') : () ),
41 my $logfile = "logfile.$$.txt";
42 print STDERR
"Redirecting server STDERR to file $logfile..\n";
43 open (STDERR
, ">$logfile") || die "can't open logfile.";
45 Catalyst
::ScriptRunner
->run('SGN', 'Server');
49 print STDERR
"$0: starting web server with PID $server_pid... ";
53 # wait for the test server to start
56 local $SIG{CHLD
} = sub {
57 waitpid $server_pid, 0;
58 die "\nTest server failed to start. Aborting.\n";
60 sleep 1 until !kill(0, $server_pid) || get
'http://localhost:3003';
61 print STDERR
"Done.\n";
65 unless( $prove_pid ) {
66 # test harness process
69 # set up env vars for prove and the tests
70 $ENV{SGN_TEST_SERVER
} = 'http://localhost:3003';
72 $ENV{SGN_PARALLEL_TESTING
} = 1;
73 $ENV{SGN_SKIP_LEAK_TEST
} = 1;
76 # now run the tests against it
77 my $app = App
::Prove
->new;
80 ( map { -I
=> $_ } @INC ),
83 exit( $app->run ?
0 : 1 );
86 $SIG{CHLD
} = 'IGNORE';
87 $SIG{INT
} = sub { kill 15, $server_pid, $prove_pid };
88 $SIG{KILL
} = sub { kill 9, $server_pid, $prove_pid };
90 warn "$0: prove started with PID $prove_pid.\n";
91 waitpid $prove_pid, 0;
92 warn "$0: prove finished, stopping web server PID $server_pid.\n";
93 END { kill 15, $server_pid if $server_pid }
94 waitpid $server_pid, 0;
100 test_all.pl - start a dev server and run tests against it
104 t/test_all.pl --carpalways -- -v -j5 t/mytest.t t/mydiroftests/
108 --carpalways Load Carp::Always in both the server and the test process
109 to force backtraces of all warnings and errors