Skip to content

increase test coverage #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ requires 'File::Path' => '2.08';

test_requires 'Test::More' => '0.88';
test_requires 'File::Temp' => '0.14';
test_requires 'Devel::Cover' => '1.23';

WriteAll;
9 changes: 7 additions & 2 deletions t/02_sleep_perl.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use warnings;
use strict;
use Test::More;

# enable coverage for get_command_output() commands
$ENV{'PERL5OPT'} = '-MDevel::Cover';

my ( $file, $ilib );

# Let's make it so people can test in t/ or in the dist directory.
Expand Down Expand Up @@ -43,8 +46,10 @@ ok $out = get_command_output( "$^X -I$ilib $file start" ), "Started system daemo
like $out, qr/\[Started\]/, "Daemon started for restarting.";
ok $out = get_command_output( "$^X -I$ilib $file status" ), "Get status of system daemon.";
like $out, qr/\[Running\]/, "Daemon running for restarting.";
ok $out = get_command_output( "$^X -I$ilib $file restart" ), "Get status of system daemon.";
like $out, qr/\[Stopped\].*\[Started\]/s, "Daemon restarted.";
ok $out = get_command_output( "$^X -I$ilib $file reload" ), "Reload system daemon.";
like $out, qr/\[Reloaded\]/, "Daemon reloaded.";
ok $out = get_command_output( "$^X -I$ilib $file restart" ), "Restart of system daemon.";
like $out, qr/\[Started\]/, "Daemon restarted.";
ok $out = get_command_output( "$^X -I$ilib $file status" ), "Get status of system daemon.";
like $out, qr/\[Running\]/, "Daemon running after restart.";
ok $out = get_command_output( "$^X -I$ilib $file stop" ), "Get status of system daemon.";
Expand Down
3 changes: 3 additions & 0 deletions t/02_sleep_perl_array.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use warnings;
use strict;
use Test::More;

# enable coverage for get_command_output() commands
$ENV{'PERL5OPT'} = '-MDevel::Cover';

my ( $file, $ilib );

# Let's make it so people can test in t/ or in the dist directory.
Expand Down
46 changes: 46 additions & 0 deletions t/02_sleep_perl_foreground.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/perl
use warnings;
use strict;
use Test::More;

# enable coverage for get_command_output() commands
$ENV{'PERL5OPT'} = '-MDevel::Cover';

my ( $file, $ilib );

# Let's make it so people can test in t/ or in the dist directory.
if ( -f 't/bin/02_sleep_perl_foreground.pl' ) { # Dist Directory.
$file = "t/bin/02_sleep_perl_foreground.pl";
$ilib = "lib";
} elsif ( -f 'bin/02_sleep_perl_foreground.pl' ) {
$file = "bin/02_sleep_perl_foreground.pl";
$ilib = "../lib";
} else {
die "Tests should be run in the dist directory or t/";
}


sub get_command_output {
my ( @command ) = @_;
open my $lf, "-|", @command
or die "Couldn't get pipe to '@command': $!";
my $content = do { local $/; <$lf> };
close $lf;
return $content;
}

my $out;

$out = get_command_output( "$^X -I$ilib $file foreground" );
like $out, qr//, "Daemon started quiet.";

sleep 10;

ok $out = get_command_output( "$^X -I$ilib $file status" ), "Get status of perl daemon.";
like $out, qr/\[Not Running\]/, "Daemon not running";

# Testing restart.
ok $out = get_command_output( "$^X -I$ilib $file start" ), "Started system daemon";
like $out, qr/\[Started\]/, "Daemon started for restarting.";

done_testing;
49 changes: 49 additions & 0 deletions t/02_sleep_perl_single.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/perl
use warnings;
use strict;
use Test::More;

# enable coverage for get_command_output() commands
$ENV{'PERL5OPT'} = '-MDevel::Cover';

my ( $file, $ilib );

