File: sysinfo.t

package info (click to toggle)
libsystem-info-perl 0.066-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,904 kB
  • sloc: perl: 2,516; sh: 25; makefile: 2
file content (108 lines) | stat: -rwxr-xr-x 4,958 bytes parent folder | download | duplicates (2)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/perl

use strict;
use warnings;

$|++;

use Test::More tests => 70;
use Test::Warnings;
my $verbose = 0;

BEGIN { use_ok "System::Info", qw( sysinfo sysinfo_hash si_uname ) }

ok (defined &sysinfo,  "sysinfo  imported");
ok (defined &si_uname, "si_uname imported");

{   local $^O = "Generic";
    ok (my $si = System::Info->new, "new instance");

    isa_ok ($si => "System::Info::Base");
    ok (        $si->cpu_type, "CPU type: ".$si->cpu_type);
    ok (        $si->cpu,      "CPU     : ".$si->cpu);
    is (        $si->ncpu, "", "no ncpu");
    ok (        $si->os,       "OS      : ".$si->os);
    ok (defined $si->host,     "Host    : ".($si->host||"")); # Hostname can be Empty
    }

{   my $si = System::Info->new;

    my ($counter, $expect) = (0, 4);

    isa_ok ($si, "System::Info::Base");
    $counter += ok ($si->cpu_type, "cpu_type: " . $si->cpu_type);
    $counter += ok ($si->cpu,      "cpu: "      . $si->cpu);
    SKIP: {
	$si->ncpu or skip "No #cpu code for this platform", 1;
	$counter += ok ($si->ncpu,  "number of cpus: " . $si->ncpu);
	$expect++;
	}
    $counter += ok (        $si->os,   $si->os);
    $counter += ok (defined $si->host, $si->host);

    ok (my $sysinfo = sysinfo (), "sysinfo function");
    is (join (" " => @{ $si }{map "_$_" => qw( host os cpu_type )}),
       $sysinfo, "test sysinfo $sysinfo");

    is ($counter, $expect, "sysinfo: $sysinfo");

    ok (my $si_hash = sysinfo_hash (), "sysinfo_hash function");
    ok (ref $si, "Returns a ref");
    ok (defined $si_hash->{$_}, "Element $_ present and set") for
	qw( cpu cpu_count cpu_cores cpu_type distro hostname os osname osvers );
    }

{   my $si = System::Info->new;
    isa_ok ($si, "System::Info::Base");

    my $si_uname = join " " => map $si->$_ => qw( host os cpu ncpu cpu_type );
    is ($si->si_uname, $si_uname,              "si_uname");
    is ($si->si_uname, $si->si_uname ("a"),    "si_uname (a)");
    is ($si->si_uname ("rubbish"), $si_uname,  "si_uname (rubbish)");

    is ($si->si_uname ("n"), $si->{_host},     "si_uname (n)");
    is ($si->si_uname ("s"), $si->{_os},       "si_uname (s)");
    is ($si->si_uname ("m"), $si->{_cpu},      "si_uname (m)");
    is ($si->si_uname ("c"), $si->{_ncpu},     "si_uname (c)");
    is ($si->si_uname ("p"), $si->{_cpu_type}, "si_uname (p)");

    is ($si->si_uname (qw( n s )), "$si->{_host} $si->{_os}",       "si_uname (n, s)");
    is ($si->si_uname (qw( n s )), $si->si_uname ("n s"),           "si_uname (n s)");
    is ($si->si_uname (qw( s n )), $si->si_uname ("n s"),           "si_uname (s n)");

    is ($si->si_uname (qw( n m )), "$si->{_host} $si->{_cpu}",      "si_uname (n, m)");
    is ($si->si_uname (qw( n m )), $si->si_uname ("n m"),           "si_uname (n m)");
    is ($si->si_uname (qw( m n )), $si->si_uname ("n m"),           "si_uname (m n)");

    is ($si->si_uname (qw( n c )), "$si->{_host} $si->{_ncpu}",     "si_uname (n, c)");
    is ($si->si_uname (qw( n c )), $si->si_uname ("n c"),           "si_uname (n c)");
    is ($si->si_uname (qw( c n )), $si->si_uname ("n c"),           "si_uname (c n)");

    is ($si->si_uname (qw( n p )), "$si->{_host} $si->{_cpu_type}", "si_uname (n, p)");
    is ($si->si_uname (qw( n p )), $si->si_uname ("n p"),           "si_uname (n p)");
    is ($si->si_uname (qw( p n )), $si->si_uname ("n p"),           "si_uname (p n)");

    is ($si->si_uname (qw( s m )), "$si->{_os} $si->{_cpu}",        "si_uname (s, m)");
    is ($si->si_uname (qw( s m )), $si->si_uname ("s m"),           "si_uname (s m)");
    is ($si->si_uname (qw( m s )), $si->si_uname ("s m"),           "si_uname (m s)");

    is ($si->si_uname (qw( s c )), "$si->{_os} $si->{_ncpu}",       "si_uname (s, c)");
    is ($si->si_uname (qw( s c )), $si->si_uname ("s c"),           "si_uname (s c)");
    is ($si->si_uname (qw( c s )), $si->si_uname ("s c"),           "si_uname (c s)");

    is ($si->si_uname (qw( s p )), "$si->{_os} $si->{_cpu_type}",   "si_uname (s, p)");
    is ($si->si_uname (qw( s p )), $si->si_uname ("s p"),           "si_uname (s p)");
    is ($si->si_uname (qw( p s )), $si->si_uname ("s p"),           "si_uname (p s)");

    is ($si->si_uname (qw( m c )), "$si->{_cpu} $si->{_ncpu}",      "si_uname (m, c)");
    is ($si->si_uname (qw( m c )), $si->si_uname ("m c"),           "si_uname (m c)");
    is ($si->si_uname (qw( c m )), $si->si_uname ("m c"),           "si_uname (c m)");

    is ($si->si_uname (qw( m p )), "$si->{_cpu} $si->{_cpu_type}",  "si_uname (m, p)");
    is ($si->si_uname (qw( m p )), $si->si_uname ("m p"),           "si_uname (m p)");
    is ($si->si_uname (qw( p m )), $si->si_uname ("m p"),           "si_uname (p m)");

    is ($si->si_uname (qw( c p )), "$si->{_ncpu} $si->{_cpu_type}", "si_uname (c, p)");
    is ($si->si_uname (qw( c p )), $si->si_uname ("c p"),           "si_uname (c p)");
    is ($si->si_uname (qw( p c )), $si->si_uname ("c p"),           "si_uname (c p)");
    }