Pass along stock type info to trials.mas to hide analysis usage table in non-accessio...
[sgn.git] / t / t_server.pl
blobdd2908a4c8091e70c64bcf1f8ee4d96469df2143
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 my $verbose = 0;
16 GetOptions(
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 ) {
32 # web server process
34 $ENV{SGN_TEST_MODE} = 1;
35 @ARGV = (
36 -p => 3003,
37 ( $parallel ? ('--fork') : () ),
40 if (!$verbose) {
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');
47 exit;
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";
64 my $prove_pid = fork;
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';
71 if( $parallel ) {
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;
78 $app->process_args(
79 '-lr',
80 ( map { -I => $_ } @INC ),
81 @prove_args
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;
96 __END__
98 =head1 NAME
100 test_all.pl - start a dev server and run tests against it
102 =head1 SYNOPSIS
104 t/test_all.pl --carpalways -- -v -j5 t/mytest.t t/mydiroftests/
106 =head1 OPTIONS
108 --carpalways Load Carp::Always in both the server and the test process
109 to force backtraces of all warnings and errors
111 =cut