root/lang/perl/mobirc/trunk/t/06-daemonize.t @ 13031

Revision 5980, 0.7 kB (checked in by tokuhirom, 7 years ago)

merge

Line 
1use strict;
2use warnings;
3use Test::More;
4use App::Mobirc::Util;
5eval "use Proc::Daemon; use File::Temp;";
6if ($@) {
7    plan skip_all => "Proc::Daemon, File::Temp is not installed.";
8} else {
9    plan tests => 1;
10}
11
12my $tmpfh = File::Temp->new(UNLINK => 0);
13my $pid = fork();
14if ($pid == 0) {
15    # child
16    daemonize($tmpfh->filename);
17    exit(0);
18} elsif ($pid > 0) {
19    # parent
20    wait;
21    sleep 3; # ad-hoc
22    like slurp($tmpfh->filename), qr{^\d+\n$}, 'pid file is exist';
23    unlink $tmpfh->filename;
24} else {
25    die "fork error";
26}
27
28sub slurp {
29    my $fname = shift;
30
31    open my $fh, q{<}, $fname or die $!;
32    my $dat = join '', <$fh>;
33    close $fh;
34
35    return $dat;
36}
37
Note: See TracBrowser for help on using the browser.