sys-uname 1.0.4 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/{CHANGES → CHANGES.md} +58 -30
- data/Gemfile +7 -0
- data/LICENSE +177 -0
- data/MANIFEST.md +12 -0
- data/README.md +53 -0
- data/Rakefile +5 -7
- data/doc/uname.rdoc +127 -0
- data/examples/uname_test.rb +15 -15
- data/lib/sys/uname.rb +1 -1
- data/lib/sys/windows/uname.rb +8 -0
- data/spec/sys_platform_spec.rb +75 -0
- data/spec/sys_uname_spec.rb +445 -0
- data/sys-uname.gemspec +8 -6
- metadata +54 -36
- metadata.gz.sig +0 -0
- data/MANIFEST +0 -12
- data/README +0 -51
- data/doc/uname.txt +0 -127
- data/test/test_sys_platform.rb +0 -79
- data/test/test_sys_uname.rb +0 -464
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
## Description
|
2
|
+
A cross-platform Ruby interface for getting operating system information. The name
|
3
|
+
comes from the Unix 'uname' command, but this library works on MS Windows as well.
|
4
|
+
|
5
|
+
## Prerequisites
|
6
|
+
ffi 1.0 or later
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
`gem install sys-uname`
|
10
|
+
|
11
|
+
## Synopsis
|
12
|
+
```
|
13
|
+
require 'sys/uname' # require 'sys-uname' works, too
|
14
|
+
|
15
|
+
# You now have Sys::Uname and Sys::Platform classes available.
|
16
|
+
|
17
|
+
# Get full information about your system
|
18
|
+
p Sys::Uname.uname
|
19
|
+
|
20
|
+
# Check individual platform details about your system
|
21
|
+
p Sys::Platform.linux? # => true
|
22
|
+
p Sys::Platform::ARCH # => :x86_64
|
23
|
+
```
|
24
|
+
|
25
|
+
## Solaris Notes
|
26
|
+
Users on SunOS get several extra methods: architecture, platform,
|
27
|
+
hw_serial, hw_provider, srpc_domain, isa_list, and dhcp_cache.
|
28
|
+
|
29
|
+
## BSD flavors, including OS X
|
30
|
+
Users on BSD platforms get the extra Uname.model method.
|
31
|
+
|
32
|
+
## HP-UX Notes
|
33
|
+
HP-UX users get the extra Uname.id_number method. This is actually a
|
34
|
+
String, not a Fixnum, because that's how it's defined in the utsname
|
35
|
+
struct.
|
36
|
+
|
37
|
+
## MS Windows Notes
|
38
|
+
The C version for Windows has been completely scrapped in favor of an OLE
|
39
|
+
plus WMI approach. It is pure Ruby. Please see the MSDN documentation for
|
40
|
+
the Win32_OperatingSystem class for a complete list of what each of the
|
41
|
+
UnameStruct members mean.
|
42
|
+
|
43
|
+
## The Platform Class
|
44
|
+
This was added both as a nicer way to check simple information about your
|
45
|
+
system, and as a replacement for the old 'Platform' gem which is no longer
|
46
|
+
maintained.
|
47
|
+
|
48
|
+
## Future Plans
|
49
|
+
I may dump the "Uname" portion of this library, and rename the project
|
50
|
+
to just sys-platform.
|
51
|
+
|
52
|
+
## Documentation
|
53
|
+
For more details, see the 'uname.rdoc' file under the 'doc' directory.
|
data/Rakefile
CHANGED
@@ -2,8 +2,9 @@ require 'rake'
|
|
2
2
|
require 'rake/testtask'
|
3
3
|
require 'rake/clean'
|
4
4
|
require 'rbconfig'
|
5
|
+
require 'rspec/core/rake_task'
|
5
6
|
|
6
|
-
CLEAN.include("**/*.rbc", "**/*.rbx", "**/*.gem")
|
7
|
+
CLEAN.include("**/*.rbc", "**/*.rbx", "**/*.gem", "**/*.lock")
|
7
8
|
|
8
9
|
desc "Run the example program"
|
9
10
|
task :example do
|
@@ -20,7 +21,7 @@ namespace :gem do
|
|
20
21
|
require 'rubygems/package'
|
21
22
|
spec = eval(IO.read('sys-uname.gemspec'))
|
22
23
|
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
|
23
|
-
Gem::Package.build(spec
|
24
|
+
Gem::Package.build(spec)
|
24
25
|
end
|
25
26
|
|
26
27
|
desc "Install the sys-uname gem"
|
@@ -31,9 +32,6 @@ namespace :gem do
|
|
31
32
|
end
|
32
33
|
|
33
34
|
desc "Run the test suite"
|
34
|
-
|
35
|
-
t.warning = true
|
36
|
-
t.verbose = true
|
37
|
-
end
|
35
|
+
RSpec::Core::RakeTask.new(:spec)
|
38
36
|
|
39
|
-
task :default => :
|
37
|
+
task :default => :spec
|
data/doc/uname.rdoc
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
== Description
|
2
|
+
A cross platform Ruby interface for getting operating system information. The
|
3
|
+
name comes from the Unix 'uname' command, but this library works on Windows as well.
|
4
|
+
|
5
|
+
== Synopsis
|
6
|
+
require 'sys/uname'
|
7
|
+
include Sys
|
8
|
+
|
9
|
+
# Unix
|
10
|
+
puts Uname.nodename => my_host
|
11
|
+
puts Uname.version => #1 Fri Oct 24 22:43:28 MDT 2003
|
12
|
+
puts Uname.sysname => Linux
|
13
|
+
puts Uname.machine => i686
|
14
|
+
puts Uname.release => 2.4.22-21mdk
|
15
|
+
|
16
|
+
p Uname.uname => Show all UnameStruct members
|
17
|
+
|
18
|
+
# Windows
|
19
|
+
u = Uname.uname
|
20
|
+
puts u.caption => 'Microsoft Windows XP Home Edition
|
21
|
+
puts u.csd_version => 'Service Pack 2'
|
22
|
+
|
23
|
+
== Constants
|
24
|
+
VERSION
|
25
|
+
The current version number of the sys-uname library. This is a String.
|
26
|
+
|
27
|
+
== Class Methods
|
28
|
+
Uname.sysname
|
29
|
+
Returns the operating system name, e.g. "SunOS"
|
30
|
+
|
31
|
+
Uname.nodename
|
32
|
+
Returns the nodename. This is usually, but not necessarily, the
|
33
|
+
same as the system's hostname.
|
34
|
+
|
35
|
+
You cannot currently set the nodename (root or otherwise). This may
|
36
|
+
be added in a future release.
|
37
|
+
|
38
|
+
Uname.machine
|
39
|
+
Returns the machine hardware type, e.g. "i686"
|
40
|
+
|
41
|
+
Uname.version
|
42
|
+
Returns the operating system version. e.g. "5.8". In the case of MS
|
43
|
+
Windows, it returns the version plus patch information, separated by
|
44
|
+
a hyphen, e.g. "2915-Service Pack 2".
|
45
|
+
|
46
|
+
Uname.release
|
47
|
+
Returns the operating system release, e.g. "2.2.16-3"
|
48
|
+
|
49
|
+
Uname.uname
|
50
|
+
Returns a struct of type UnameStruct that contains sysname, nodename,
|
51
|
+
machine, version, and release. On Solaris, it will also include
|
52
|
+
architecture and platform. On HP-UX, it will also include id_number.
|
53
|
+
|
54
|
+
MS Windows - there are many more, and different, fields in the struct.
|
55
|
+
Please see the MSDN documenation on the Win32_OperatingSystem WMI class
|
56
|
+
for a complete explanation of what each of these members mean.
|
57
|
+
|
58
|
+
== Solaris Only
|
59
|
+
Uname.architecture
|
60
|
+
Returns the instruction set architecture, e.g. "sparc"
|
61
|
+
|
62
|
+
Uname.platform
|
63
|
+
Returns the platform identifier, e.g. "SUNW,Sun-Blade-100"
|
64
|
+
|
65
|
+
Uname.isa_list
|
66
|
+
Returns a space separated string containing a list of all variant
|
67
|
+
instruction set architectures executable on the current system.
|
68
|
+
|
69
|
+
They are listed in order of performance, from best to worst.
|
70
|
+
|
71
|
+
Uname.hw_provider
|
72
|
+
Returns the name of the hardware manufacturer.
|
73
|
+
|
74
|
+
Uname.hw_serial_number
|
75
|
+
Returns the ASCII representation of the hardware-specific serial number
|
76
|
+
of the machine that executes the function.
|
77
|
+
|
78
|
+
Uname.srpc_domain
|
79
|
+
Returns the name of the Secure Remote Procedure Call domain, if any.
|
80
|
+
|
81
|
+
Uname.dhcp_cache
|
82
|
+
Returns a hexidecimal encoding, in String form, of the name of the
|
83
|
+
interface configured by boot(1M) followed by the DHCPACK reply from
|
84
|
+
the server.
|
85
|
+
|
86
|
+
== BSD Platforms Only (including OS X)
|
87
|
+
Uname.model
|
88
|
+
Returns the model type, e.g. "PowerBook5,1"
|
89
|
+
|
90
|
+
== HP-UX Only
|
91
|
+
Uname.id
|
92
|
+
Returns the id number, e.g. 234233587. This is a String, not a Fixnum.
|
93
|
+
|
94
|
+
== Notes
|
95
|
+
Not all of the information that you might be used to seeing with
|
96
|
+
a 'uname -a' is available. This may be added in future releases,
|
97
|
+
but since different implementations provide different information
|
98
|
+
(via different header files) it will be a bit of a pain.
|
99
|
+
|
100
|
+
Windows users - please see the MSDN documentation for the
|
101
|
+
Win32_OperatingSystem class for a complete list of what each of the
|
102
|
+
UnameStruct members mean.
|
103
|
+
|
104
|
+
== Known Bugs
|
105
|
+
None that I'm aware of. Please log any bugs on the project page at
|
106
|
+
https://github.com/djberg96/sys-uname
|
107
|
+
|
108
|
+
== Future Plans
|
109
|
+
Add additional info for Linux, Solaris, BSD.
|
110
|
+
|
111
|
+
== License
|
112
|
+
Apache-2.0
|
113
|
+
|
114
|
+
== Copyright
|
115
|
+
(C) 2002-2020 Daniel J. Berger
|
116
|
+
All Rights Reserved
|
117
|
+
|
118
|
+
== Warranty
|
119
|
+
This package is provided "as is" and without any express or
|
120
|
+
implied warranties, including, without limitation, the implied
|
121
|
+
warranties of merchantability and fitness for a particular purpose.
|
122
|
+
|
123
|
+
== Author
|
124
|
+
Daniel Berger
|
125
|
+
|
126
|
+
== See Also
|
127
|
+
uname(1) for unix, or WMI for MS Windows.
|
data/examples/uname_test.rb
CHANGED
@@ -16,27 +16,27 @@ puts 'Release: ' + Uname.release
|
|
16
16
|
puts 'Machine: ' + Uname.machine # May be "unknown" on Win32
|
17
17
|
|
18
18
|
if RbConfig::CONFIG['host_os'] =~ /sun|solaris/i
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
print "\nSolaris specific tests\n"
|
20
|
+
puts "==========================="
|
21
|
+
puts 'Architecture: ' + Uname.architecture
|
22
|
+
puts 'Platform: ' + Uname.platform
|
23
|
+
puts 'Instruction Set List: ' + Uname.isa_list.split.join(", ")
|
24
|
+
puts 'Hardware Provider: ' + Uname.hw_provider
|
25
|
+
puts 'Serial Number: ' + Uname.hw_serial_number.to_s
|
26
|
+
puts 'SRPC Domain: ' + Uname.srpc_domain # might be empty
|
27
|
+
puts 'DHCP Cache: ' + Uname.dhcp_cache # might be empty
|
28
28
|
end
|
29
29
|
|
30
30
|
if RbConfig::CONFIG['host_os'] =~ /powerpc|darwin|bsd|mach/i
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
print "\nBSD/OS X specific tests\n"
|
32
|
+
puts "======================="
|
33
|
+
puts 'Model: ' + Uname.model
|
34
34
|
end
|
35
35
|
|
36
36
|
if RbConfig::CONFIG['host_os'] =~ /hpux/i
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
print "\nHP-UX specific tests\n"
|
38
|
+
puts "========================"
|
39
|
+
puts "ID: " + Uname.id
|
40
40
|
end
|
41
41
|
|
42
42
|
print "\nTest finished successfully\n"
|
data/lib/sys/uname.rb
CHANGED
data/lib/sys/windows/uname.rb
CHANGED
@@ -34,6 +34,7 @@ module Sys
|
|
34
34
|
debug
|
35
35
|
description
|
36
36
|
distributed
|
37
|
+
encryption_level
|
37
38
|
foreground_application_boost
|
38
39
|
free_physical_memory
|
39
40
|
free_space_in_paging_files
|
@@ -57,6 +58,7 @@ module Sys
|
|
57
58
|
plus_product_id
|
58
59
|
plus_version_number
|
59
60
|
primary
|
61
|
+
product_type
|
60
62
|
quantum_length
|
61
63
|
quantum_type
|
62
64
|
registered_user
|
@@ -65,8 +67,10 @@ module Sys
|
|
65
67
|
service_pack_minor_version
|
66
68
|
size_stored_in_paging_files
|
67
69
|
status
|
70
|
+
suite_mask
|
68
71
|
system_device
|
69
72
|
system_directory
|
73
|
+
system_drive
|
70
74
|
total_swap_space_size
|
71
75
|
total_virtual_memory_size
|
72
76
|
total_visible_memory_size
|
@@ -443,6 +447,7 @@ module Sys
|
|
443
447
|
os.Debug,
|
444
448
|
os.Description,
|
445
449
|
os.Distributed,
|
450
|
+
os.EncryptionLevel,
|
446
451
|
os.ForegroundApplicationBoost,
|
447
452
|
self.convert(os.FreePhysicalMemory),
|
448
453
|
self.convert(os.FreeSpaceInPagingFiles),
|
@@ -466,6 +471,7 @@ module Sys
|
|
466
471
|
os.PlusProductID,
|
467
472
|
os.PlusVersionNumber,
|
468
473
|
os.Primary,
|
474
|
+
os.ProductType,
|
469
475
|
os.respond_to?(:QuantumLength) ? os.QuantumLength : nil,
|
470
476
|
os.respond_to?(:QuantumType) ? os.QuantumType : nil,
|
471
477
|
os.RegisteredUser,
|
@@ -474,8 +480,10 @@ module Sys
|
|
474
480
|
os.ServicePackMinorVersion,
|
475
481
|
self.convert(os.SizeStoredInPagingFiles),
|
476
482
|
os.Status,
|
483
|
+
os.SuiteMask,
|
477
484
|
os.SystemDevice,
|
478
485
|
os.SystemDirectory,
|
486
|
+
os.SystemDrive,
|
479
487
|
self.convert(os.TotalSwapSpaceSize),
|
480
488
|
self.convert(os.TotalVirtualMemorySize),
|
481
489
|
self.convert(os.TotalVisibleMemorySize),
|
@@ -0,0 +1,75 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# sys_platform_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Sys::Platform class.
|
5
|
+
##############################################################################
|
6
|
+
require 'rspec'
|
7
|
+
require 'sys/uname'
|
8
|
+
require 'rbconfig'
|
9
|
+
|
10
|
+
RSpec.describe Sys::Platform do
|
11
|
+
|
12
|
+
before(:context) do
|
13
|
+
@host_os = RbConfig::CONFIG['host_os']
|
14
|
+
@windows = @host_os =~ /mingw|mswin|windows/i ? true : false
|
15
|
+
end
|
16
|
+
|
17
|
+
example "the VERSION constant is set to the expected value" do
|
18
|
+
expect(Sys::Platform::VERSION).to eql('1.2.2')
|
19
|
+
expect(Sys::Platform::VERSION).to be_frozen
|
20
|
+
end
|
21
|
+
|
22
|
+
example "the ARCH constant is defined" do
|
23
|
+
expect(Sys::Platform::ARCH).to be_kind_of(Symbol)
|
24
|
+
end
|
25
|
+
|
26
|
+
example "the OS constant is defined" do
|
27
|
+
expect(Sys::Platform::OS).to be_kind_of(Symbol)
|
28
|
+
end
|
29
|
+
|
30
|
+
example "the IMPL constant is defined" do
|
31
|
+
expect(Sys::Platform::IMPL).to be_kind_of(Symbol)
|
32
|
+
end
|
33
|
+
|
34
|
+
example "the IMPL returns an expected value", :if => @windows do
|
35
|
+
expect(Sys::Platform::IMPL).to include([:mingw, :mswin])
|
36
|
+
end
|
37
|
+
|
38
|
+
example "the mac? method is defined and returns a boolean" do
|
39
|
+
expect(Sys::Platform).to respond_to(:mac?)
|
40
|
+
expect(Sys::Platform.mac?).to eql(true).or eql(false)
|
41
|
+
end
|
42
|
+
|
43
|
+
example "the windows? method is defined and returns a boolean" do
|
44
|
+
expect(Sys::Platform).to respond_to(:windows?)
|
45
|
+
expect(Sys::Platform.windows?).to eql(true).or eql(false)
|
46
|
+
end
|
47
|
+
|
48
|
+
example "the windows? method returns the expected value" do
|
49
|
+
expect(Sys::Platform.windows?).to eql(@windows)
|
50
|
+
end
|
51
|
+
|
52
|
+
example "the unix? method is defined and returns a boolean" do
|
53
|
+
expect(Sys::Platform).to respond_to(:unix?)
|
54
|
+
expect(Sys::Platform.unix?).to eql(true).or eql(false)
|
55
|
+
end
|
56
|
+
|
57
|
+
example "the unix? method returns the expected value" do
|
58
|
+
expect(Sys::Platform.unix?).not_to eql(@windows)
|
59
|
+
end
|
60
|
+
|
61
|
+
example "the solaris? method is defined and returns a boolean" do
|
62
|
+
expect(Sys::Platform).to respond_to(:solaris?)
|
63
|
+
expect(Sys::Platform.solaris?).to eql(true).or eql(false)
|
64
|
+
end
|
65
|
+
|
66
|
+
example "the linux? method is defined and returns a boolean" do
|
67
|
+
expect(Sys::Platform).to respond_to(:linux?)
|
68
|
+
expect(Sys::Platform.linux?).to eql(true).or eql(false)
|
69
|
+
end
|
70
|
+
|
71
|
+
example "the bsd? method is defined and returns a boolean" do
|
72
|
+
expect(Sys::Platform).to respond_to(:bsd?)
|
73
|
+
expect(Sys::Platform.bsd?).to eql(true).or eql(false)
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,445 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# sys_uname_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the sys-uname library. Run 'rake test' to execute tests.
|
5
|
+
##############################################################################
|
6
|
+
require 'rspec'
|
7
|
+
require 'sys/uname'
|
8
|
+
require 'rbconfig'
|
9
|
+
|
10
|
+
RSpec.describe Sys::Uname do
|
11
|
+
context "universal singleton methods" do
|
12
|
+
example "version constant is set to expected value" do
|
13
|
+
expect(Sys::Uname::VERSION).to eql('1.2.2')
|
14
|
+
expect(Sys::Uname::VERSION).to be_frozen
|
15
|
+
end
|
16
|
+
|
17
|
+
example "machine singleton method works as expected" do
|
18
|
+
expect(described_class).to respond_to(:machine)
|
19
|
+
expect{ described_class.machine }.not_to raise_error
|
20
|
+
expect(described_class.machine).to be_kind_of(String)
|
21
|
+
expect(described_class.machine.size).to be > 0
|
22
|
+
end
|
23
|
+
|
24
|
+
example "version singleton method works as expected" do
|
25
|
+
expect(described_class).to respond_to(:version)
|
26
|
+
expect{ described_class.version }.not_to raise_error
|
27
|
+
expect(described_class.version).to be_kind_of(String)
|
28
|
+
expect(described_class.version.size).to be > 0
|
29
|
+
end
|
30
|
+
|
31
|
+
example "nodename singleton method works as expected" do
|
32
|
+
expect(described_class).to respond_to(:nodename)
|
33
|
+
expect{ described_class.nodename }.not_to raise_error
|
34
|
+
expect(described_class.nodename).to be_kind_of(String)
|
35
|
+
expect(described_class.nodename.size).to be > 0
|
36
|
+
end
|
37
|
+
|
38
|
+
example "release singleton method works as expected" do
|
39
|
+
expect(described_class).to respond_to(:release)
|
40
|
+
expect{ described_class.release }.not_to raise_error
|
41
|
+
expect(described_class.release).to be_kind_of(String)
|
42
|
+
expect(described_class.release.size).to be > 0
|
43
|
+
end
|
44
|
+
|
45
|
+
example "sysname singleton method works as expected" do
|
46
|
+
expect(described_class).to respond_to(:sysname)
|
47
|
+
expect{ described_class.sysname }.not_to raise_error
|
48
|
+
expect(described_class.sysname).to be_kind_of(String)
|
49
|
+
expect(described_class.sysname.size).to be > 0
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "singleton methods for Solaris only", :if => RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i do
|
54
|
+
example "architecture singleton method works as expected on solaris" do
|
55
|
+
expect(described_class).to respond_to(:architecture)
|
56
|
+
expect{ described_class.architecture }.not_to raise_error
|
57
|
+
expect(described_class.architecture).to be_kind_of(String)
|
58
|
+
end
|
59
|
+
|
60
|
+
example "platform singleton method works as expected on solaris" do
|
61
|
+
expect(described_class).to respond_to(:platform)
|
62
|
+
expect{ described_class.platform }.not_to raise_error
|
63
|
+
expect(described_class.platform).to be_kind_of(String)
|
64
|
+
end
|
65
|
+
|
66
|
+
example "isa_list singleton method works as expected on solaris" do
|
67
|
+
expect(described_class).to respond_to(:isa_list)
|
68
|
+
expect{ described_class.isa_list }.not_to raise_error
|
69
|
+
expect(described_class.isa_list).to be_kind_of(String)
|
70
|
+
end
|
71
|
+
|
72
|
+
example "hw_provider singleton method works as expected on solaris" do
|
73
|
+
expect(described_class).to respond_to(:hw_provider)
|
74
|
+
expect{ described_class.hw_provider }.not_to raise_error
|
75
|
+
expect(described_class.hw_provider).to be_kind_of(String)
|
76
|
+
end
|
77
|
+
|
78
|
+
example "hw_serial singleton method works as expected on solaris" do
|
79
|
+
expect(described_class).to respond_to(:hw_serial)
|
80
|
+
expect{ described_class.hw_serial }.not_to raise_error
|
81
|
+
expect(described_class.hw_serial).to be_kind_of(Integer)
|
82
|
+
end
|
83
|
+
|
84
|
+
example "srpc_domain singleton method works as expected on solaris" do
|
85
|
+
expect(described_class).to respond_to(:srpc_domain)
|
86
|
+
expect{ described_class.srpc_domain }.not_to raise_error
|
87
|
+
expect(described_class.srpc_domain).to be_kind_of(String)
|
88
|
+
end
|
89
|
+
|
90
|
+
example "dhcp_cache singleton method works as expected on solaris" do
|
91
|
+
expect(described_class).to respond_to(:dhcp_cache)
|
92
|
+
expect{ described_class.dhcp_cache }.not_to raise_error
|
93
|
+
expect(described_class.dhcp_cache).to be_kind_of(String)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "singleton methods for BSD and Darwin only", :if => RbConfig::CONFIG['host_os'] =~ /darwin|bsd/i do
|
98
|
+
example "model singleton method works as expected on BSD and Darwin" do
|
99
|
+
expect(described_class).to respond_to(:model)
|
100
|
+
expect{ described_class.model }.not_to raise_error
|
101
|
+
expect(described_class.model).to be_kind_of(String)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "singleton methods for HP-UX only", :if => RbConfig::CONFIG['host_os'] =~ /hpux/i do
|
106
|
+
example "id_number singleton method works as expected on HP-UX" do
|
107
|
+
expect(described_class).to respond_to(:id_number)
|
108
|
+
expect{ described_class.id_number }.not_to raise_error
|
109
|
+
expect(described_class.id_number).to be_kind_of(String)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "uname struct" do
|
114
|
+
example "uname struct contains expected members based on platform" do
|
115
|
+
members = %w/sysname nodename machine version release/
|
116
|
+
case RbConfig::CONFIG['host_os']
|
117
|
+
when /linux/i
|
118
|
+
members.push('domainname')
|
119
|
+
when /sunos|solaris/i
|
120
|
+
members.push(
|
121
|
+
'architecture', 'platform', 'hw_serial', 'hw_provider',
|
122
|
+
'srpc_domain', 'isa_list', 'dhcp_cache'
|
123
|
+
)
|
124
|
+
when /powerpc|darwin|bsd/i
|
125
|
+
members.push('model')
|
126
|
+
when /hpux/i
|
127
|
+
members.push('id')
|
128
|
+
when /win32|mingw|cygwin|dos|windows/i
|
129
|
+
members = %w[
|
130
|
+
boot_device build_number build_type caption code_set country_code
|
131
|
+
creation_class_name cscreation_class_name csd_version cs_name
|
132
|
+
current_time_zone debug description distributed encryption_level
|
133
|
+
foreground_application_boost free_physical_memory
|
134
|
+
free_space_in_paging_files free_virtual_memory
|
135
|
+
install_date last_bootup_time local_date_time locale
|
136
|
+
manufacturer max_number_of_processes max_process_memory_size
|
137
|
+
name number_of_licensed_users number_of_processes
|
138
|
+
number_of_users organization os_language os_product_suite
|
139
|
+
os_type other_type_description plus_product_id
|
140
|
+
plus_version_number primary product_type quantum_length quantum_type
|
141
|
+
registered_user serial_number service_pack_major_version
|
142
|
+
service_pack_minor_version size_stored_in_paging_files
|
143
|
+
status suite_mask system_device system_directory system_drive total_swap_space_size
|
144
|
+
total_virtual_memory_size total_visible_memory_size version
|
145
|
+
windows_directory
|
146
|
+
]
|
147
|
+
end
|
148
|
+
|
149
|
+
members.map!{ |e| e.to_sym } if RUBY_VERSION.to_f >= 1.9
|
150
|
+
|
151
|
+
expect{ described_class.uname }.not_to raise_error
|
152
|
+
expect(described_class.uname).to be_kind_of(Struct)
|
153
|
+
expect(described_class.uname.members.sort).to eql(members.sort)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "ffi" do
|
158
|
+
example "ffi and internal functions are not public" do
|
159
|
+
methods = described_class.methods(false).map{ |e| e.to_s }
|
160
|
+
expect(methods).not_to include('get_model')
|
161
|
+
expect(methods).not_to include('get_si')
|
162
|
+
expect(methods).not_to include('uname_c')
|
163
|
+
expect(methods).not_to include('sysctl')
|
164
|
+
expect(methods).not_to include('sysinfo')
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context "instance methods for MS Windows", :if => File::ALT_SEPARATOR do
|
169
|
+
example "boot_device" do
|
170
|
+
expect{ described_class.uname.boot_device }.not_to raise_error
|
171
|
+
expect(described_class.uname.boot_device).to be_kind_of(String)
|
172
|
+
end
|
173
|
+
|
174
|
+
example "build_number" do
|
175
|
+
expect{ described_class.uname.build_number }.not_to raise_error
|
176
|
+
expect(described_class.uname.build_number).to be_kind_of(String)
|
177
|
+
end
|
178
|
+
|
179
|
+
example "build_type" do
|
180
|
+
expect{ described_class.uname.build_type }.not_to raise_error
|
181
|
+
expect(described_class.uname.build_type).to be_kind_of(String)
|
182
|
+
end
|
183
|
+
|
184
|
+
example "caption" do
|
185
|
+
expect{ described_class.uname.caption }.not_to raise_error
|
186
|
+
expect(described_class.uname.caption).to be_kind_of(String)
|
187
|
+
end
|
188
|
+
|
189
|
+
example "code_set" do
|
190
|
+
expect{ described_class.uname.code_set }.not_to raise_error
|
191
|
+
expect(described_class.uname.code_set).to be_kind_of(String)
|
192
|
+
end
|
193
|
+
|
194
|
+
example "country_code" do
|
195
|
+
expect{ described_class.uname.country_code }.not_to raise_error
|
196
|
+
expect(described_class.uname.country_code).to be_kind_of(String)
|
197
|
+
end
|
198
|
+
|
199
|
+
example "creation_class_name" do
|
200
|
+
expect{ described_class.uname.creation_class_name }.not_to raise_error
|
201
|
+
expect(described_class.uname.creation_class_name).to be_kind_of(String)
|
202
|
+
end
|
203
|
+
|
204
|
+
example "cscreation_class_name" do
|
205
|
+
expect{ described_class.uname.cscreation_class_name }.not_to raise_error
|
206
|
+
expect(described_class.uname.cscreation_class_name).to be_kind_of(String)
|
207
|
+
end
|
208
|
+
|
209
|
+
example "csd_version" do
|
210
|
+
expect{ described_class.uname.csd_version }.not_to raise_error
|
211
|
+
expect(described_class.uname.csd_version).to be_kind_of(String).or be_nil
|
212
|
+
end
|
213
|
+
|
214
|
+
example "cs_name" do
|
215
|
+
expect{ described_class.uname.cs_name }.not_to raise_error
|
216
|
+
expect(described_class.uname.cs_name).to be_kind_of(String)
|
217
|
+
end
|
218
|
+
|
219
|
+
example "current_time_zone" do
|
220
|
+
expect{ described_class.uname.current_time_zone }.not_to raise_error
|
221
|
+
expect(described_class.uname.current_time_zone).to be_kind_of(Integer)
|
222
|
+
end
|
223
|
+
|
224
|
+
example "debug" do
|
225
|
+
expect{ described_class.uname.debug }.not_to raise_error
|
226
|
+
expect(described_class.uname.debug).to be(true).or be(false)
|
227
|
+
end
|
228
|
+
|
229
|
+
example "description" do
|
230
|
+
expect{ described_class.uname.description }.not_to raise_error
|
231
|
+
expect(described_class.uname.description).to be_kind_of(String)
|
232
|
+
end
|
233
|
+
|
234
|
+
example "distributed" do
|
235
|
+
expect{ described_class.uname.distributed }.not_to raise_error
|
236
|
+
expect(described_class.uname.distributed).to be(true).or be(false)
|
237
|
+
end
|
238
|
+
|
239
|
+
example "encryption_level" do
|
240
|
+
expect{ described_class.uname.encryption_level }.not_to raise_error
|
241
|
+
expect(described_class.uname.encryption_level).to be_kind_of(Integer)
|
242
|
+
end
|
243
|
+
|
244
|
+
example "foreground_application_boost" do
|
245
|
+
expect{ described_class.uname.foreground_application_boost }.not_to raise_error
|
246
|
+
expect(described_class.uname.foreground_application_boost).to be_kind_of(Integer)
|
247
|
+
end
|
248
|
+
|
249
|
+
example "free_physical_memory" do
|
250
|
+
expect{ described_class.uname.free_physical_memory }.not_to raise_error
|
251
|
+
expect(described_class.uname.free_physical_memory).to be_kind_of(Integer)
|
252
|
+
end
|
253
|
+
|
254
|
+
example "free_space_in_paging_files" do
|
255
|
+
expect{ described_class.uname.free_space_in_paging_files }.not_to raise_error
|
256
|
+
expect(described_class.uname.free_space_in_paging_files).to be_kind_of(Integer)
|
257
|
+
end
|
258
|
+
|
259
|
+
example "free_virtual_memory" do
|
260
|
+
expect{ described_class.uname.free_virtual_memory}.not_to raise_error
|
261
|
+
expect(described_class.uname.free_virtual_memory).to be_kind_of(Integer)
|
262
|
+
end
|
263
|
+
|
264
|
+
example "install_date" do
|
265
|
+
expect{ described_class.uname.install_date}.not_to raise_error
|
266
|
+
expect(described_class.uname.install_date).to be_kind_of(Time)
|
267
|
+
end
|
268
|
+
|
269
|
+
example "last_bootup_time" do
|
270
|
+
expect{ described_class.uname.last_bootup_time}.not_to raise_error
|
271
|
+
expect(described_class.uname.last_bootup_time).to be_kind_of(Time)
|
272
|
+
end
|
273
|
+
|
274
|
+
example "local_date_time" do
|
275
|
+
expect{ described_class.uname.local_date_time}.not_to raise_error
|
276
|
+
expect(described_class.uname.local_date_time).to be_kind_of(Time)
|
277
|
+
end
|
278
|
+
|
279
|
+
example "locale" do
|
280
|
+
expect{ described_class.uname.locale}.not_to raise_error
|
281
|
+
expect(described_class.uname.locale).to be_kind_of(String)
|
282
|
+
end
|
283
|
+
|
284
|
+
example "manufacturer" do
|
285
|
+
expect{ described_class.uname.manufacturer}.not_to raise_error
|
286
|
+
expect(described_class.uname.manufacturer).to be_kind_of(String)
|
287
|
+
end
|
288
|
+
|
289
|
+
example "max_number_of_processes" do
|
290
|
+
expect{ described_class.uname.max_number_of_processes}.not_to raise_error
|
291
|
+
expect(described_class.uname.max_number_of_processes).to be_kind_of(Integer)
|
292
|
+
end
|
293
|
+
|
294
|
+
example "max_process_memory_size" do
|
295
|
+
expect{ described_class.uname.max_process_memory_size}.not_to raise_error
|
296
|
+
expect(described_class.uname.max_process_memory_size).to be_kind_of(Integer)
|
297
|
+
end
|
298
|
+
|
299
|
+
example "name" do
|
300
|
+
expect{ described_class.uname.name }.not_to raise_error
|
301
|
+
expect(described_class.uname.name).to be_kind_of(String)
|
302
|
+
end
|
303
|
+
|
304
|
+
example "number_of_licensed_users" do
|
305
|
+
expect{ described_class.uname.number_of_licensed_users }.not_to raise_error
|
306
|
+
expect(described_class.uname.number_of_licensed_users).to be_kind_of(Integer).or be_nil
|
307
|
+
end
|
308
|
+
|
309
|
+
example "number_of_processes" do
|
310
|
+
expect{ described_class.uname.number_of_processes }.not_to raise_error
|
311
|
+
expect(described_class.uname.number_of_processes).to be_kind_of(Integer)
|
312
|
+
end
|
313
|
+
|
314
|
+
example "number_of_users" do
|
315
|
+
expect{ described_class.uname.number_of_users }.not_to raise_error
|
316
|
+
expect(described_class.uname.number_of_users).to be_kind_of(Integer)
|
317
|
+
end
|
318
|
+
|
319
|
+
example "organization" do
|
320
|
+
expect{ described_class.uname.organization }.not_to raise_error
|
321
|
+
expect(described_class.uname.organization).to be_kind_of(String)
|
322
|
+
end
|
323
|
+
|
324
|
+
example "os_language" do
|
325
|
+
expect{ described_class.uname.os_language }.not_to raise_error
|
326
|
+
expect(described_class.uname.os_language).to be_kind_of(Integer)
|
327
|
+
end
|
328
|
+
|
329
|
+
example "os_product_suite" do
|
330
|
+
expect{ described_class.uname.os_product_suite }.not_to raise_error
|
331
|
+
expect(described_class.uname.os_product_suite).to be_kind_of(Integer)
|
332
|
+
end
|
333
|
+
|
334
|
+
example "os_type" do
|
335
|
+
expect{ described_class.uname.os_type }.not_to raise_error
|
336
|
+
expect(described_class.uname.os_type).to be_kind_of(Integer)
|
337
|
+
end
|
338
|
+
|
339
|
+
example "other_type_description" do
|
340
|
+
expect{ described_class.uname.other_type_description}.not_to raise_error
|
341
|
+
expect(described_class.uname.other_type_description).to be_kind_of(String).or be_nil
|
342
|
+
end
|
343
|
+
|
344
|
+
example "plus_product_id" do
|
345
|
+
expect{ described_class.uname.plus_product_id }.not_to raise_error
|
346
|
+
expect(described_class.uname.plus_product_id).to be_kind_of(Integer).or be_nil
|
347
|
+
end
|
348
|
+
|
349
|
+
example "plus_version_number" do
|
350
|
+
expect{ described_class.uname.plus_version_number }.not_to raise_error
|
351
|
+
expect(described_class.uname.plus_version_number).to be_kind_of(Integer).or be_nil
|
352
|
+
end
|
353
|
+
|
354
|
+
example "primary" do
|
355
|
+
expect{ described_class.uname.primary }.not_to raise_error
|
356
|
+
expect(described_class.uname.primary).to eql(true).or eql(false)
|
357
|
+
end
|
358
|
+
|
359
|
+
example "product_type" do
|
360
|
+
expect{ described_class.uname.product_type }.not_to raise_error
|
361
|
+
expect(described_class.uname.product_type).to be_kind_of(Integer)
|
362
|
+
end
|
363
|
+
|
364
|
+
example "quantum_length" do
|
365
|
+
expect{ described_class.uname.quantum_length }.not_to raise_error
|
366
|
+
expect(described_class.uname.quantum_length).to be_kind_of(Integer).or be_nil
|
367
|
+
end
|
368
|
+
|
369
|
+
example "quantum_type" do
|
370
|
+
expect{ described_class.uname.quantum_type }.not_to raise_error
|
371
|
+
expect(described_class.uname.quantum_type).to be_kind_of(Integer).or be_nil
|
372
|
+
end
|
373
|
+
|
374
|
+
example "registered_user" do
|
375
|
+
expect{ described_class.uname.registered_user }.not_to raise_error
|
376
|
+
expect(described_class.uname.registered_user).to be_kind_of(String)
|
377
|
+
end
|
378
|
+
|
379
|
+
example "serial_number" do
|
380
|
+
expect{ described_class.uname.serial_number }.not_to raise_error
|
381
|
+
expect(described_class.uname.serial_number).to be_kind_of(String)
|
382
|
+
end
|
383
|
+
|
384
|
+
example "service_pack_major_version" do
|
385
|
+
expect{ described_class.uname.service_pack_major_version }.not_to raise_error
|
386
|
+
expect(described_class.uname.service_pack_major_version).to be_kind_of(Integer)
|
387
|
+
end
|
388
|
+
|
389
|
+
example "service_pack_minor_version" do
|
390
|
+
expect{ described_class.uname.service_pack_minor_version }.not_to raise_error
|
391
|
+
expect(described_class.uname.service_pack_minor_version).to be_kind_of(Integer)
|
392
|
+
end
|
393
|
+
|
394
|
+
example "status" do
|
395
|
+
expect{ described_class.uname.status }.not_to raise_error
|
396
|
+
expect(described_class.uname.status).to be_kind_of(String)
|
397
|
+
end
|
398
|
+
|
399
|
+
example "suite_mask" do
|
400
|
+
expect{ described_class.uname.suite_mask }.not_to raise_error
|
401
|
+
expect(described_class.uname.suite_mask).to be_kind_of(Integer)
|
402
|
+
end
|
403
|
+
|
404
|
+
example "system_device" do
|
405
|
+
expect{ described_class.uname.system_device }.not_to raise_error
|
406
|
+
expect(described_class.uname.system_device).to be_kind_of(String)
|
407
|
+
end
|
408
|
+
|
409
|
+
example "system_directory" do
|
410
|
+
expect{ described_class.uname.system_directory }.not_to raise_error
|
411
|
+
expect(described_class.uname.system_directory).to be_kind_of(String)
|
412
|
+
end
|
413
|
+
|
414
|
+
example "system_drive" do
|
415
|
+
expect{ described_class.uname.system_drive }.not_to raise_error
|
416
|
+
expect(described_class.uname.system_drive).to be_kind_of(String)
|
417
|
+
expect(described_class.uname.system_drive).to eql("C:")
|
418
|
+
end
|
419
|
+
|
420
|
+
example "total_swap_space_size" do
|
421
|
+
expect{ described_class.uname.total_swap_space_size }.not_to raise_error
|
422
|
+
expect(described_class.uname.total_swap_space_size).to be_kind_of(Integer).or be_nil
|
423
|
+
end
|
424
|
+
|
425
|
+
example "total_virtual_memory_size" do
|
426
|
+
expect{ described_class.uname.total_virtual_memory_size }.not_to raise_error
|
427
|
+
expect(described_class.uname.total_virtual_memory_size).to be_kind_of(Integer)
|
428
|
+
end
|
429
|
+
|
430
|
+
example "total_visible_memory_size" do
|
431
|
+
expect{ described_class.uname.total_visible_memory_size }.not_to raise_error
|
432
|
+
expect(described_class.uname.total_visible_memory_size).to be_kind_of(Integer)
|
433
|
+
end
|
434
|
+
|
435
|
+
example "version" do
|
436
|
+
expect{ described_class.uname.version }.not_to raise_error
|
437
|
+
expect(described_class.uname.version).to be_kind_of(String)
|
438
|
+
end
|
439
|
+
|
440
|
+
example "windows_directory" do
|
441
|
+
expect{ described_class.uname.windows_directory }.not_to raise_error
|
442
|
+
expect(described_class.uname.windows_directory).to be_kind_of(String)
|
443
|
+
end
|
444
|
+
end
|
445
|
+
end
|