10 use Catalyst::Script::FastCGI;
12 local our $fake_handler = \42;
15 package TestFastCGIScript;
17 use namespace::autoclean;
19 extends 'Catalyst::Script::FastCGI';
21 # Avoid loading the real plack engine, as that will load FCGI and fail if
22 # it's not there. We don't really need a full engine anyway as the overriden
23 # MyApp->run will just capture its arguments and return without delegating
24 # to the engine to run things.
25 override load_engine => sub { $fake_handler };
27 __PACKAGE__->meta->make_immutable;
31 my ($argstring, $resultarray) = @_;
33 local @ARGV = @$argstring;
34 local @TestAppToTestScripts::RUN_ARGS;
36 TestFastCGIScript->new_with_options(application_name => 'TestAppToTestScripts')->run;
37 }, undef, "new_with_options";
38 # First element of RUN_ARGS will be the script name, which we don't care about
39 shift @TestAppToTestScripts::RUN_ARGS;
41 my $server = pop @TestAppToTestScripts::RUN_ARGS;
42 is $server, $fake_handler, 'Loaded Plack handler gets passed to the app';
44 if (scalar(@TestAppToTestScripts::RUN_ARGS) && ref($TestAppToTestScripts::RUN_ARGS[-1]) eq "HASH") {
45 is ref(delete($TestAppToTestScripts::RUN_ARGS[-1]->{argv})), 'ARRAY';
46 is ref(delete($TestAppToTestScripts::RUN_ARGS[-1]->{extra_argv})), 'ARRAY';
49 is_deeply \@TestAppToTestScripts::RUN_ARGS, $resultarray, "is_deeply comparison";
52 # Returns the hash expected when no flags are passed
55 (map { ($_ => undef) } qw(pidfile keep_stderr detach nproc manager)),
56 proc_title => 'perl-fcgi-pm [TestAppToTestScripts]',
62 # Test default (no opts/args behaviour)
63 testOption( [ qw// ], [undef, opthash()] );
66 testOption( [ qw|-l /tmp/foo| ], ['/tmp/foo', opthash()] );
67 testOption( [ qw/-l 127.0.0.1:3000/ ], ['127.0.0.1:3000', opthash()] );
69 #daemonize -d --daemon
70 testOption( [ qw/-d/ ], [undef, opthash(detach => 1)] );
71 testOption( [ qw/--daemon/ ], [undef, opthash(detach => 1)] );
73 # pidfile -pidfile -p --pid --pidfile
74 testOption( [ qw/--pidfile cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
75 testOption( [ qw/--pid cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
76 testOption( [ qw/-p cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
79 testOption( [ qw/--manager foo::bar/ ], [undef, opthash(manager => 'foo::bar')] );
80 testOption( [ qw/-M foo::bar/ ], [undef, opthash(manager => 'foo::bar')] );
83 testOption( [ qw/--keeperr/ ], [undef, opthash(keep_stderr => 1)] );
84 testOption( [ qw/-e/ ], [undef, opthash(keep_stderr => 1)] );
87 testOption( [ qw/--nproc 6/ ], [undef, opthash(nproc => 6)] );
88 testOption( [ qw/--n 6/ ], [undef, opthash(nproc => 6)] );
91 testOption( [ qw/--proc_title foo/ ], [undef, opthash(proc_title => 'foo')] );