X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Funit_core_script_server.t;h=d93cebb7e95672cd7291d77d9337e8d4b7da95f7;hb=f3bf297698a51092213b2339aa1d1271cda0a28c;hp=dc46372f9f0ad4f84a48513f37dd52a59ed7a02c;hpb=60b86a55d91b58f9dc0771358034281096ccd418;p=catagits%2FCatalyst-Runtime.git diff --git a/t/unit_core_script_server.t b/t/unit_core_script_server.t index dc46372..d93cebb 100644 --- a/t/unit_core_script_server.t +++ b/t/unit_core_script_server.t @@ -9,38 +9,81 @@ use Test::Exception; use Catalyst::Script::Server; -{ - local @ARGV; # Blank - local @TestAppToTestScripts::RUN_ARGS; - lives_ok { - Catalyst::Script::Server->new_with_options(application_name => 'TestAppToTestScripts')->run; - }; - is_deeply \@TestAppToTestScripts::RUN_ARGS, ['TestAppToTestScripts', - '3000', - 'localhost', - { - 'pidfile' => undef, - 'fork' => undef, - 'follow_symlinks' => undef, - 'background' => undef, - 'keepalive' => undef - }]; +my $testopts; + +# Test default (no opts/args behaviour) +testOption( [ qw// ], ['3000', 'localhost', opthash()] ); + +# Old version supports long format opts with either one or two dashes. New version only supports two. +# Old New +# help -? -help --help -h --help +# debug -d -debug --debug -d --debug +# host -host --host --host +testOption( [ qw/--host testhost/ ], ['3000', 'testhost', opthash()] ); +testOption( [ qw/-h testhost/ ], ['3000', 'testhost', opthash()] ); + +# port -p -port --port -l --listen +testOption( [ qw/-p 3001/ ], ['3001', 'localhost', opthash()] ); +testOption( [ qw/--port 3001/ ], ['3001', 'localhost', opthash()] ); + +# fork -f -fork --fork -f --fork +$testopts = opthash(); +$testopts->{fork} = 1; +testOption( [ qw/--fork/ ], ['3000', 'localhost', $testopts] ); +testOption( [ qw/-f/ ], ['3000', 'localhost', $testopts] ); + +# pidfile -pidfile --pid --pidfile +$testopts = opthash(); +$testopts->{pidfile} = "cat.pid"; +testOption( [ qw/--pidfile cat.pid/ ], ['3000', 'localhost', $testopts] ); + +# keepalive -k -keepalive --keepalive -k --keepalive +$testopts = opthash(); +$testopts->{keepalive} = 1; +testOption( [ qw/-k/ ], ['3000', 'localhost', $testopts] ); +testOption( [ qw/--keepalive/ ], ['3000', 'localhost', $testopts] ); + +# symlinks -follow_symlinks --sym --follow_symlinks +$testopts = opthash(); +$testopts->{follow_symlinks} = 1; +testOption( [ qw/--follow_symlinks/ ], ['3000', 'localhost', $testopts] ); + +# background -background --bg --background +$testopts = opthash(); +$testopts->{background} = 1; +testOption( [ qw/--background/ ], ['3000', 'localhost', $testopts] ); + +# Restart stuff requires a threaded perl, apparently. +# restart -r -restart --restart -R --restart +# restart dly -rd -restartdelay --rdel --restart_delay +# restart dir -restartdirectory --rdir --restart_directory +# restart regex -rr -restartregex --rxp --restart_regex + + +sub testOption { + my ($argstring, $resultarray) = @_; + + subtest "Test for ARGV: @$argstring" => sub + { + plan tests => 2; + local @ARGV = @$argstring; + local @TestAppToTestScripts::RUN_ARGS; + lives_ok { + Catalyst::Script::Server->new_with_options(application_name => 'TestAppToTestScripts')->run; + } "new_with_options"; + # First element of RUN_ARGS will be the script name, which we don't care about + shift @TestAppToTestScripts::RUN_ARGS; + is_deeply \@TestAppToTestScripts::RUN_ARGS, $resultarray, "is_deeply comparison"; + done_testing; + }; } -{ - local @ARGV = qw/-p 3001/; - local @TestAppToTestScripts::RUN_ARGS; - lives_ok { - Catalyst::Script::Server->new_with_options(application_name => 'TestAppToTestScripts')->run; - }; - is_deeply \@TestAppToTestScripts::RUN_ARGS, ['TestAppToTestScripts', - '3001', - 'localhost', - { - 'pidfile' => undef, - 'fork' => undef, - 'follow_symlinks' => undef, - 'background' => undef, - 'keepalive' => undef - }]; +# Returns the hash expected when no flags are passed +sub opthash { + return { 'pidfile' => undef, + 'fork' => undef, + 'follow_symlinks' => undef, + 'background' => undef, + 'keepalive' => undef, + } }