[Catalyst-commits] r12034 - in Catalyst-Runtime/5.80/branches/better_scripts: lib/Catalyst t/aggregate

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Thu Nov 26 21:02:58 GMT 2009


Author: t0m
Date: 2009-11-26 21:02:57 +0000 (Thu, 26 Nov 2009)
New Revision: 12034

Modified:
   Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/ScriptRole.pm
   Catalyst-Runtime/5.80/branches/better_scripts/t/aggregate/unit_core_script_server.t
Log:
Fix typo, bricas++, add simple test for restarter arguments

Modified: Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/ScriptRole.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/ScriptRole.pm	2009-11-26 20:56:01 UTC (rev 12033)
+++ Catalyst-Runtime/5.80/branches/better_scripts/lib/Catalyst/ScriptRole.pm	2009-11-26 21:02:57 UTC (rev 12034)
@@ -74,7 +74,7 @@
     use Moose;
     use namespace::autoclean;
 
-    with 'Catalyst::Script::Role';
+    with 'Catalyst::ScriptRole';
 
      sub _application_args { ... }
 

Modified: Catalyst-Runtime/5.80/branches/better_scripts/t/aggregate/unit_core_script_server.t
===================================================================
--- Catalyst-Runtime/5.80/branches/better_scripts/t/aggregate/unit_core_script_server.t	2009-11-26 20:56:01 UTC (rev 12033)
+++ Catalyst-Runtime/5.80/branches/better_scripts/t/aggregate/unit_core_script_server.t	2009-11-26 21:02:57 UTC (rev 12034)
@@ -46,25 +46,54 @@
 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 restartopthash {
+    return {
+        @_,
+    };
+}




More information about the Catalyst-commits mailing list