Unified help display, at the cost of having lost the info about what you fucked up...
[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
19# help -? -help --help -h --help
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
30$testopts = opthash();
31$testopts->{fork} = 1;
32testOption( [ qw/--fork/ ], ['3000', 'localhost', $testopts] );
33testOption( [ qw/-f/ ], ['3000', 'localhost', $testopts] );
34
35# pidfile -pidfile --pid --pidfile
36$testopts = opthash();
37$testopts->{pidfile} = "cat.pid";
38testOption( [ qw/--pidfile cat.pid/ ], ['3000', 'localhost', $testopts] );
39
40# keepalive -k -keepalive --keepalive -k --keepalive
41$testopts = opthash();
42$testopts->{keepalive} = 1;
43testOption( [ qw/-k/ ], ['3000', 'localhost', $testopts] );
44testOption( [ qw/--keepalive/ ], ['3000', 'localhost', $testopts] );
45
46# symlinks -follow_symlinks --sym --follow_symlinks
47$testopts = opthash();
48$testopts->{follow_symlinks} = 1;
49testOption( [ qw/--follow_symlinks/ ], ['3000', 'localhost', $testopts] );
50
51# background -background --bg --background
52$testopts = opthash();
53$testopts->{background} = 1;
54testOption( [ qw/--background/ ], ['3000', 'localhost', $testopts] );
53c6ec79 55
f3bf2976 56# Restart stuff requires a threaded perl, apparently.
57# restart -r -restart --restart -R --restart
58# restart dly -rd -restartdelay --rdel --restart_delay
59# restart dir -restartdirectory --rdir --restart_directory
60# restart regex -rr -restartregex --rxp --restart_regex
61
62
63sub testOption {
64 my ($argstring, $resultarray) = @_;
65
66 subtest "Test for ARGV: @$argstring" => sub
67 {
68 plan tests => 2;
69 local @ARGV = @$argstring;
70 local @TestAppToTestScripts::RUN_ARGS;
71 lives_ok {
72 Catalyst::Script::Server->new_with_options(application_name => 'TestAppToTestScripts')->run;
73 } "new_with_options";
74 # First element of RUN_ARGS will be the script name, which we don't care about
75 shift @TestAppToTestScripts::RUN_ARGS;
76 is_deeply \@TestAppToTestScripts::RUN_ARGS, $resultarray, "is_deeply comparison";
77 done_testing;
78 };
60b86a55 79}
80
f3bf2976 81# Returns the hash expected when no flags are passed
82sub opthash {
83 return { 'pidfile' => undef,
53c6ec79 84 'fork' => 0,
85 'follow_symlinks' => 0,
86 'background' => 0,
87 'keepalive' => 0,
f3bf2976 88 }
60b86a55 89}