Catalyst-Runtime

 view release on metacpan or  search on metacpan

t/aggregate/unit_core_script_server.t  view on Meta::CPAN

use strict;
use warnings;

use FindBin qw/$Bin/;
use lib "$Bin/../lib";

use File::Temp qw/ tempdir /;
use Cwd;
use Test::More;
use Try::Tiny;

use Catalyst::Script::Server;

my $cwd = getcwd;
chdir(tempdir(CLEANUP => 1));

my $testopts;

# Test default (no opts/args behaviour)
# Note undef for host means we bind to all interfaces.
testOption( [ qw// ], ['3000', undef, opthash()] );

# Old version supports long format opts with either one or two dashes.  New version only supports two.
#                Old                       New
# help           -? -help --help           -? --help
# debug          -d -debug --debug         -d --debug
# host           -host --host              --host
testOption( [ qw/--host testhost/ ], ['3000', 'testhost', opthash(host => 'testhost')] );
testOption( [ qw/-h testhost/ ], ['3000', 'testhost', opthash(host => 'testhost')] );

# port           -p -port --port           -l --listen
testOption( [ qw/-p 3001/ ], ['3001', undef, opthash(port => 3001)] );
testOption( [ qw/--port 3001/ ], ['3001', undef, opthash(port => 3001)] );
{
    local $ENV{TESTAPPTOTESTSCRIPTS_PORT} = 5000;
    testOption( [ qw// ], [5000, undef, opthash(port => 5000)] );
}
{
    local $ENV{CATALYST_PORT} = 5000;
    testOption( [ qw// ], [5000, undef, opthash(port => 5000)] );
}

if (try { require Plack::Handler::Starman; 1; }) {
    # fork           -f -fork --fork           -f --fork
    testOption( [ qw/--fork/ ], ['3000', undef, opthash(fork => 1)] );
    testOption( [ qw/-f/ ], ['3000', undef, opthash(fork => 1)] );
}

if (try { require MooseX::Daemonize; 1; }) {
    # pidfile        -pidfile                  --pid --pidfile
    testOption( [ qw/--pidfile cat.pid/ ], ['3000', undef, opthash(pidfile => "cat.pid")] );
    testOption( [ qw/--pid cat.pid/ ], ['3000', undef, opthash(pidfile => "cat.pid")] );
}

if (try { require Plack::Handler::Starman; 1; }) {
    # keepalive      -k -keepalive --keepalive -k --keepalive
    testOption( [ qw/-k/ ], ['3000', undef, opthash(keepalive => 1)] );
    testOption( [ qw/--keepalive/ ], ['3000', undef, opthash(keepalive => 1)] );
}

# symlinks       -follow_symlinks          --sym --follow_symlinks
#
testOption( [ qw/--sym/ ], ['3000', undef, opthash(follow_symlinks => 1)] );
testOption( [ qw/--follow_symlinks/ ], ['3000', undef, opthash(follow_symlinks => 1)] );

if (try { require MooseX::Daemonize; 1; }) {
    # background     -background               --bg --background
    testBackgroundOptionWithFork( [ qw/--background/ ]);
    testBackgroundOptionWithFork( [ qw/--bg/ ]);
}



( run in 0.511 second using v1.01-cache-2.11-cpan-39bf76dae61 )