Developer-Dashboard
view release on metacpan or search on metacpan
t/103-collectorrunner-coverage.t view on Meta::CPAN
chmod 0600, $file;
}
}
{
write_raw_state( 'emptypayload.loop', '' );
no warnings 'redefine';
local *Developer::Dashboard::CollectorRunner::sleep = sub { return 0 };
like( ( eval { $runner->loop_state('emptypayload.loop'); 1 } ? '' : $@ ), qr/was empty/, 'loop_state reports a truly empty state payload' );
}
{
write_raw_state( 'nonref.loop', '{ not: valid json' );
no warnings 'redefine';
local *Developer::Dashboard::CollectorRunner::sleep = sub { return 0 };
ok( !eval { $runner->loop_state('nonref.loop'); 1 }, 'loop_state dies after retrying an undecodable state payload' );
}
{
# A decode that yields a falsy-but-defined value (no exception) drives the
# default decode-error fallback message.
write_raw_state( 'falsydecode.loop', '{}' );
no warnings 'redefine';
local *Developer::Dashboard::CollectorRunner::sleep = sub { return 0 };
local *Developer::Dashboard::CollectorRunner::json_decode = sub { return 0 };
ok( !eval { $runner->loop_state('falsydecode.loop'); 1 }, 'loop_state falls back to the default decode-error message when json_decode yields a falsy value' );
}
# ===========================================================================
# _write_loop_state: undef data merge and temp-open failure.
# ===========================================================================
{
my $state = $runner->_write_loop_state( 'undefdata.loop', undef );
is( $state->{name}, 'undefdata.loop', '_write_loop_state tolerates an undef data payload' );
}
{
SKIP: {
my $dir = $paths->collector_dir('nowrite.loop');
chmod 0500, $dir or skip 'chmod not honored on this filesystem', 1;
skip 'running as root defeats the unwritable-directory failure', 1 if -w $dir;
like( ( eval { $runner->_write_loop_state( 'nowrite.loop', { status => 'running' } ); 1 } ? '' : $@ ), qr/Unable to write/, '_write_loop_state dies when the temp state file cannot be opened' );
chmod 0700, $dir;
}
}
# ===========================================================================
# _slurp failure.
# ===========================================================================
like( ( eval { Developer::Dashboard::CollectorRunner::_slurp( File::Spec->catfile( $home, 'no-such-slurp-file' ) ); 1 } ? '' : $@ ), qr/Unable to read/, '_slurp dies for a missing file' );
# ===========================================================================
# _descriptor_is_inherited_pipe fd classification.
# ===========================================================================
is( $runner->_descriptor_is_inherited_pipe(undef), 0, '_descriptor_is_inherited_pipe rejects an undef fd' );
is( $runner->_descriptor_is_inherited_pipe('abc'), 0, '_descriptor_is_inherited_pipe rejects a non-numeric fd' );
is( $runner->_descriptor_is_inherited_pipe(999999999), 0, '_descriptor_is_inherited_pipe rejects an fd with no symlink target' );
{
open my $reg, '>', File::Spec->catfile( $home, 'fd-regular' ) or die $!;
is( $runner->_descriptor_is_inherited_pipe( fileno($reg) ), 0, '_descriptor_is_inherited_pipe ignores a plain-file fd without close_ipc' );
is( $runner->_descriptor_is_inherited_pipe( fileno($reg), close_ipc => 1 ), 0, '_descriptor_is_inherited_pipe ignores a plain-file fd even with close_ipc' );
close $reg;
socketpair my $sa, my $sb, AF_UNIX, SOCK_STREAM, PF_UNSPEC or die "socketpair failed: $!";
is( $runner->_descriptor_is_inherited_pipe( fileno($sa), close_ipc => 1 ), 1, '_descriptor_is_inherited_pipe treats a socket fd as an IPC endpoint under close_ipc' );
close $sa;
close $sb;
}
# ===========================================================================
# _current_perl_command / _dashboard_core_helper_path /
# _helper_file_supports_internal_command / _powershell_command /
# _powershell_single_quote / _replace_path_via_powershell /
# _overwrite_state_file_in_place / _spawn_windows_background_command.
# ===========================================================================
# _current_perl_command: Windows branch and the $^X shape guards on Linux.
{
no warnings 'redefine';
local *Developer::Dashboard::CollectorRunner::is_windows = sub { return 1 };
{
local *Developer::Dashboard::CollectorRunner::command_in_path = sub { return '/win/perl' };
is( $runner->_current_perl_command, '/win/perl', '_current_perl_command prefers perl on Windows when present' );
}
{
my %answers = ( 'perl' => undef, 'perl.exe' => '/win/perl.exe' );
local *Developer::Dashboard::CollectorRunner::command_in_path = sub { return $answers{ $_[0] } };
is( $runner->_current_perl_command, '/win/perl.exe', '_current_perl_command falls back to perl.exe on Windows' );
}
{
local *Developer::Dashboard::CollectorRunner::command_in_path = sub { return undef };
local $^X = 'x';
is( $runner->_current_perl_command, 'x', '_current_perl_command falls through to $^X when no Windows perl is resolvable' );
}
}
{
no warnings 'redefine';
local *Developer::Dashboard::CollectorRunner::command_in_path = sub { return '/usr/bin/perl' };
is( $runner->_current_perl_command, $^X, '_current_perl_command returns a runnable $^X on Linux' );
{
local $^X = '';
is( $runner->_current_perl_command, '/usr/bin/perl', '_current_perl_command skips an empty $^X' );
}
{
no warnings 'uninitialized';
local $^X = undef;
is( $runner->_current_perl_command, '/usr/bin/perl', '_current_perl_command skips an undef $^X' );
}
{
local $^X = File::Spec->catfile( $home, 'not-a-real-perl-binary' );
is( $runner->_current_perl_command, '/usr/bin/perl', '_current_perl_command skips a non-existent $^X' );
}
}
# _dashboard_core_helper_path: default command plus the undef shipped-path guard.
ok( defined $runner->_dashboard_core_helper_path(), '_dashboard_core_helper_path defaults its command argument' );
{
no warnings 'redefine';
local *Developer::Dashboard::InternalCLI::_helper_asset_path = sub { return undef };
ok( defined $runner->_dashboard_core_helper_path('collector-loop-foreground'), '_dashboard_core_helper_path tolerates an undef shipped helper path' );
}
# _helper_file_supports_internal_command: argument guards and unreadable file.
is( $runner->_helper_file_supports_internal_command( undef, 'cmd' ), 0, '_helper_file_supports_internal_command rejects an undef path' );
is( $runner->_helper_file_supports_internal_command( '', 'cmd' ), 0, '_helper_file_supports_internal_command rejects an empty path' );
( run in 1.451 second using v1.01-cache-2.11-cpan-9789f410c06 )