X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Faggregate%2Funit_core_script_server.t;h=7cd6fb4986e9d578e5bc3ddc1cf962e69db19606;hb=89222c2a9136170aa4012fbf3c7b804abeff2463;hp=c133e52df32f3744f8f6b9b467d1e2fc2f83fd20;hpb=1a3dd976ad46b71f2eabd3230a393c7a1aa84b6e;p=catagits%2FCatalyst-Runtime.git diff --git a/t/aggregate/unit_core_script_server.t b/t/aggregate/unit_core_script_server.t index c133e52..7cd6fb4 100644 --- a/t/aggregate/unit_core_script_server.t +++ b/t/aggregate/unit_core_script_server.t @@ -4,11 +4,16 @@ 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) @@ -60,8 +65,8 @@ testOption( [ qw/--follow_symlinks/ ], ['3000', undef, opthash(follow_symlinks = if (try { require MooseX::Daemonize; 1; }) { # background -background --bg --background - testOption( [ qw/--background/ ], ['3000', undef, opthash(background => 1)] ); - testOption( [ qw/--bg/ ], ['3000', undef, opthash(background => 1)] ); + testBackgroundOptionWithFork( [ qw/--background/ ]); + testBackgroundOptionWithFork( [ qw/--bg/ ]); } # restart -r -restart --restart -R --restart @@ -113,6 +118,7 @@ sub testOption { fail $_; }; # First element of RUN_ARGS will be the script name, which we don't care about + shift @TestAppToTestScripts::RUN_ARGS; my $server = pop @TestAppToTestScripts::RUN_ARGS; like ref($server), qr/^Plack::Handler/, 'Is a Plack::Handler'; @@ -127,6 +133,28 @@ sub testOption { is_deeply \@run_args, $resultarray, "is_deeply comparison " . join(' ', @$argstring); } +sub testBackgroundOptionWithFork { + my ($argstring) = @_; + + ## First, make sure we can get an app + my $app = _build_testapp($argstring); + + ## Sorry, don't really fork since this cause trouble in Test::Aggregate + $app->meta->add_around_method_modifier('daemon_fork', sub { return; }); + + try { + $app->run; + } + catch { + fail $_; + }; + + ## Check a few args + is_deeply $app->{ARGV}, $argstring; + is $app->{port}, '3000'; + is($app->{background}, 1); +} + sub testRestart { my ($argstring, $resultarray) = @_; my $app = _build_testapp($argstring); @@ -177,3 +205,8 @@ sub restartopthash { }; return $val; } + +chdir($cwd); + +1; +