blib/lib/Poet/t/Run.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 50 CC 3 SCAR 13.3
CC
3
Cov
0%
test_run
6.0
is_port_active
6.0
BEGIN
2.0
CRAP 3.8
1 package Poet::t::Run;
2 $Poet::t::Run::VERSION = '0.16';
3 use Test::Class::Most parent => 'Poet::Test::Class';
4 use Poet::Tools qw(read_file);
5 use Guard;
6 use IO::Socket;
7 use Test::WWW::Mechanize;
8  
9 sub test_run : Tests {
10 my $self = shift;
11 my $poet = $self->temp_env( conf => { layer => 'development', server => { port => 9999 } } );
12 my $root_dir = $poet->root_dir;
13 my $run_log = "$root_dir/logs/run.log";
14 if ( my $pid = fork() ) {
15 scope_guard { kill( 1, $pid ) };
16 sleep(2);
17 ok( -f $run_log, "run log exists" );
18 like(
19 read_file($run_log),
20 qr/Watching .* for file updates.*Accepting connections at .*:9999/s,
21 "run log contents"
22 );
23 ok( is_port_active( 9999, '127.0.0.1' ), "port 9999 active" );
24  
25 my $mech = Test::WWW::Mechanize->new;
26 $mech->get_ok('http://127.0.0.1:9999/');
27 $mech->content_like(qr/Welcome to Poet/);
28 $mech->content_like(qr/Environment root.*\Q$root_dir\E/);
29 }
30 else {
31 close STDOUT;
32 close STDERR;
33 exec( $poet->bin_path("run.pl > $run_log 2>&1") );
34 }
35 }
36  
37 sub is_port_active {
38 my ( $port, $bind_addr ) = @_;
39  
40 return IO::Socket::INET->new(
41 PeerAddr => $bind_addr,
42 PeerPort => $port
43 ) ? 1 : 0;
44 }
45  
46 1;