Doc --host change
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_script_server.t
CommitLineData
60b86a55 1use strict;
2use warnings;
3
4use FindBin qw/$Bin/;
04f4497c 5use lib "$Bin/../lib";
60b86a55 6
6ec45f37 7use Test::More;
60b86a55 8use Test::Exception;
9
10use Catalyst::Script::Server;
11
f3bf2976 12my $testopts;
13
14# Test default (no opts/args behaviour)
15testOption( [ qw// ], ['3000', 'localhost', opthash()] );
16
17# Old version supports long format opts with either one or two dashes. New version only supports two.
18# Old New
fb533ac3 19# help -? -help --help -? --help
f3bf2976 20# debug -d -debug --debug -d --debug
21# host -host --host --host
22testOption( [ qw/--host testhost/ ], ['3000', 'testhost', opthash()] );
23testOption( [ qw/-h testhost/ ], ['3000', 'testhost', opthash()] );
24
25# port -p -port --port -l --listen
26testOption( [ qw/-p 3001/ ], ['3001', 'localhost', opthash()] );
27testOption( [ qw/--port 3001/ ], ['3001', 'localhost', opthash()] );
28
29# fork -f -fork --fork -f --fork
960bf5b0 30testOption( [ qw/--fork/ ], ['3000', 'localhost', opthash(fork => 1)] );
31testOption( [ qw/-f/ ], ['3000', 'localhost', opthash(fork => 1)] );
f3bf2976 32
33# pidfile -pidfile --pid --pidfile
960bf5b0 34testOption( [ qw/--pidfile cat.pid/ ], ['3000', 'localhost', opthash(pidfile => "cat.pid")] );
35testOption( [ qw/--pid cat.pid/ ], ['3000', 'localhost', opthash(pidfile => "cat.pid")] );
f3bf2976 36
37# keepalive -k -keepalive --keepalive -k --keepalive
960bf5b0 38testOption( [ qw/-k/ ], ['3000', 'localhost', opthash(keepalive => 1)] );
39testOption( [ qw/--keepalive/ ], ['3000', 'localhost', opthash(keepalive => 1)] );
f3bf2976 40
41# symlinks -follow_symlinks --sym --follow_symlinks
960bf5b0 42testOption( [ qw/--follow_symlinks/ ], ['3000', 'localhost', opthash(follow_symlinks => 1)] );
43testOption( [ qw/--sym/ ], ['3000', 'localhost', opthash(follow_symlinks => 1)] );
f3bf2976 44
45# background -background --bg --background
960bf5b0 46testOption( [ qw/--background/ ], ['3000', 'localhost', opthash(background => 1)] );
47testOption( [ qw/--bg/ ], ['3000', 'localhost', opthash(background => 1)] );
53c6ec79 48
f3bf2976 49# restart -r -restart --restart -R --restart
2c298960 50testRestart( ['-r'], restartopthash() );
51# restart dly -rd -restartdelay --rd --restart_delay
52testRestart( ['-r', '--rd', 30], restartopthash(sleep_interval => 30) );
53testRestart( ['-r', '--restart_delay', 30], restartopthash(sleep_interval => 30) );
54
f3bf2976 55# restart dir -restartdirectory --rdir --restart_directory
2c298960 56testRestart( ['-r', '--rdir', 'root'], restartopthash(directories => ['root']) );
57testRestart( ['-r', '--rdir', 'root', '--rdir', 'lib'], restartopthash(directories => ['root', 'lib']) );
58testRestart( ['-r', '--restart_directory', 'root'], restartopthash(directories => ['root']) );
59
60# restart regex -rr -restartregex --rr --restart_regex
61testRestart( ['-r', '--rr', 'foo'], restartopthash(filter => qr/foo/) );
62testRestart( ['-r', '--restart_regex', 'foo'], restartopthash(filter => qr/foo/) );
f3bf2976 63
6ec45f37 64done_testing;
f3bf2976 65
66sub testOption {
67 my ($argstring, $resultarray) = @_;
2c298960 68 my $app = _build_testapp($argstring);
69 lives_ok {
70 $app->run;
71 };
72 # First element of RUN_ARGS will be the script name, which we don't care about
73 shift @TestAppToTestScripts::RUN_ARGS;
74 is_deeply \@TestAppToTestScripts::RUN_ARGS, $resultarray, "is_deeply comparison " . join(' ', @$argstring);
75}
76
77sub testRestart {
78 my ($argstring, $resultarray) = @_;
79 my $app = _build_testapp($argstring);
80 my $args = {$app->_restarter_args};
81 is_deeply delete $args->{argv}, $argstring, 'argv is arg string';
82 is ref(delete $args->{start_sub}), 'CODE', 'Closure to start app present';
83 is_deeply $args, $resultarray, "is_deeply comparison of restarter args " . join(' ', @$argstring);
84}
85
86sub _build_testapp {
87 my ($argstring, $resultarray) = @_;
f3bf2976 88
6ec45f37 89 local @ARGV = @$argstring;
90 local @TestAppToTestScripts::RUN_ARGS;
2c298960 91 my $i;
6ec45f37 92 lives_ok {
2c298960 93 $i = Catalyst::Script::Server->new_with_options(application_name => 'TestAppToTestScripts');
94 } "new_with_options " . join(' ', @$argstring);;
95 ok $i;
96 return $i;
60b86a55 97}
98
f3bf2976 99# Returns the hash expected when no flags are passed
100sub opthash {
960bf5b0 101 return {
102 'pidfile' => undef,
103 'fork' => 0,
104 'follow_symlinks' => 0,
105 'background' => 0,
106 'keepalive' => 0,
107 @_,
108 };
60b86a55 109}
2c298960 110
111sub restartopthash {
112 return {
34be7d45 113 follow_symlinks => 0,
2c298960 114 @_,
115 };
116}