-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn user if interface cannot be detected
We also tell the user how this situation can be fixed (by asking them to send us the output if `ifconfig` or `ipconfig`). This is much more helpful than "uninitialized value" warnings. If the interface can't be detected, we return the empty string from the `ip()` sub so that *something* turns up, but not something that's going to be misleading.
- Loading branch information
1 parent
887f011
commit d6cba1e
Showing
4 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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" ); | ||
} |