File: 03-iface-undetected.t

package info (click to toggle)
libsys-hostip-perl 2.120-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 240 kB
  • sloc: perl: 487; makefile: 2
file content (49 lines) | stat: -rw-r--r-- 1,187 bytes parent folder | download | duplicates (3)
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" );
}