1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#!perl
use strict;
use warnings;
use lib '.';
use Test::More 'tests' => 4;
use Sys::HostIP qw/ip/;
use Capture::Tiny qw/capture/;
# check unavailable interface on Windows
{
# Mock Windows
local $Sys::HostIP::IS_WIN = 1;
{
## no critic qw(TestingAndDebugging::ProhibitNoWarnings)
no warnings qw/redefine once/;
*Sys::HostIP::_get_win32_interface_info = sub {
return {};
};
}
my ($stdout, $stderr, @result) = capture { ip() };
like(
$stderr,
qr/Unable to detect interface information!/,
"Inform user if interface info not detectable"
);
is( $result[0], '', "Empty ip info returned" );
}
# check unavailable interface on *nix
{
{
## no critic qw(TestingAndDebugging::ProhibitNoWarnings)
no warnings qw/redefine once/;
*Sys::HostIP::_get_unix_interface_info = sub {
return {};
};
}
my ($stdout, $stderr, @result) = capture { ip() };
like(
$stderr,
qr/Unable to detect interface information!/,
"Inform user if interface info not detectable"
);
is( $result[0], '', "Empty ip info returned" );
}
|