From: Tomas Doran Date: Thu, 26 Nov 2009 21:02:57 +0000 (+0000) Subject: Fix typo, bricas++, add simple test for restarter arguments X-Git-Tag: 5.80014_02~24 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=2c298960a7602044a287c444e3f421d628202b76 Fix typo, bricas++, add simple test for restarter arguments --- diff --git a/lib/Catalyst/ScriptRole.pm b/lib/Catalyst/ScriptRole.pm index 089f2df..1cd745f 100644 --- a/lib/Catalyst/ScriptRole.pm +++ b/lib/Catalyst/ScriptRole.pm @@ -74,7 +74,7 @@ Catalyst::ScriptRole - Common functionality for Catalyst scripts. use Moose; use namespace::autoclean; - with 'Catalyst::Script::Role'; + with 'Catalyst::ScriptRole'; sub _application_args { ... } diff --git a/t/aggregate/unit_core_script_server.t b/t/aggregate/unit_core_script_server.t index e129f19..035be38 100644 --- a/t/aggregate/unit_core_script_server.t +++ b/t/aggregate/unit_core_script_server.t @@ -46,25 +46,54 @@ testOption( [ qw/--sym/ ], ['3000', 'localhost', opthash(follow_symlinks => 1)] testOption( [ qw/--background/ ], ['3000', 'localhost', opthash(background => 1)] ); testOption( [ qw/--bg/ ], ['3000', 'localhost', opthash(background => 1)] ); -# Restart stuff requires a threaded perl, apparently. # restart -r -restart --restart -R --restart -# restart dly -rd -restartdelay --rdel --restart_delay +testRestart( ['-r'], restartopthash() ); +# restart dly -rd -restartdelay --rd --restart_delay +testRestart( ['-r', '--rd', 30], restartopthash(sleep_interval => 30) ); +testRestart( ['-r', '--restart_delay', 30], restartopthash(sleep_interval => 30) ); + # restart dir -restartdirectory --rdir --restart_directory -# restart regex -rr -restartregex --rxp --restart_regex +testRestart( ['-r', '--rdir', 'root'], restartopthash(directories => ['root']) ); +testRestart( ['-r', '--rdir', 'root', '--rdir', 'lib'], restartopthash(directories => ['root', 'lib']) ); +testRestart( ['-r', '--restart_directory', 'root'], restartopthash(directories => ['root']) ); + +# restart regex -rr -restartregex --rr --restart_regex +testRestart( ['-r', '--rr', 'foo'], restartopthash(filter => qr/foo/) ); +testRestart( ['-r', '--restart_regex', 'foo'], restartopthash(filter => qr/foo/) ); done_testing; sub testOption { my ($argstring, $resultarray) = @_; + my $app = _build_testapp($argstring); + lives_ok { + $app->run; + }; + # 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 " . join(' ', @$argstring); +} + +sub testRestart { + my ($argstring, $resultarray) = @_; + my $app = _build_testapp($argstring); + my $args = {$app->_restarter_args}; + is_deeply delete $args->{argv}, $argstring, 'argv is arg string'; + is ref(delete $args->{start_sub}), 'CODE', 'Closure to start app present'; + is_deeply $args, $resultarray, "is_deeply comparison of restarter args " . join(' ', @$argstring); +} + +sub _build_testapp { + my ($argstring, $resultarray) = @_; local @ARGV = @$argstring; local @TestAppToTestScripts::RUN_ARGS; + my $i; 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"; + $i = Catalyst::Script::Server->new_with_options(application_name => 'TestAppToTestScripts'); + } "new_with_options " . join(' ', @$argstring);; + ok $i; + return $i; } # Returns the hash expected when no flags are passed @@ -78,3 +107,9 @@ sub opthash { @_, }; } + +sub restartopthash { + return { + @_, + }; +}