# Let's make it so people can test in t/ or in the dist directory.
if ( -f 't/bin/02_sleep_perl_single.pl' ) { # Dist Directory.
$file = "t/bin/02_sleep_perl_single.pl";
$ilib = "lib";
} elsif ( -f 'bin/02_sleep_perl_single.pl' ) {
$file = "bin/02_sleep_perl_single.pl";
$ilib = "../lib";
} else {
die "Tests should be run in the dist directory or t/";
}


sub get_command_output {
my ( @command ) = @_;
open my $lf, "-|", @command
or die "Couldn't get pipe to '@command': $!";
my $content = do { local $/; <$lf> };
close $lf;
return $content;
}

my $out;

ok $out = get_command_output( "$^X -I$ilib $file start" ), "Started perl daemon";
like $out, qr/\[Started\]/, "Daemon started.";

sleep 10;

ok $out = get_command_output( "$^X -I$ilib $file status" ), "Get status of perl daemon.";
like $out, qr/\[Not Running\]/, "Daemon not running";

ok $out = get_command_output( "$^X -I$ilib $file help" ), "Get help for perl daemon.";
like $out, qr/Some test help$/, "Daemon help";

# Testing restart.
ok $out = get_command_output( "$^X -I$ilib $file start" ), "Started system daemon";
like $out, qr/\[Started\]/, "Daemon started for restarting.";

done_testing;
3 changes: 3 additions & 0 deletions t/02_sleep_system.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use warnings;
use strict;
use Test::More;

# enable coverage for get_command_output() commands
$ENV{'PERL5OPT'} = '-MDevel::Cover';

my ( $file, $ilib );

# Let's make it so people can test in t/ or in the dist directory.
Expand Down
3 changes: 3 additions & 0 deletions t/03_perl_gets_control.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use warnings;
use strict;
use Test::More;

# enable coverage for get_command_output() commands
$ENV{'PERL5OPT'} = '-MDevel::Cover';

my ( $file, $ilib );

# Let's make it so people can test in t/ or in the dist directory.
Expand Down
3 changes: 3 additions & 0 deletions t/06_stderr_stdout.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use strict;
use Test::More;
use File::Temp;

# enable coverage for get_command_output() commands
$ENV{'PERL5OPT'} = '-MDevel::Cover';

my ( $file, $ilib );

# Let's make it so people can test in t/ or in the dist directory.
Expand Down
26 changes: 26 additions & 0 deletions t/bin/02_sleep_perl_foreground.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/perl
use warnings;
use strict;
use Daemon::Control;

Daemon::Control->new({
name => "My Daemon",
lsb_start => '$syslog $remote_fs',
lsb_stop => '$syslog',
lsb_sdesc => 'My Daemon Short',
lsb_desc => 'My Daemon controls the My Daemon daemon.',
path => '/usr/sbin/mydaemon/init.pl',

program => sub { sleep $_[1] },
program_args => [ 10 ],

pid_file => 'pid_tmp',
stderr_file => '/dev/null',
stdout_file => '/dev/null',

user => (getpwuid($>))[0],
prereq_no_process => 1,

fork => 0,

})->run;
28 changes: 28 additions & 0 deletions t/bin/02_sleep_perl_single.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/perl
use warnings;
use strict;

use lib './t/lib';

use Daemon::Control;

Daemon::Control->with_plugins( qw( +Daemon::Control::Plugin::Help ) )->new({
name => "My Daemon",
lsb_start => '$syslog $remote_fs',
lsb_stop => '$syslog',
lsb_sdesc => 'My Daemon Short',
lsb_desc => 'My Daemon controls the My Daemon daemon.',
path => '/usr/sbin/mydaemon/init.pl',

program => sub { sleep $_[1] },
program_args => [ 10 ],

pid_file => 'pid_tmp',
stderr_file => '/dev/null',
stdout_file => '/dev/null',

fork => 1,

help => 'some test help',

})->run;
15 changes: 15 additions & 0 deletions t/lib/Daemon/Control/Plugin/Help.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package Daemon::Control::Plugin::Help;

use strict;
use warnings;

use Class::Method::Modifiers qw();
use Role::Tiny;

around 'help' => sub {
my $orig = shift;
print ucfirst( $orig->(@_) );
return 0;
};

1;