App-Base
view release on metacpan or search on metacpan
is($sc->run, 0, 'run() returns 0');
is($sc->script_name, 'common.t', 'script_name() returns correct value');
is(trim($scswitches), trim($switches), 'switches() returns correct value');
divert_stderr(
sub {
exits_ok(sub { $sc->usage; }, "usage() method causes exit");
warnings_like {
exits_ok(sub { $sc->__error("Error message"); }, "__error() method causes exit");
}
[qr/^Error message/], "Expected warning on __error";
throws_ok { $sc->getOption('bogus_option'); } qr/Unknown option/, 'Bogus option names cause death';
is($sc->run, 0, 'Run returns 0');
COLUMNS:
{
my $long_switches = qq{--baz The baz option
--foo=<f> The foo option should be <f> (default: bar)
--fribitz=<f> fribitz is a floating-point option (default: 0.01)
--help Show this help information
--quux=N quux is an integer option (default: 7)
local $ENV{APP_BASE_DAEMON_PIDDIR} = $pdir;
ok(File::Flock::Tiny->trylock($pidfile), "Pidfile is not locked");
is(Test::Daemon->new->run, 0, 'Test daemon spawns detached child process');
wait_file($pidfile);
ok(-f $pidfile, "Pid file exists");
chomp(my $pid = read_file($pidfile));
ok $pid, "Have read daemon PID";
BAIL_OUT("No PID file, can't continue") unless $pid;
ok !File::Flock::Tiny->trylock($pidfile), "Pidfile is locked";
ok kill(0 => $pid), "Grandchild process is running";
throws_ok { Test::Daemon->new->run } qr/another copy of this daemon already running/, "Can not start second copy";
ok kill(INT => $pid), "Able to send SIGINT signal to process";
#wait pid to exit at most 5 seconds
for (my $i = 0; $i <= 10; $i++) {
last unless kill(0 => $pid);
Time::HiRes::usleep(5e5);
}
ok !kill(0 => $pid), "Grandchild process has shut down";
}
( run in 0.244 second using v1.01-cache-2.11-cpan-496ff517765 )