ptools 1.2.2-universal-mingw32 → 1.2.3-universal-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES +126 -121
- data/MANIFEST +17 -17
- data/README +65 -65
- data/Rakefile +135 -130
- data/lib/ptools.rb +429 -429
- data/ptools.gemspec +30 -30
- data/test/test_binary.rb +47 -47
- data/test/test_constants.rb +38 -38
- data/test/test_head.rb +51 -51
- data/test/test_image.rb +43 -43
- data/test/test_is_sparse.rb +52 -52
- data/test/test_middle.rb +61 -61
- data/test/test_nlconvert.rb +99 -99
- data/test/test_null.rb +40 -40
- data/test/test_tail.rb +56 -56
- data/test/test_touch.rb +55 -55
- data/test/test_wc.rb +76 -76
- data/test/test_whereis.rb +98 -98
- data/test/test_which.rb +113 -113
- metadata +57 -76
data/ptools.gemspec
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rbconfig'
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.name = 'ptools'
|
6
|
-
gem.version = '1.2.
|
7
|
-
gem.license = 'Artistic 2.0'
|
8
|
-
gem.author = 'Daniel J. Berger'
|
9
|
-
gem.email = 'djberg96@gmail.com'
|
10
|
-
gem.homepage = '
|
11
|
-
gem.summary = 'Extra methods for the File class'
|
12
|
-
gem.test_files = Dir['test/test*']
|
13
|
-
gem.files = Dir['**/*'] << '.gemtest'
|
14
|
-
|
15
|
-
gem.rubyforge_project = 'shards'
|
16
|
-
gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
|
17
|
-
|
18
|
-
gem.description = <<-EOF
|
19
|
-
The ptools (power tools) library provides several handy methods to
|
20
|
-
Ruby's core File class, such as File.which for finding executables,
|
21
|
-
File.null to return the null device on your platform, and so on.
|
22
|
-
EOF
|
23
|
-
|
24
|
-
gem.add_development_dependency('test-unit', '>= 2.
|
25
|
-
|
26
|
-
if File::ALT_SEPARATOR
|
27
|
-
gem.platform = Gem::Platform.new(['universal', 'mingw32'])
|
28
|
-
gem.add_dependency('win32-file', '>= 0.
|
29
|
-
end
|
30
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rbconfig'
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'ptools'
|
6
|
+
gem.version = '1.2.3'
|
7
|
+
gem.license = 'Artistic 2.0'
|
8
|
+
gem.author = 'Daniel J. Berger'
|
9
|
+
gem.email = 'djberg96@gmail.com'
|
10
|
+
gem.homepage = 'https://github.com/djberg96/ptools'
|
11
|
+
gem.summary = 'Extra methods for the File class'
|
12
|
+
gem.test_files = Dir['test/test*']
|
13
|
+
gem.files = Dir['**/*'] << '.gemtest'
|
14
|
+
|
15
|
+
gem.rubyforge_project = 'shards'
|
16
|
+
gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
|
17
|
+
|
18
|
+
gem.description = <<-EOF
|
19
|
+
The ptools (power tools) library provides several handy methods to
|
20
|
+
Ruby's core File class, such as File.which for finding executables,
|
21
|
+
File.null to return the null device on your platform, and so on.
|
22
|
+
EOF
|
23
|
+
|
24
|
+
gem.add_development_dependency('test-unit', '>= 2.5.0')
|
25
|
+
|
26
|
+
if File::ALT_SEPARATOR
|
27
|
+
gem.platform = Gem::Platform.new(['universal', 'mingw32'])
|
28
|
+
gem.add_dependency('win32-file', '>= 0.7.0')
|
29
|
+
end
|
30
|
+
end
|
data/test/test_binary.rb
CHANGED
@@ -1,47 +1,47 @@
|
|
1
|
-
#####################################################################
|
2
|
-
# test_binary.rb
|
3
|
-
#
|
4
|
-
# Test case for the File.binary? method. You should run this test
|
5
|
-
# via the 'rake test_binary' task.
|
6
|
-
#####################################################################
|
7
|
-
require 'rubygems'
|
8
|
-
require 'test-unit'
|
9
|
-
require 'ptools'
|
10
|
-
|
11
|
-
class TC_Ptools_Binary < Test::Unit::TestCase
|
12
|
-
def self.startup
|
13
|
-
@@txt_file = 'test_binary.txt'
|
14
|
-
|
15
|
-
if File::ALT_SEPARATOR
|
16
|
-
@@bin_file = File.join(ENV['windir'], 'notepad.exe')
|
17
|
-
else
|
18
|
-
@@bin_file = '/bin/ls'
|
19
|
-
end
|
20
|
-
|
21
|
-
Dir.chdir('test') if File.exists?('test')
|
22
|
-
|
23
|
-
File.open(@@txt_file, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
|
24
|
-
end
|
25
|
-
|
26
|
-
test "File.binary? basic functionality" do
|
27
|
-
assert_respond_to(File, :binary?)
|
28
|
-
assert_nothing_raised{ File.binary?(@@txt_file) }
|
29
|
-
end
|
30
|
-
|
31
|
-
test "File.binary? returns expected results" do
|
32
|
-
assert_false(File.binary?(@@txt_file))
|
33
|
-
assert_true(File.binary?(@@bin_file))
|
34
|
-
end
|
35
|
-
|
36
|
-
test "File.binary? raises an error if the file cannot be found" do
|
37
|
-
assert_raise_kind_of(SystemCallError){ File.binary?('bogus') }
|
38
|
-
end
|
39
|
-
|
40
|
-
test "File.binary? only accepts one argument" do
|
41
|
-
assert_raise_kind_of(ArgumentError){ File.binary?(@@txt_file, @@bin_file) }
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.shutdown
|
45
|
-
File.delete(@@txt_file) if File.exists?(@@txt_file)
|
46
|
-
end
|
47
|
-
end
|
1
|
+
#####################################################################
|
2
|
+
# test_binary.rb
|
3
|
+
#
|
4
|
+
# Test case for the File.binary? method. You should run this test
|
5
|
+
# via the 'rake test_binary' task.
|
6
|
+
#####################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
require 'test-unit'
|
9
|
+
require 'ptools'
|
10
|
+
|
11
|
+
class TC_Ptools_Binary < Test::Unit::TestCase
|
12
|
+
def self.startup
|
13
|
+
@@txt_file = 'test_binary.txt'
|
14
|
+
|
15
|
+
if File::ALT_SEPARATOR
|
16
|
+
@@bin_file = File.join(ENV['windir'], 'notepad.exe')
|
17
|
+
else
|
18
|
+
@@bin_file = '/bin/ls'
|
19
|
+
end
|
20
|
+
|
21
|
+
Dir.chdir('test') if File.exists?('test')
|
22
|
+
|
23
|
+
File.open(@@txt_file, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
|
24
|
+
end
|
25
|
+
|
26
|
+
test "File.binary? basic functionality" do
|
27
|
+
assert_respond_to(File, :binary?)
|
28
|
+
assert_nothing_raised{ File.binary?(@@txt_file) }
|
29
|
+
end
|
30
|
+
|
31
|
+
test "File.binary? returns expected results" do
|
32
|
+
assert_false(File.binary?(@@txt_file))
|
33
|
+
assert_true(File.binary?(@@bin_file))
|
34
|
+
end
|
35
|
+
|
36
|
+
test "File.binary? raises an error if the file cannot be found" do
|
37
|
+
assert_raise_kind_of(SystemCallError){ File.binary?('bogus') }
|
38
|
+
end
|
39
|
+
|
40
|
+
test "File.binary? only accepts one argument" do
|
41
|
+
assert_raise_kind_of(ArgumentError){ File.binary?(@@txt_file, @@bin_file) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.shutdown
|
45
|
+
File.delete(@@txt_file) if File.exists?(@@txt_file)
|
46
|
+
end
|
47
|
+
end
|
data/test/test_constants.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
#####################################################################
|
2
|
-
# test_constants.rb
|
3
|
-
#
|
4
|
-
# Tests the constants that have been defined for our package. This
|
5
|
-
# test case should be run via the 'rake test_constants' task.
|
6
|
-
#####################################################################
|
7
|
-
require 'rubygems'
|
8
|
-
require 'test-unit'
|
9
|
-
require 'rbconfig'
|
10
|
-
require 'ptools'
|
11
|
-
|
12
|
-
class TC_Ptools_Constants < Test::Unit::TestCase
|
13
|
-
def self.startup
|
14
|
-
@@windows = File::ALT_SEPARATOR
|
15
|
-
end
|
16
|
-
|
17
|
-
test "PTOOLS_VERSION constant is set to expected value" do
|
18
|
-
assert_equal('1.2.
|
19
|
-
end
|
20
|
-
|
21
|
-
test "IMAGE_EXT constant is set to array of values" do
|
22
|
-
assert_equal(%w[.bmp .gif .jpeg .jpg .png], File::IMAGE_EXT.sort)
|
23
|
-
end
|
24
|
-
|
25
|
-
test "WINDOWS constant is defined on MS Windows" do
|
26
|
-
omit_unless(@@windows, "Skipping on Unix systems")
|
27
|
-
assert_not_nil(File::MSWINDOWS)
|
28
|
-
end
|
29
|
-
|
30
|
-
test "WIN32EXTS constant is defiend on MS Windows" do
|
31
|
-
omit_unless(@@windows, "Skipping on Unix systems")
|
32
|
-
assert_not_nil(File::WIN32EXTS)
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.shutdown
|
36
|
-
@@windows = nil
|
37
|
-
end
|
38
|
-
end
|
1
|
+
#####################################################################
|
2
|
+
# test_constants.rb
|
3
|
+
#
|
4
|
+
# Tests the constants that have been defined for our package. This
|
5
|
+
# test case should be run via the 'rake test_constants' task.
|
6
|
+
#####################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
require 'test-unit'
|
9
|
+
require 'rbconfig'
|
10
|
+
require 'ptools'
|
11
|
+
|
12
|
+
class TC_Ptools_Constants < Test::Unit::TestCase
|
13
|
+
def self.startup
|
14
|
+
@@windows = File::ALT_SEPARATOR
|
15
|
+
end
|
16
|
+
|
17
|
+
test "PTOOLS_VERSION constant is set to expected value" do
|
18
|
+
assert_equal('1.2.3', File::PTOOLS_VERSION)
|
19
|
+
end
|
20
|
+
|
21
|
+
test "IMAGE_EXT constant is set to array of values" do
|
22
|
+
assert_equal(%w[.bmp .gif .jpeg .jpg .png], File::IMAGE_EXT.sort)
|
23
|
+
end
|
24
|
+
|
25
|
+
test "WINDOWS constant is defined on MS Windows" do
|
26
|
+
omit_unless(@@windows, "Skipping on Unix systems")
|
27
|
+
assert_not_nil(File::MSWINDOWS)
|
28
|
+
end
|
29
|
+
|
30
|
+
test "WIN32EXTS constant is defiend on MS Windows" do
|
31
|
+
omit_unless(@@windows, "Skipping on Unix systems")
|
32
|
+
assert_not_nil(File::WIN32EXTS)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.shutdown
|
36
|
+
@@windows = nil
|
37
|
+
end
|
38
|
+
end
|
data/test/test_head.rb
CHANGED
@@ -1,51 +1,51 @@
|
|
1
|
-
######################################################################
|
2
|
-
# test_head.rb
|
3
|
-
#
|
4
|
-
# Test case for the File.head method. This test should be run via
|
5
|
-
# the 'rake test_head' task.
|
6
|
-
######################################################################
|
7
|
-
require 'rubygems'
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
11
|
-
require 'ptools'
|
12
|
-
|
13
|
-
class TC_FileHead < Test::Unit::TestCase
|
14
|
-
def self.startup
|
15
|
-
Dir.chdir('test') if File.exists?('test')
|
16
|
-
File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
|
17
|
-
end
|
18
|
-
|
19
|
-
def setup
|
20
|
-
@test_file = 'test_file1.txt'
|
21
|
-
@expected_head1 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
|
22
|
-
@expected_head1.push("line6\n","line7\n","line8\n","line9\n","line10\n")
|
23
|
-
@expected_head2 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_head_basic
|
27
|
-
assert_respond_to(File, :head)
|
28
|
-
assert_nothing_raised{ File.head(@test_file) }
|
29
|
-
assert_nothing_raised{ File.head(@test_file, 5) }
|
30
|
-
assert_nothing_raised{ File.head(@test_file){} }
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_head_expected_results
|
34
|
-
assert_kind_of(Array, File.head(@test_file))
|
35
|
-
assert_equal(@expected_head1, File.head(@test_file))
|
36
|
-
assert_equal(@expected_head2, File.head(@test_file, 5))
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_head_expected_errors
|
40
|
-
assert_raises(ArgumentError){ File.head(@test_file, 5, "foo") }
|
41
|
-
assert_raises(Errno::ENOENT){ File.head("bogus") }
|
42
|
-
end
|
43
|
-
|
44
|
-
def teardown
|
45
|
-
@test_file = nil
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.shutdown
|
49
|
-
File.delete('test_file1.txt') if File.exists?('test_file1.txt')
|
50
|
-
end
|
51
|
-
end
|
1
|
+
######################################################################
|
2
|
+
# test_head.rb
|
3
|
+
#
|
4
|
+
# Test case for the File.head method. This test should be run via
|
5
|
+
# the 'rake test_head' task.
|
6
|
+
######################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'ptools'
|
12
|
+
|
13
|
+
class TC_FileHead < Test::Unit::TestCase
|
14
|
+
def self.startup
|
15
|
+
Dir.chdir('test') if File.exists?('test')
|
16
|
+
File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup
|
20
|
+
@test_file = 'test_file1.txt'
|
21
|
+
@expected_head1 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
|
22
|
+
@expected_head1.push("line6\n","line7\n","line8\n","line9\n","line10\n")
|
23
|
+
@expected_head2 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_head_basic
|
27
|
+
assert_respond_to(File, :head)
|
28
|
+
assert_nothing_raised{ File.head(@test_file) }
|
29
|
+
assert_nothing_raised{ File.head(@test_file, 5) }
|
30
|
+
assert_nothing_raised{ File.head(@test_file){} }
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_head_expected_results
|
34
|
+
assert_kind_of(Array, File.head(@test_file))
|
35
|
+
assert_equal(@expected_head1, File.head(@test_file))
|
36
|
+
assert_equal(@expected_head2, File.head(@test_file, 5))
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_head_expected_errors
|
40
|
+
assert_raises(ArgumentError){ File.head(@test_file, 5, "foo") }
|
41
|
+
assert_raises(Errno::ENOENT){ File.head("bogus") }
|
42
|
+
end
|
43
|
+
|
44
|
+
def teardown
|
45
|
+
@test_file = nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.shutdown
|
49
|
+
File.delete('test_file1.txt') if File.exists?('test_file1.txt')
|
50
|
+
end
|
51
|
+
end
|
data/test/test_image.rb
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
#####################################################################
|
2
|
-
# test_image.rb
|
3
|
-
#
|
4
|
-
# Test case for the File.image? method. You should run this test
|
5
|
-
# via the 'rake test_image' task.
|
6
|
-
#####################################################################
|
7
|
-
require 'rubygems'
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
11
|
-
require 'ptools'
|
12
|
-
|
13
|
-
class TC_Ptools_Image < Test::Unit::TestCase
|
14
|
-
def self.startup
|
15
|
-
Dir.chdir('test') if File.exists?('test')
|
16
|
-
File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
|
17
|
-
end
|
18
|
-
|
19
|
-
def setup
|
20
|
-
@text_file = 'test_file1.txt'
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_image_basic
|
24
|
-
assert_respond_to(File, :image?)
|
25
|
-
assert_nothing_raised{ File.image?(@text_file) }
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_image_expected_results
|
29
|
-
assert_equal(false, File.image?(@text_file))
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_image_expected_errors
|
33
|
-
assert_raises(Errno::ENOENT, ArgumentError){ File.image?('bogus') }
|
34
|
-
end
|
35
|
-
|
36
|
-
def teardown
|
37
|
-
@text_file = nil
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.shutdown
|
41
|
-
File.delete('test_file1.txt') if File.exists?('test_file1.txt')
|
42
|
-
end
|
43
|
-
end
|
1
|
+
#####################################################################
|
2
|
+
# test_image.rb
|
3
|
+
#
|
4
|
+
# Test case for the File.image? method. You should run this test
|
5
|
+
# via the 'rake test_image' task.
|
6
|
+
#####################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'ptools'
|
12
|
+
|
13
|
+
class TC_Ptools_Image < Test::Unit::TestCase
|
14
|
+
def self.startup
|
15
|
+
Dir.chdir('test') if File.exists?('test')
|
16
|
+
File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup
|
20
|
+
@text_file = 'test_file1.txt'
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_image_basic
|
24
|
+
assert_respond_to(File, :image?)
|
25
|
+
assert_nothing_raised{ File.image?(@text_file) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_image_expected_results
|
29
|
+
assert_equal(false, File.image?(@text_file))
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_image_expected_errors
|
33
|
+
assert_raises(Errno::ENOENT, ArgumentError){ File.image?('bogus') }
|
34
|
+
end
|
35
|
+
|
36
|
+
def teardown
|
37
|
+
@text_file = nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.shutdown
|
41
|
+
File.delete('test_file1.txt') if File.exists?('test_file1.txt')
|
42
|
+
end
|
43
|
+
end
|
data/test/test_is_sparse.rb
CHANGED
@@ -1,52 +1,52 @@
|
|
1
|
-
#####################################################################
|
2
|
-
# test_is_sparse.rb
|
3
|
-
#
|
4
|
-
# Test case for the File.sparse? method. You should run this test
|
5
|
-
# via the 'rake test:is_sparse' task.
|
6
|
-
#####################################################################
|
7
|
-
require 'rubygems'
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
11
|
-
require 'ptools'
|
12
|
-
|
13
|
-
class TC_IsSparse < Test::Unit::TestCase
|
14
|
-
def self.startup
|
15
|
-
Dir.chdir("test") if File.exists?("test")
|
16
|
-
@@win = RbConfig::CONFIG['host_os'] =~ /windows|mswin|dos|cygwin|mingw/i
|
17
|
-
@@osx = RbConfig::CONFIG['host_os'] =~ /darwin|osx/i
|
18
|
-
@@sun = RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
|
19
|
-
end
|
20
|
-
|
21
|
-
def setup
|
22
|
-
@sparse_file = @@sun ? '/var/adm/lastlog' : '/var/log/lastlog'
|
23
|
-
@non_sparse_file = File.expand_path(File.basename(__FILE__))
|
24
|
-
end
|
25
|
-
|
26
|
-
test "is_sparse basic functionality" do
|
27
|
-
omit_if(@@win, "File.sparse? tests skipped on MS Windows")
|
28
|
-
omit_if(@@osx, "File.sparse? tests skipped on OS X")
|
29
|
-
|
30
|
-
assert_respond_to(File, :sparse?)
|
31
|
-
assert_nothing_raised{ File.sparse?(@sparse_file) }
|
32
|
-
assert_boolean(File.sparse?(@sparse_file))
|
33
|
-
end
|
34
|
-
|
35
|
-
test "is_sparse returns the expected results" do
|
36
|
-
omit_if(@@win, "File.sparse? tests skipped on MS Windows")
|
37
|
-
omit_if(@@osx, "File.sparse? tests skipped on OS X")
|
38
|
-
|
39
|
-
assert_true(File.sparse?(@sparse_file))
|
40
|
-
assert_false(File.sparse?(@non_sparse_file))
|
41
|
-
end
|
42
|
-
|
43
|
-
test "is_sparse only accepts one argument" do
|
44
|
-
omit_if(@@win, "File.sparse? tests skipped on MS Windows")
|
45
|
-
assert_raise(ArgumentError){ File.sparse?(@sparse_file, @sparse_file) }
|
46
|
-
end
|
47
|
-
|
48
|
-
def teardown
|
49
|
-
@sparse_file = nil
|
50
|
-
@non_sparse_file = nil
|
51
|
-
end
|
52
|
-
end
|
1
|
+
#####################################################################
|
2
|
+
# test_is_sparse.rb
|
3
|
+
#
|
4
|
+
# Test case for the File.sparse? method. You should run this test
|
5
|
+
# via the 'rake test:is_sparse' task.
|
6
|
+
#####################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'ptools'
|
12
|
+
|
13
|
+
class TC_IsSparse < Test::Unit::TestCase
|
14
|
+
def self.startup
|
15
|
+
Dir.chdir("test") if File.exists?("test")
|
16
|
+
@@win = RbConfig::CONFIG['host_os'] =~ /windows|mswin|dos|cygwin|mingw/i
|
17
|
+
@@osx = RbConfig::CONFIG['host_os'] =~ /darwin|osx/i
|
18
|
+
@@sun = RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
|
19
|
+
end
|
20
|
+
|
21
|
+
def setup
|
22
|
+
@sparse_file = @@sun ? '/var/adm/lastlog' : '/var/log/lastlog'
|
23
|
+
@non_sparse_file = File.expand_path(File.basename(__FILE__))
|
24
|
+
end
|
25
|
+
|
26
|
+
test "is_sparse basic functionality" do
|
27
|
+
omit_if(@@win, "File.sparse? tests skipped on MS Windows")
|
28
|
+
omit_if(@@osx, "File.sparse? tests skipped on OS X")
|
29
|
+
|
30
|
+
assert_respond_to(File, :sparse?)
|
31
|
+
assert_nothing_raised{ File.sparse?(@sparse_file) }
|
32
|
+
assert_boolean(File.sparse?(@sparse_file))
|
33
|
+
end
|
34
|
+
|
35
|
+
test "is_sparse returns the expected results" do
|
36
|
+
omit_if(@@win, "File.sparse? tests skipped on MS Windows")
|
37
|
+
omit_if(@@osx, "File.sparse? tests skipped on OS X")
|
38
|
+
|
39
|
+
assert_true(File.sparse?(@sparse_file))
|
40
|
+
assert_false(File.sparse?(@non_sparse_file))
|
41
|
+
end
|
42
|
+
|
43
|
+
test "is_sparse only accepts one argument" do
|
44
|
+
omit_if(@@win, "File.sparse? tests skipped on MS Windows")
|
45
|
+
assert_raise(ArgumentError){ File.sparse?(@sparse_file, @sparse_file) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def teardown
|
49
|
+
@sparse_file = nil
|
50
|
+
@non_sparse_file = nil
|
51
|
+
end
|
52
|
+
end
|