File Coverage

blib/lib/Poet/t/Script.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1             package Poet::t::Script;
2             $Poet::t::Script::VERSION = '0.16';
3 1     1   850 use Test::Class::Most parent => 'Poet::Test::Class';
  1         30803  
  1         9  
4             use Capture::Tiny qw(capture);
5             use Cwd qw(realpath);
6             use YAML::XS;
7             use Poet::Tools qw(dirname mkpath perl_executable tempdir_simple write_file);
8              
9             my $script_template;
10              
11             sub test_script : Tests {
12             my $self = shift;
13             my $root_dir = $self->temp_env_dir();
14              
15             $self->write_conf_file( "$root_dir/conf/global/server.cfg", { 'foo.bar' => 42 } );
16              
17             my $script = "$root_dir/bin/foo/bar.pl";
18             mkpath( dirname($script), 0, 0775 );
19             my $env_lib_dir = realpath("lib");
20             write_file( $script, sprintf( $script_template, perl_executable(), $env_lib_dir ) );
21             chmod( 0775, $script );
22             my ( $stdout, $stderr ) = capture { system($script) };
23             ok( !$stderr, "no stderr" . ( defined($stderr) ? " - $stderr" : "" ) );
24              
25             my $result = Load($stdout);
26             is_deeply( $result, [ $root_dir, "$root_dir/lib", "$root_dir/lib", 42 ] );
27             }
28              
29             $script_template = '#!%s
30             use lib qw(%s);
31             use Poet::Script qw($conf $poet);
32             use YAML::XS;
33              
34             print Dump([$poet->root_dir, $poet->lib_dir, $INC[0], $conf->get("foo.bar")]);
35             ';
36              
37             1;