sys-filesystem 0.3.4-x86-mingw32 → 1.0.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +49 -45
- data/MANIFEST +12 -13
- data/README +83 -83
- data/Rakefile +49 -83
- data/examples/example_stat.rb +24 -24
- data/lib/sys/filesystem.rb +5 -408
- data/lib/unix/sys/filesystem.rb +561 -0
- data/lib/windows/sys/filesystem.rb +408 -0
- data/sys-filesystem.gemspec +24 -25
- data/test/test_sys_filesystem.rb +7 -9
- data/test/test_sys_filesystem_unix.rb +261 -253
- data/test/test_sys_filesystem_windows.rb +198 -198
- metadata +41 -66
@@ -1,253 +1,261 @@
|
|
1
|
-
####################################################################
|
2
|
-
# test_sys_filesystem_unix.rb
|
3
|
-
#
|
4
|
-
# Test case for the Sys::Filesystem.stat method and related stuff.
|
5
|
-
# This test suite should be run via the 'rake test' task.
|
6
|
-
####################################################################
|
7
|
-
require 'rubygems'
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
11
|
-
require 'sys/filesystem'
|
12
|
-
include Sys
|
13
|
-
|
14
|
-
class TC_Sys_Filesystem_Unix < Test::Unit::TestCase
|
15
|
-
def self.startup
|
16
|
-
@@solaris =
|
17
|
-
@@linux =
|
18
|
-
@@freebsd =
|
19
|
-
@@darwin =
|
20
|
-
end
|
21
|
-
|
22
|
-
def setup
|
23
|
-
@dir = "/"
|
24
|
-
@stat = Filesystem.stat(@dir)
|
25
|
-
@mnt = Filesystem.mounts[0]
|
26
|
-
@size = 58720256
|
27
|
-
@array = []
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_version
|
31
|
-
assert_equal('0.
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_stat_path
|
35
|
-
assert_respond_to(@stat, :path)
|
36
|
-
assert_equal("/", @stat.path)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_stat_block_size
|
40
|
-
assert_respond_to(@stat, :block_size)
|
41
|
-
assert_kind_of(Fixnum, @stat.block_size)
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_block_size_is_a_plausible_value
|
45
|
-
assert_true(@stat.block_size >= 1024)
|
46
|
-
assert_true(@stat.block_size <= 16384)
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_stat_fragment_size
|
50
|
-
assert_respond_to(@stat, :fragment_size)
|
51
|
-
assert_kind_of(Fixnum, @stat.fragment_size)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_stat_blocks
|
55
|
-
assert_respond_to(@stat, :blocks)
|
56
|
-
assert_kind_of(Fixnum, @stat.blocks)
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_stat_blocks_free
|
60
|
-
assert_respond_to(@stat, :blocks_free)
|
61
|
-
assert_kind_of(Fixnum, @stat.blocks_free)
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_stat_blocks_available
|
65
|
-
assert_respond_to(@stat, :blocks_available)
|
66
|
-
assert_kind_of(Fixnum, @stat.blocks_available)
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_stat_files
|
70
|
-
assert_respond_to(@stat, :files)
|
71
|
-
assert_kind_of(Fixnum, @stat.files)
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_inodes_alias
|
75
|
-
assert_respond_to(@stat, :inodes)
|
76
|
-
assert_true(@stat.method(:inodes) == @stat.method(:files))
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_stat_files_free
|
80
|
-
assert_respond_to(@stat, :files_free)
|
81
|
-
assert_kind_of(Fixnum, @stat.files_free)
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_stat_inodes_free_alias
|
85
|
-
assert_respond_to(@stat, :inodes_free)
|
86
|
-
assert_true(@stat.method(:inodes_free) == @stat.method(:files_free))
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_stat_files_available
|
90
|
-
assert_respond_to(@stat, :files_available)
|
91
|
-
assert_kind_of(Fixnum, @stat.files_available)
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_stat_inodes_available_alias
|
95
|
-
assert_respond_to(@stat, :inodes_available)
|
96
|
-
assert_true(@stat.method(:inodes_available) == @stat.method(:files_available))
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_stat_filesystem_id
|
100
|
-
assert_respond_to(@stat, :filesystem_id)
|
101
|
-
assert_kind_of(Integer, @stat.filesystem_id)
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_stat_flags
|
105
|
-
assert_respond_to(@stat, :flags)
|
106
|
-
assert_kind_of(Fixnum, @stat.flags)
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_stat_name_max
|
110
|
-
assert_respond_to(@stat, :name_max)
|
111
|
-
assert_kind_of(Fixnum, @stat.name_max)
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_stat_base_type
|
115
|
-
omit_unless(@@solaris, "base_type test skipped except on Solaris")
|
116
|
-
|
117
|
-
assert_respond_to(@stat, :base_type)
|
118
|
-
assert_kind_of(String, @stat.base_type)
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_stat_constants
|
122
|
-
assert_not_nil(Filesystem::Stat::RDONLY)
|
123
|
-
assert_not_nil(Filesystem::Stat::NOSUID)
|
124
|
-
|
125
|
-
omit_unless(@@solaris, "NOTRUNC test skipped except on Solaris")
|
126
|
-
|
127
|
-
assert_not_nil(Filesystem::Stat::NOTRUNC)
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_stat_expected_errors
|
131
|
-
assert_raises(ArgumentError){ Filesystem.stat }
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_fixnum_methods_basic
|
135
|
-
assert_respond_to(@size, :to_kb)
|
136
|
-
assert_respond_to(@size, :to_mb)
|
137
|
-
assert_respond_to(@size, :to_gb)
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_to_kb
|
141
|
-
assert_equal(57344, @size.to_kb)
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_to_mb
|
145
|
-
assert_equal(56, @size.to_mb)
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_to_gb
|
149
|
-
assert_equal(0, @size.to_gb)
|
150
|
-
end
|
151
|
-
|
152
|
-
# Filesystem::Mount tests
|
153
|
-
|
154
|
-
def test_mounts_with_no_block
|
155
|
-
assert_nothing_raised{ @array = Filesystem.mounts }
|
156
|
-
assert_kind_of(Filesystem::Mount, @array[0])
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_mounts_with_block
|
160
|
-
assert_nothing_raised{ Filesystem.mounts{ |m| @array << m } }
|
161
|
-
assert_kind_of(Filesystem::Mount, @array[0])
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_mounts_high_iteration
|
165
|
-
assert_nothing_raised{ 1000.times{ @array = Filesystem.mounts } }
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_mount_name
|
169
|
-
assert_respond_to(@mnt, :name)
|
170
|
-
assert_kind_of(String, @mnt.name)
|
171
|
-
end
|
172
|
-
|
173
|
-
def test_fsname_alias
|
174
|
-
assert_respond_to(@mnt, :fsname)
|
175
|
-
assert_true(@mnt.method(:fsname) == @mnt.method(:name))
|
176
|
-
end
|
177
|
-
|
178
|
-
def test_mount_point
|
179
|
-
assert_respond_to(@mnt, :mount_point)
|
180
|
-
assert_kind_of(String, @mnt.mount_point)
|
181
|
-
end
|
182
|
-
|
183
|
-
def test_dir_alias
|
184
|
-
assert_respond_to(@mnt, :dir)
|
185
|
-
assert_true(@mnt.method(:dir) == @mnt.method(:mount_point))
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_mount_type
|
189
|
-
assert_respond_to(@mnt, :mount_type)
|
190
|
-
assert_kind_of(String, @mnt.mount_type)
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_mount_options
|
194
|
-
assert_respond_to(@mnt, :options)
|
195
|
-
assert_kind_of(String, @mnt.options)
|
196
|
-
end
|
197
|
-
|
198
|
-
def test_opts_alias
|
199
|
-
assert_respond_to(@mnt, :opts)
|
200
|
-
assert_true(@mnt.method(:opts) == @mnt.method(:options))
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_mount_time
|
204
|
-
assert_respond_to(@mnt, :mount_time)
|
205
|
-
|
206
|
-
if @@solaris
|
207
|
-
assert_kind_of(Time, @mnt.mount_time)
|
208
|
-
else
|
209
|
-
assert_nil(@mnt.mount_time)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_mount_dump_frequency
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
end
|
1
|
+
####################################################################
|
2
|
+
# test_sys_filesystem_unix.rb
|
3
|
+
#
|
4
|
+
# Test case for the Sys::Filesystem.stat method and related stuff.
|
5
|
+
# This test suite should be run via the 'rake test' task.
|
6
|
+
####################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'sys/filesystem'
|
12
|
+
include Sys
|
13
|
+
|
14
|
+
class TC_Sys_Filesystem_Unix < Test::Unit::TestCase
|
15
|
+
def self.startup
|
16
|
+
@@solaris = RbConfig::CONFIG['host_os'] =~ /solaris/i
|
17
|
+
@@linux = RbConfig::CONFIG['host_os'] =~ /linux/i
|
18
|
+
@@freebsd = RbConfig::CONFIG['host_os'] =~ /freebsd/i
|
19
|
+
@@darwin = RbConfig::CONFIG['host_os'] =~ /darwin/i
|
20
|
+
end
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@dir = "/"
|
24
|
+
@stat = Filesystem.stat(@dir)
|
25
|
+
@mnt = Filesystem.mounts[0]
|
26
|
+
@size = 58720256
|
27
|
+
@array = []
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_version
|
31
|
+
assert_equal('1.0.0', Filesystem::VERSION)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_stat_path
|
35
|
+
assert_respond_to(@stat, :path)
|
36
|
+
assert_equal("/", @stat.path)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_stat_block_size
|
40
|
+
assert_respond_to(@stat, :block_size)
|
41
|
+
assert_kind_of(Fixnum, @stat.block_size)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_block_size_is_a_plausible_value
|
45
|
+
assert_true(@stat.block_size >= 1024)
|
46
|
+
assert_true(@stat.block_size <= 16384)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_stat_fragment_size
|
50
|
+
assert_respond_to(@stat, :fragment_size)
|
51
|
+
assert_kind_of(Fixnum, @stat.fragment_size)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_stat_blocks
|
55
|
+
assert_respond_to(@stat, :blocks)
|
56
|
+
assert_kind_of(Fixnum, @stat.blocks)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_stat_blocks_free
|
60
|
+
assert_respond_to(@stat, :blocks_free)
|
61
|
+
assert_kind_of(Fixnum, @stat.blocks_free)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_stat_blocks_available
|
65
|
+
assert_respond_to(@stat, :blocks_available)
|
66
|
+
assert_kind_of(Fixnum, @stat.blocks_available)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_stat_files
|
70
|
+
assert_respond_to(@stat, :files)
|
71
|
+
assert_kind_of(Fixnum, @stat.files)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_inodes_alias
|
75
|
+
assert_respond_to(@stat, :inodes)
|
76
|
+
assert_true(@stat.method(:inodes) == @stat.method(:files))
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_stat_files_free
|
80
|
+
assert_respond_to(@stat, :files_free)
|
81
|
+
assert_kind_of(Fixnum, @stat.files_free)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_stat_inodes_free_alias
|
85
|
+
assert_respond_to(@stat, :inodes_free)
|
86
|
+
assert_true(@stat.method(:inodes_free) == @stat.method(:files_free))
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_stat_files_available
|
90
|
+
assert_respond_to(@stat, :files_available)
|
91
|
+
assert_kind_of(Fixnum, @stat.files_available)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_stat_inodes_available_alias
|
95
|
+
assert_respond_to(@stat, :inodes_available)
|
96
|
+
assert_true(@stat.method(:inodes_available) == @stat.method(:files_available))
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_stat_filesystem_id
|
100
|
+
assert_respond_to(@stat, :filesystem_id)
|
101
|
+
assert_kind_of(Integer, @stat.filesystem_id)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_stat_flags
|
105
|
+
assert_respond_to(@stat, :flags)
|
106
|
+
assert_kind_of(Fixnum, @stat.flags)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_stat_name_max
|
110
|
+
assert_respond_to(@stat, :name_max)
|
111
|
+
assert_kind_of(Fixnum, @stat.name_max)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_stat_base_type
|
115
|
+
omit_unless(@@solaris, "base_type test skipped except on Solaris")
|
116
|
+
|
117
|
+
assert_respond_to(@stat, :base_type)
|
118
|
+
assert_kind_of(String, @stat.base_type)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_stat_constants
|
122
|
+
assert_not_nil(Filesystem::Stat::RDONLY)
|
123
|
+
assert_not_nil(Filesystem::Stat::NOSUID)
|
124
|
+
|
125
|
+
omit_unless(@@solaris, "NOTRUNC test skipped except on Solaris")
|
126
|
+
|
127
|
+
assert_not_nil(Filesystem::Stat::NOTRUNC)
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_stat_expected_errors
|
131
|
+
assert_raises(ArgumentError){ Filesystem.stat }
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_fixnum_methods_basic
|
135
|
+
assert_respond_to(@size, :to_kb)
|
136
|
+
assert_respond_to(@size, :to_mb)
|
137
|
+
assert_respond_to(@size, :to_gb)
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_to_kb
|
141
|
+
assert_equal(57344, @size.to_kb)
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_to_mb
|
145
|
+
assert_equal(56, @size.to_mb)
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_to_gb
|
149
|
+
assert_equal(0, @size.to_gb)
|
150
|
+
end
|
151
|
+
|
152
|
+
# Filesystem::Mount tests
|
153
|
+
|
154
|
+
def test_mounts_with_no_block
|
155
|
+
assert_nothing_raised{ @array = Filesystem.mounts }
|
156
|
+
assert_kind_of(Filesystem::Mount, @array[0])
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_mounts_with_block
|
160
|
+
assert_nothing_raised{ Filesystem.mounts{ |m| @array << m } }
|
161
|
+
assert_kind_of(Filesystem::Mount, @array[0])
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_mounts_high_iteration
|
165
|
+
assert_nothing_raised{ 1000.times{ @array = Filesystem.mounts } }
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_mount_name
|
169
|
+
assert_respond_to(@mnt, :name)
|
170
|
+
assert_kind_of(String, @mnt.name)
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_fsname_alias
|
174
|
+
assert_respond_to(@mnt, :fsname)
|
175
|
+
assert_true(@mnt.method(:fsname) == @mnt.method(:name))
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_mount_point
|
179
|
+
assert_respond_to(@mnt, :mount_point)
|
180
|
+
assert_kind_of(String, @mnt.mount_point)
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_dir_alias
|
184
|
+
assert_respond_to(@mnt, :dir)
|
185
|
+
assert_true(@mnt.method(:dir) == @mnt.method(:mount_point))
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_mount_type
|
189
|
+
assert_respond_to(@mnt, :mount_type)
|
190
|
+
assert_kind_of(String, @mnt.mount_type)
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_mount_options
|
194
|
+
assert_respond_to(@mnt, :options)
|
195
|
+
assert_kind_of(String, @mnt.options)
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_opts_alias
|
199
|
+
assert_respond_to(@mnt, :opts)
|
200
|
+
assert_true(@mnt.method(:opts) == @mnt.method(:options))
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_mount_time
|
204
|
+
assert_respond_to(@mnt, :mount_time)
|
205
|
+
|
206
|
+
if @@solaris
|
207
|
+
assert_kind_of(Time, @mnt.mount_time)
|
208
|
+
else
|
209
|
+
assert_nil(@mnt.mount_time)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_mount_dump_frequency
|
214
|
+
msg = 'dump_frequency test skipped on this platform'
|
215
|
+
omit_if(@@solaris || @@freebsd || @@darwin, msg)
|
216
|
+
assert_respond_to(@mnt, :dump_frequency)
|
217
|
+
assert_kind_of(Fixnum, @mnt.dump_frequency)
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_freq_alias
|
221
|
+
assert_respond_to(@mnt, :freq)
|
222
|
+
assert_true(@mnt.method(:freq) == @mnt.method(:dump_frequency))
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_mount_pass_number
|
226
|
+
msg = 'pass_number test skipped on this platform'
|
227
|
+
omit_if(@@solaris || @@freebsd || @@darwin, msg)
|
228
|
+
assert_respond_to(@mnt, :pass_number)
|
229
|
+
assert_kind_of(Fixnum, @mnt.pass_number)
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_passno_alias
|
233
|
+
assert_respond_to(@mnt, :passno)
|
234
|
+
assert_true(@mnt.method(:passno) == @mnt.method(:pass_number))
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_mount_point_singleton
|
238
|
+
assert_respond_to(Filesystem, :mount_point)
|
239
|
+
assert_nothing_raised{ Filesystem.mount_point(Dir.pwd) }
|
240
|
+
assert_kind_of(String, Filesystem.mount_point(Dir.pwd))
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_ffi_functions_are_private
|
244
|
+
methods = Filesystem.methods(false).map{ |e| e.to_s }
|
245
|
+
assert_false(Filesystem.methods.include?('statvfs'))
|
246
|
+
assert_false(Filesystem.methods.include?('strerror'))
|
247
|
+
end
|
248
|
+
|
249
|
+
def teardown
|
250
|
+
@dir = nil
|
251
|
+
@stat = nil
|
252
|
+
@array = nil
|
253
|
+
end
|
254
|
+
|
255
|
+
def self.shutdown
|
256
|
+
@@solaris = nil
|
257
|
+
@@linux = nil
|
258
|
+
@@freebsd = nil
|
259
|
+
@@darwin = nil
|
260
|
+
end
|
261
|
+
end
|