Pass Pod coverage
[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
7use Test::More 'no_plan';
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 stuff requires a threaded perl, apparently.
50# restart -r -restart --restart -R --restart
51# restart dly -rd -restartdelay --rdel --restart_delay
52# restart dir -restartdirectory --rdir --restart_directory
53# restart regex -rr -restartregex --rxp --restart_regex
54
55
56sub testOption {
57 my ($argstring, $resultarray) = @_;
58
59 subtest "Test for ARGV: @$argstring" => sub
60 {
61 plan tests => 2;
62 local @ARGV = @$argstring;
63 local @TestAppToTestScripts::RUN_ARGS;
64 lives_ok {
65 Catalyst::Script::Server->new_with_options(application_name => 'TestAppToTestScripts')->run;
66 } "new_with_options";
67 # First element of RUN_ARGS will be the script name, which we don't care about
68 shift @TestAppToTestScripts::RUN_ARGS;
69 is_deeply \@TestAppToTestScripts::RUN_ARGS, $resultarray, "is_deeply comparison";
70 done_testing;
71 };
60b86a55 72}
73
f3bf2976 74# Returns the hash expected when no flags are passed
75sub opthash {
960bf5b0 76 return {
77 'pidfile' => undef,
78 'fork' => 0,
79 'follow_symlinks' => 0,
80 'background' => 0,
81 'keepalive' => 0,
82 @_,
83 };
60b86a55 84}