10 use Ref::Util qw(is_plain_hashref);
12 use Catalyst::Script::FastCGI;
14 local our $fake_handler = \42;
17 package TestFastCGIScript;
19 use namespace::autoclean;
21 extends 'Catalyst::Script::FastCGI';
23 # Avoid loading the real plack engine, as that will load FCGI and fail if
24 # it's not there. We don't really need a full engine anyway as the overriden
25 # MyApp->run will just capture its arguments and return without delegating
26 # to the engine to run things.
27 override load_engine => sub { $fake_handler };
29 __PACKAGE__->meta->make_immutable;
33 my ($argstring, $resultarray) = @_;
35 local @ARGV = @$argstring;
36 local @TestAppToTestScripts::RUN_ARGS;
38 TestFastCGIScript->new_with_options(application_name => 'TestAppToTestScripts')->run;
39 }, undef, "new_with_options";
40 # First element of RUN_ARGS will be the script name, which we don't care about
41 shift @TestAppToTestScripts::RUN_ARGS;
43 my $server = pop @TestAppToTestScripts::RUN_ARGS;
44 is $server, $fake_handler, 'Loaded Plack handler gets passed to the app';
46 if (scalar(@TestAppToTestScripts::RUN_ARGS) && is_plain_hashref($TestAppToTestScripts::RUN_ARGS[-1])) {
47 is ref(delete($TestAppToTestScripts::RUN_ARGS[-1]->{argv})), 'ARRAY';
48 is ref(delete($TestAppToTestScripts::RUN_ARGS[-1]->{extra_argv})), 'ARRAY';
51 is_deeply \@TestAppToTestScripts::RUN_ARGS, $resultarray, "is_deeply comparison";
54 # Returns the hash expected when no flags are passed
57 (map { ($_ => undef) } qw(pidfile keep_stderr detach nproc manager)),
58 proc_title => 'perl-fcgi-pm [TestAppToTestScripts]',
64 # Test default (no opts/args behaviour)
65 testOption( [ qw// ], [undef, opthash()] );
68 testOption( [ qw|-l /tmp/foo| ], ['/tmp/foo', opthash()] );
69 testOption( [ qw/-l 127.0.0.1:3000/ ], ['127.0.0.1:3000', opthash()] );
71 #daemonize -d --daemon
72 testOption( [ qw/-d/ ], [undef, opthash(detach => 1)] );
73 testOption( [ qw/--daemon/ ], [undef, opthash(detach => 1)] );
75 # pidfile -pidfile -p --pid --pidfile
76 testOption( [ qw/--pidfile cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
77 testOption( [ qw/--pid cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
78 testOption( [ qw/-p cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
81 testOption( [ qw/--manager foo::bar/ ], [undef, opthash(manager => 'foo::bar')] );
82 testOption( [ qw/-M foo::bar/ ], [undef, opthash(manager => 'foo::bar')] );
85 testOption( [ qw/--keeperr/ ], [undef, opthash(keep_stderr => 1)] );
86 testOption( [ qw/-e/ ], [undef, opthash(keep_stderr => 1)] );
89 testOption( [ qw/--nproc 6/ ], [undef, opthash(nproc => 6)] );
90 testOption( [ qw/--n 6/ ], [undef, opthash(nproc => 6)] );
93 testOption( [ qw/--proc_title foo/ ], [undef, opthash(proc_title => 'foo')] );