convert uses of Test::Exception to Test::Fatal
[gitmo/MooseX-Daemonize.git] / t / 10.pidfile.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 25;
7 use Test::Fatal;
8
9 BEGIN {
10     use_ok('MooseX::Daemonize::Pid::File');
11 }
12
13 {
14     my $f = MooseX::Daemonize::Pid::File->new(
15         file => [ 't', 'foo.pid' ]
16     );
17     isa_ok($f, 'MooseX::Daemonize::Pid::File');
18
19     isa_ok($f->file, 'Path::Class::File');
20
21     is($f->pid, $$, '... the PID is our current process');
22
23     is(
24         exception { $f->write },
25         undef,
26         '... writing the PID file',
27     );
28
29     is($f->file->slurp(chomp => 1), $f->pid, '... the PID in the file is correct');
30     
31     ok($f->is_running, '... it is running too');
32
33     is(
34         exception { $f->remove },
35         undef,
36         '... removing the PID file',
37     );
38
39     ok(!-e $f->file, '... the PID file does not exist anymore');
40 }
41
42 {
43     my $f = MooseX::Daemonize::Pid::File->new(
44         file => [ 't', 'bar.pid' ]
45     );
46     isa_ok($f, 'MooseX::Daemonize::Pid::File');
47
48     isa_ok($f->file, 'Path::Class::File');
49
50     is(
51         exception { $f->write },
52         undef,
53         '... writing the PID file',
54     );
55
56     is($f->file->slurp(chomp => 1), $f->pid, '... the PID in the file is correct');
57     is($f->pid, $$, '... the PID is our current process');
58     
59     ok($f->is_running, '... it is running too');    
60
61     is(
62         exception { $f->remove },
63         undef,
64         '... removing the PID file',
65     );
66
67     ok(!-e $f->file, '... the PID file does not exist anymore');
68 }
69
70 {
71     my $PID = 9999;
72     
73     my $f = MooseX::Daemonize::Pid::File->new(
74         file => [ 't', 'baz.pid' ],
75         pid  => $PID,
76     );
77     isa_ok($f, 'MooseX::Daemonize::Pid::File');
78
79     isa_ok($f->file, 'Path::Class::File');
80     
81     is($f->pid, $PID, '... the PID is our made up PID');
82
83     is(
84         exception { $f->write },
85         undef,
86         '... writing the PID file',
87     );
88
89     is($f->file->slurp(chomp => 1), $f->pid, '... the PID in the file is correct');
90
91     ok(!$f->is_running, '... it is not running (cause we made the PID up)');
92
93     is(
94         exception { $f->remove },
95         undef,
96         '... removing the PID file',
97     );
98
99     ok(!-e $f->file, '... the PID file does not exist anymore');
100 }