10 use Catalyst::Script::Server;
14 # Test default (no opts/args behaviour)
15 # Note undef for host means we bind to all interfaces.
16 testOption( [ qw// ], ['3000', undef, opthash()] );
18 # Old version supports long format opts with either one or two dashes. New version only supports two.
20 # help -? -help --help -? --help
21 # debug -d -debug --debug -d --debug
22 # host -host --host --host
23 testOption( [ qw/--host testhost/ ], ['3000', 'testhost', opthash()] );
24 testOption( [ qw/-h testhost/ ], ['3000', 'testhost', opthash()] );
26 # port -p -port --port -l --listen
27 testOption( [ qw/-p 3001/ ], ['3001', undef, opthash()] );
28 testOption( [ qw/--port 3001/ ], ['3001', undef, opthash()] );
30 local $ENV{TESTAPPTOTESTSCRIPTS_PORT} = 5000;
31 testOption( [ qw// ], [5000, undef, opthash()] );
34 # fork -f -fork --fork -f --fork
35 testOption( [ qw/--fork/ ], ['3000', undef, opthash(fork => 1)] );
36 testOption( [ qw/-f/ ], ['3000', undef, opthash(fork => 1)] );
38 # pidfile -pidfile --pid --pidfile
39 testOption( [ qw/--pidfile cat.pid/ ], ['3000', undef, opthash(pidfile => "cat.pid")] );
40 testOption( [ qw/--pid cat.pid/ ], ['3000', undef, opthash(pidfile => "cat.pid")] );
42 # keepalive -k -keepalive --keepalive -k --keepalive
43 testOption( [ qw/-k/ ], ['3000', undef, opthash(keepalive => 1)] );
44 testOption( [ qw/--keepalive/ ], ['3000', undef, opthash(keepalive => 1)] );
46 # symlinks -follow_symlinks --sym --follow_symlinks
47 testOption( [ qw/--follow_symlinks/ ], ['3000', undef, opthash(follow_symlinks => 1)] );
48 testOption( [ qw/--sym/ ], ['3000', undef, opthash(follow_symlinks => 1)] );
50 # background -background --bg --background
51 testOption( [ qw/--background/ ], ['3000', undef, opthash(background => 1)] );
52 testOption( [ qw/--bg/ ], ['3000', undef, opthash(background => 1)] );
54 # restart -r -restart --restart -R --restart
55 testRestart( ['-r'], restartopthash() );
56 # restart dly -rd -restartdelay --rd --restart_delay
57 testRestart( ['-r', '--rd', 30], restartopthash(sleep_interval => 30) );
58 testRestart( ['-r', '--restart_delay', 30], restartopthash(sleep_interval => 30) );
60 # restart dir -restartdirectory --rdir --restart_directory
61 testRestart( ['-r', '--rdir', 'root'], restartopthash(directories => ['root']) );
62 testRestart( ['-r', '--rdir', 'root', '--rdir', 'lib'], restartopthash(directories => ['root', 'lib']) );
63 testRestart( ['-r', '--restart_directory', 'root'], restartopthash(directories => ['root']) );
65 # restart regex -rr -restartregex --rr --restart_regex
66 testRestart( ['-r', '--rr', 'foo'], restartopthash(filter => qr/foo/) );
67 testRestart( ['-r', '--restart_regex', 'foo'], restartopthash(filter => qr/foo/) );
72 my ($argstring, $resultarray) = @_;
73 my $app = _build_testapp($argstring);
77 # First element of RUN_ARGS will be the script name, which we don't care about
78 shift @TestAppToTestScripts::RUN_ARGS;
79 is_deeply \@TestAppToTestScripts::RUN_ARGS, $resultarray, "is_deeply comparison " . join(' ', @$argstring);
83 my ($argstring, $resultarray) = @_;
84 my $app = _build_testapp($argstring);
85 my $args = {$app->_restarter_args};
86 is_deeply delete $args->{argv}, $argstring, 'argv is arg string';
87 is ref(delete $args->{start_sub}), 'CODE', 'Closure to start app present';
88 is_deeply $args, $resultarray, "is_deeply comparison of restarter args " . join(' ', @$argstring);
92 my ($argstring, $resultarray) = @_;
94 local @ARGV = @$argstring;
95 local @TestAppToTestScripts::RUN_ARGS;
98 $i = Catalyst::Script::Server->new_with_options(application_name => 'TestAppToTestScripts');
99 } "new_with_options " . join(' ', @$argstring);;
104 # Returns the hash expected when no flags are passed
109 'follow_symlinks' => 0,
118 follow_symlinks => 0,