remove unused variable $base_url.
[sgn.git] / t / t_server.pl
blob960fd4a5a5e81d519a4b1adfa78a41f7e5fd50bf
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use LWP::Simple;
5 use App::Prove;
7 use Pod::Usage;
8 use Getopt::Long;
10 use Catalyst::ScriptRunner;
12 use lib 'lib';
13 use SGN::Devel::MyDevLibs;
15 GetOptions(
16 "carpalways" => \( my $carpalways = 0 ),
19 require Carp::Always if $carpalways;
21 my @prove_args = @ARGV;
22 @prove_args = ( 't' ) unless @prove_args;
24 my $parallel = (grep /^-j\d*$/, @ARGV) ? 1 : 0;
26 $ENV{SGN_CONFIG_LOCAL_SUFFIX} = 'testing';
28 my $server_pid = fork;
29 unless( $server_pid ) {
30 # web server process
32 $ENV{SGN_TEST_MODE} = 1;
33 @ARGV = (
34 -p => 3003,
35 ( $parallel ? ('--fork') : () ),
37 Catalyst::ScriptRunner->run('SGN', 'Server');
38 exit;
40 warn "$0: starting web server with PID $server_pid.\n";
42 # wait for the test server to start
44 local $SIG{CHLD} = sub {
45 waitpid $server_pid, 0;
46 die "\nTest server failed to start. Aborting.\n";
48 sleep 1 until !kill(0, $server_pid) || get 'http://localhost:3003';
51 my $prove_pid = fork;
52 unless( $prove_pid ) {
53 # test harness process
56 # set up env vars for prove and the tests
57 $ENV{SGN_TEST_SERVER} = 'http://localhost:3003';
58 if( $parallel ) {
59 $ENV{SGN_PARALLEL_TESTING} = 1;
60 $ENV{SGN_SKIP_LEAK_TEST} = 1;
63 # now run the tests against it
64 my $app = App::Prove->new;
65 $app->process_args(
66 '-lr',
67 ( map { -I => $_ } @INC ),
68 @prove_args
70 exit( $app->run ? 0 : 1 );
73 $SIG{CHLD} = 'IGNORE';
74 $SIG{INT} = sub { kill 15, $server_pid, $prove_pid };
75 $SIG{KILL} = sub { kill 9, $server_pid, $prove_pid };
77 warn "$0: prove started with PID $prove_pid.\n";
78 waitpid $prove_pid, 0;
79 warn "$0: prove finished, stopping web server PID $server_pid.\n";
80 END { kill 15, $server_pid if $server_pid }
81 waitpid $server_pid, 0;
83 __END__
85 =head1 NAME
87 test_all.pl - start a dev server and run tests against it
89 =head1 SYNOPSIS
91 t/test_all.pl --carpalways -- -v -j5 t/mytest.t t/mydiroftests/
93 =head1 OPTIONS
95 --carpalways Load Carp::Always in both the server and the test process
96 to force backtraces of all warnings and errors
98 =cut