ptools 1.3.1-universal-mingw32 → 1.3.2-universal-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/CHANGES +168 -163
- data/Gemfile +12 -12
- data/MANIFEST +19 -19
- data/README +66 -61
- data/Rakefile +139 -142
- data/lib/ptools.rb +482 -476
- data/ptools.gemspec +30 -30
- data/test/test_binary.rb +65 -65
- data/test/test_constants.rb +38 -38
- data/test/test_head.rb +48 -48
- data/test/test_image.rb +57 -57
- data/test/test_is_sparse.rb +53 -53
- data/test/test_nlconvert.rb +110 -110
- data/test/test_null.rb +40 -40
- data/test/test_tail.rb +124 -123
- data/test/test_touch.rb +53 -52
- data/test/test_wc.rb +73 -73
- data/test/test_whereis.rb +98 -98
- data/test/test_which.rb +126 -126
- data/test/txt/english.txt +1 -1
- data/test/txt/korean.txt +1 -1
- metadata +16 -15
data/test/test_is_sparse.rb
CHANGED
@@ -1,53 +1,53 @@
|
|
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 'test-unit'
|
8
|
-
require 'ptools'
|
9
|
-
|
10
|
-
class TC_IsSparse < Test::Unit::TestCase
|
11
|
-
def self.startup
|
12
|
-
Dir.chdir("test") if File.exist?("test")
|
13
|
-
@@win = File::ALT_SEPARATOR
|
14
|
-
@@osx = RbConfig::CONFIG['host_os'] =~ /darwin|osx/i
|
15
|
-
system("dd of=test_sparse bs=1k seek=5120 count=0 2>/dev/null") unless @@win
|
16
|
-
end
|
17
|
-
|
18
|
-
def setup
|
19
|
-
@sparse_file = 'test_sparse'
|
20
|
-
@non_sparse_file = File.expand_path(File.basename(__FILE__))
|
21
|
-
end
|
22
|
-
|
23
|
-
test "is_sparse basic functionality" do
|
24
|
-
omit_if(@@win, "File.sparse? tests skipped on MS Windows")
|
25
|
-
omit_if(@@osx, "File.sparse? tests skipped on OS X")
|
26
|
-
|
27
|
-
assert_respond_to(File, :sparse?)
|
28
|
-
assert_nothing_raised{ File.sparse?(@sparse_file) }
|
29
|
-
assert_boolean(File.sparse?(@sparse_file))
|
30
|
-
end
|
31
|
-
|
32
|
-
test "is_sparse returns the expected results" do
|
33
|
-
omit_if(@@win, "File.sparse? tests skipped on MS Windows")
|
34
|
-
omit_if(@@osx, "File.sparse? tests skipped on OS X")
|
35
|
-
|
36
|
-
assert_true(File.sparse?(@sparse_file))
|
37
|
-
assert_false(File.sparse?(@non_sparse_file))
|
38
|
-
end
|
39
|
-
|
40
|
-
test "is_sparse only accepts one argument" do
|
41
|
-
omit_if(@@win, "File.sparse? tests skipped on MS Windows")
|
42
|
-
assert_raise(ArgumentError){ File.sparse?(@sparse_file, @sparse_file) }
|
43
|
-
end
|
44
|
-
|
45
|
-
def teardown
|
46
|
-
@sparse_file = nil
|
47
|
-
@non_sparse_file = nil
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.shutdown
|
51
|
-
File.delete('test_sparse') if File.exist?('test_sparse')
|
52
|
-
end
|
53
|
-
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 'test-unit'
|
8
|
+
require 'ptools'
|
9
|
+
|
10
|
+
class TC_IsSparse < Test::Unit::TestCase
|
11
|
+
def self.startup
|
12
|
+
Dir.chdir("test") if File.exist?("test")
|
13
|
+
@@win = File::ALT_SEPARATOR
|
14
|
+
@@osx = RbConfig::CONFIG['host_os'] =~ /darwin|osx/i
|
15
|
+
system("dd of=test_sparse bs=1k seek=5120 count=0 2>/dev/null") unless @@win
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup
|
19
|
+
@sparse_file = 'test_sparse'
|
20
|
+
@non_sparse_file = File.expand_path(File.basename(__FILE__))
|
21
|
+
end
|
22
|
+
|
23
|
+
test "is_sparse basic functionality" do
|
24
|
+
omit_if(@@win, "File.sparse? tests skipped on MS Windows")
|
25
|
+
omit_if(@@osx, "File.sparse? tests skipped on OS X")
|
26
|
+
|
27
|
+
assert_respond_to(File, :sparse?)
|
28
|
+
assert_nothing_raised{ File.sparse?(@sparse_file) }
|
29
|
+
assert_boolean(File.sparse?(@sparse_file))
|
30
|
+
end
|
31
|
+
|
32
|
+
test "is_sparse returns the expected results" do
|
33
|
+
omit_if(@@win, "File.sparse? tests skipped on MS Windows")
|
34
|
+
omit_if(@@osx, "File.sparse? tests skipped on OS X")
|
35
|
+
|
36
|
+
assert_true(File.sparse?(@sparse_file))
|
37
|
+
assert_false(File.sparse?(@non_sparse_file))
|
38
|
+
end
|
39
|
+
|
40
|
+
test "is_sparse only accepts one argument" do
|
41
|
+
omit_if(@@win, "File.sparse? tests skipped on MS Windows")
|
42
|
+
assert_raise(ArgumentError){ File.sparse?(@sparse_file, @sparse_file) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def teardown
|
46
|
+
@sparse_file = nil
|
47
|
+
@non_sparse_file = nil
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.shutdown
|
51
|
+
File.delete('test_sparse') if File.exist?('test_sparse')
|
52
|
+
end
|
53
|
+
end
|
data/test/test_nlconvert.rb
CHANGED
@@ -1,110 +1,110 @@
|
|
1
|
-
#####################################################################
|
2
|
-
# test_nlconvert.rb
|
3
|
-
#
|
4
|
-
# Test case for the File.nl_convert method. You should run this
|
5
|
-
# test via the 'rake test_nlconvert' task.
|
6
|
-
#####################################################################
|
7
|
-
require 'rubygems'
|
8
|
-
require 'test-unit'
|
9
|
-
require 'ptools'
|
10
|
-
|
11
|
-
class TC_Ptools_NLConvert < Test::Unit::TestCase
|
12
|
-
def self.startup
|
13
|
-
|
14
|
-
@@test_file1 = 'test_nl_convert1.txt'
|
15
|
-
@@test_file2 = 'test_nl_convert2.txt'
|
16
|
-
File.open(@@test_file1, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
|
17
|
-
File.open(@@test_file2, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
|
18
|
-
end
|
19
|
-
|
20
|
-
def setup
|
21
|
-
@test_file1 = 'test_nl_convert1.txt'
|
22
|
-
@test_file2 = 'test_nl_convert2.txt'
|
23
|
-
@dos_file = 'dos_test_file.txt'
|
24
|
-
@mac_file = 'mac_test_file.txt'
|
25
|
-
@unix_file = 'nix_test_file.txt'
|
26
|
-
end
|
27
|
-
|
28
|
-
test "nl_for_platform basic functionality" do
|
29
|
-
assert_respond_to(File, :nl_for_platform)
|
30
|
-
end
|
31
|
-
|
32
|
-
test "nl_for_platform" do
|
33
|
-
assert_equal( "\cM\cJ", File.nl_for_platform('dos') )
|
34
|
-
assert_equal( "\cJ", File.nl_for_platform('unix') )
|
35
|
-
assert_equal( "\cM", File.nl_for_platform('mac') )
|
36
|
-
assert_nothing_raised{ File.nl_for_platform('local') }
|
37
|
-
end
|
38
|
-
|
39
|
-
test "nl_convert basic functionality" do
|
40
|
-
assert_respond_to(File, :nl_convert)
|
41
|
-
end
|
42
|
-
|
43
|
-
test "nl_convert accepts one, two or three arguments" do
|
44
|
-
assert_nothing_raised{ File.nl_convert(@test_file2) }
|
45
|
-
assert_nothing_raised{ File.nl_convert(@test_file2, @test_file2) }
|
46
|
-
assert_nothing_raised{ File.nl_convert(@test_file2, @test_file2, "unix") }
|
47
|
-
end
|
48
|
-
|
49
|
-
test "nl_convert with dos platform argument works as expected" do
|
50
|
-
msg = "dos file should be larger, but isn't"
|
51
|
-
|
52
|
-
assert_nothing_raised{ File.nl_convert(@test_file1, @dos_file, "dos") }
|
53
|
-
assert_true(File.size(@dos_file) > File.size(@test_file1), msg)
|
54
|
-
assert_equal(["\cM","\cJ"], IO.readlines(@dos_file).first.split("")[-2..-1])
|
55
|
-
end
|
56
|
-
|
57
|
-
test "nl_convert with mac platform argument works as expected" do
|
58
|
-
assert_nothing_raised{ File.nl_convert(@test_file1, @mac_file, 'mac') }
|
59
|
-
assert_equal("\cM", IO.readlines(@mac_file).first.split("").last)
|
60
|
-
|
61
|
-
omit_if(File::ALT_SEPARATOR)
|
62
|
-
msg = "=> Mac file should be the same size (or larger), but isn't"
|
63
|
-
assert_true(File.size(@mac_file) == File.size(@test_file1), msg)
|
64
|
-
end
|
65
|
-
|
66
|
-
test "nl_convert with unix platform argument works as expected" do
|
67
|
-
msg = "unix file should be the same size (or smaller), but isn't"
|
68
|
-
|
69
|
-
assert_nothing_raised{ File.nl_convert(@test_file1, @unix_file, "unix") }
|
70
|
-
assert_equal("\n", IO.readlines(@unix_file).first.split("").last)
|
71
|
-
|
72
|
-
if File::ALT_SEPARATOR
|
73
|
-
assert_true(File.size(@unix_file) >= File.size(@test_file1), msg)
|
74
|
-
else
|
75
|
-
assert_true(File.size(@unix_file) <= File.size(@test_file1), msg)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
test "nl_convert requires at least one argument" do
|
80
|
-
assert_raise(ArgumentError){ File.nl_convert }
|
81
|
-
end
|
82
|
-
|
83
|
-
test "nl_convert requires a valid platform string" do
|
84
|
-
assert_raise(ArgumentError){ File.nl_convert(@test_file1, "bogus.txt", "blah") }
|
85
|
-
end
|
86
|
-
|
87
|
-
test "nl_convert accepts a maximum of three arguments" do
|
88
|
-
assert_raise(ArgumentError){ File.nl_convert(@test_file1, @test_file2, 'dos', 1) }
|
89
|
-
end
|
90
|
-
|
91
|
-
test "nl_convert will fail on anything but plain files" do
|
92
|
-
assert_raise(ArgumentError){ File.nl_convert(File.null_device, @test_file1) }
|
93
|
-
end
|
94
|
-
|
95
|
-
def teardown
|
96
|
-
[@dos_file, @mac_file, @unix_file].each{ |file|
|
97
|
-
File.delete(file) if File.exist?(file)
|
98
|
-
}
|
99
|
-
@dos_file = nil
|
100
|
-
@mac_file = nil
|
101
|
-
@unix_file = nil
|
102
|
-
@test_file1 = nil
|
103
|
-
@test_file2 = nil
|
104
|
-
end
|
105
|
-
|
106
|
-
def self.shutdown
|
107
|
-
File.delete(@@test_file1) if File.exist?(@@test_file1)
|
108
|
-
File.delete(@@test_file2) if File.exist?(@@test_file2)
|
109
|
-
end
|
110
|
-
end
|
1
|
+
#####################################################################
|
2
|
+
# test_nlconvert.rb
|
3
|
+
#
|
4
|
+
# Test case for the File.nl_convert method. You should run this
|
5
|
+
# test via the 'rake test_nlconvert' task.
|
6
|
+
#####################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
require 'test-unit'
|
9
|
+
require 'ptools'
|
10
|
+
|
11
|
+
class TC_Ptools_NLConvert < Test::Unit::TestCase
|
12
|
+
def self.startup
|
13
|
+
@@dirname = File.dirname(__FILE__)
|
14
|
+
@@test_file1 = File.join(@@dirname, 'test_nl_convert1.txt')
|
15
|
+
@@test_file2 = File.join(@@dirname, 'test_nl_convert2.txt')
|
16
|
+
File.open(@@test_file1, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
|
17
|
+
File.open(@@test_file2, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@test_file1 = File.join(@@dirname, 'test_nl_convert1.txt')
|
22
|
+
@test_file2 = File.join(@@dirname, 'test_nl_convert2.txt')
|
23
|
+
@dos_file = File.join(@@dirname, 'dos_test_file.txt')
|
24
|
+
@mac_file = File.join(@@dirname, 'mac_test_file.txt')
|
25
|
+
@unix_file = 'nix_test_file.txt'
|
26
|
+
end
|
27
|
+
|
28
|
+
test "nl_for_platform basic functionality" do
|
29
|
+
assert_respond_to(File, :nl_for_platform)
|
30
|
+
end
|
31
|
+
|
32
|
+
test "nl_for_platform" do
|
33
|
+
assert_equal( "\cM\cJ", File.nl_for_platform('dos') )
|
34
|
+
assert_equal( "\cJ", File.nl_for_platform('unix') )
|
35
|
+
assert_equal( "\cM", File.nl_for_platform('mac') )
|
36
|
+
assert_nothing_raised{ File.nl_for_platform('local') }
|
37
|
+
end
|
38
|
+
|
39
|
+
test "nl_convert basic functionality" do
|
40
|
+
assert_respond_to(File, :nl_convert)
|
41
|
+
end
|
42
|
+
|
43
|
+
test "nl_convert accepts one, two or three arguments" do
|
44
|
+
assert_nothing_raised{ File.nl_convert(@test_file2) }
|
45
|
+
assert_nothing_raised{ File.nl_convert(@test_file2, @test_file2) }
|
46
|
+
assert_nothing_raised{ File.nl_convert(@test_file2, @test_file2, "unix") }
|
47
|
+
end
|
48
|
+
|
49
|
+
test "nl_convert with dos platform argument works as expected" do
|
50
|
+
msg = "dos file should be larger, but isn't"
|
51
|
+
|
52
|
+
assert_nothing_raised{ File.nl_convert(@test_file1, @dos_file, "dos") }
|
53
|
+
assert_true(File.size(@dos_file) > File.size(@test_file1), msg)
|
54
|
+
assert_equal(["\cM","\cJ"], IO.readlines(@dos_file).first.split("")[-2..-1])
|
55
|
+
end
|
56
|
+
|
57
|
+
test "nl_convert with mac platform argument works as expected" do
|
58
|
+
assert_nothing_raised{ File.nl_convert(@test_file1, @mac_file, 'mac') }
|
59
|
+
assert_equal("\cM", IO.readlines(@mac_file).first.split("").last)
|
60
|
+
|
61
|
+
omit_if(File::ALT_SEPARATOR)
|
62
|
+
msg = "=> Mac file should be the same size (or larger), but isn't"
|
63
|
+
assert_true(File.size(@mac_file) == File.size(@test_file1), msg)
|
64
|
+
end
|
65
|
+
|
66
|
+
test "nl_convert with unix platform argument works as expected" do
|
67
|
+
msg = "unix file should be the same size (or smaller), but isn't"
|
68
|
+
|
69
|
+
assert_nothing_raised{ File.nl_convert(@test_file1, @unix_file, "unix") }
|
70
|
+
assert_equal("\n", IO.readlines(@unix_file).first.split("").last)
|
71
|
+
|
72
|
+
if File::ALT_SEPARATOR
|
73
|
+
assert_true(File.size(@unix_file) >= File.size(@test_file1), msg)
|
74
|
+
else
|
75
|
+
assert_true(File.size(@unix_file) <= File.size(@test_file1), msg)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
test "nl_convert requires at least one argument" do
|
80
|
+
assert_raise(ArgumentError){ File.nl_convert }
|
81
|
+
end
|
82
|
+
|
83
|
+
test "nl_convert requires a valid platform string" do
|
84
|
+
assert_raise(ArgumentError){ File.nl_convert(@test_file1, "bogus.txt", "blah") }
|
85
|
+
end
|
86
|
+
|
87
|
+
test "nl_convert accepts a maximum of three arguments" do
|
88
|
+
assert_raise(ArgumentError){ File.nl_convert(@test_file1, @test_file2, 'dos', 1) }
|
89
|
+
end
|
90
|
+
|
91
|
+
test "nl_convert will fail on anything but plain files" do
|
92
|
+
assert_raise(ArgumentError){ File.nl_convert(File.null_device, @test_file1) }
|
93
|
+
end
|
94
|
+
|
95
|
+
def teardown
|
96
|
+
[@dos_file, @mac_file, @unix_file].each{ |file|
|
97
|
+
File.delete(file) if File.exist?(file)
|
98
|
+
}
|
99
|
+
@dos_file = nil
|
100
|
+
@mac_file = nil
|
101
|
+
@unix_file = nil
|
102
|
+
@test_file1 = nil
|
103
|
+
@test_file2 = nil
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.shutdown
|
107
|
+
File.delete(@@test_file1) if File.exist?(@@test_file1)
|
108
|
+
File.delete(@@test_file2) if File.exist?(@@test_file2)
|
109
|
+
end
|
110
|
+
end
|
data/test/test_null.rb
CHANGED
@@ -1,40 +1,40 @@
|
|
1
|
-
#####################################################################
|
2
|
-
# test_null.rb
|
3
|
-
#
|
4
|
-
# Test case for the File.null method. You should run this test via
|
5
|
-
# the 'rake test_null' task.
|
6
|
-
#####################################################################
|
7
|
-
require 'rubygems'
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
11
|
-
require 'ptools'
|
12
|
-
|
13
|
-
class TC_FileNull < Test::Unit::TestCase
|
14
|
-
def setup
|
15
|
-
@nulls = ['/dev/null', 'NUL', 'NIL:', 'NL:']
|
16
|
-
end
|
17
|
-
|
18
|
-
test "null method basic functionality" do
|
19
|
-
assert_respond_to(File, :null)
|
20
|
-
assert_nothing_raised{ File.null }
|
21
|
-
end
|
22
|
-
|
23
|
-
test "null method returns expected results" do
|
24
|
-
assert_kind_of(String, File.null)
|
25
|
-
assert(@nulls.include?(File.null))
|
26
|
-
end
|
27
|
-
|
28
|
-
test "null method does not accept any arguments" do
|
29
|
-
assert_raises(ArgumentError){ File.null(1) }
|
30
|
-
end
|
31
|
-
|
32
|
-
test "null_device is an alias for null" do
|
33
|
-
assert_respond_to(File, :null_device)
|
34
|
-
assert_alias_method(File, :null_device, :null)
|
35
|
-
end
|
36
|
-
|
37
|
-
def teardown
|
38
|
-
@nulls = nil
|
39
|
-
end
|
40
|
-
end
|
1
|
+
#####################################################################
|
2
|
+
# test_null.rb
|
3
|
+
#
|
4
|
+
# Test case for the File.null method. You should run this test via
|
5
|
+
# the 'rake test_null' task.
|
6
|
+
#####################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'ptools'
|
12
|
+
|
13
|
+
class TC_FileNull < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
@nulls = ['/dev/null', 'NUL', 'NIL:', 'NL:']
|
16
|
+
end
|
17
|
+
|
18
|
+
test "null method basic functionality" do
|
19
|
+
assert_respond_to(File, :null)
|
20
|
+
assert_nothing_raised{ File.null }
|
21
|
+
end
|
22
|
+
|
23
|
+
test "null method returns expected results" do
|
24
|
+
assert_kind_of(String, File.null)
|
25
|
+
assert(@nulls.include?(File.null))
|
26
|
+
end
|
27
|
+
|
28
|
+
test "null method does not accept any arguments" do
|
29
|
+
assert_raises(ArgumentError){ File.null(1) }
|
30
|
+
end
|
31
|
+
|
32
|
+
test "null_device is an alias for null" do
|
33
|
+
assert_respond_to(File, :null_device)
|
34
|
+
assert_alias_method(File, :null_device, :null)
|
35
|
+
end
|
36
|
+
|
37
|
+
def teardown
|
38
|
+
@nulls = nil
|
39
|
+
end
|
40
|
+
end
|
data/test/test_tail.rb
CHANGED
@@ -1,123 +1,124 @@
|
|
1
|
-
#####################################################################
|
2
|
-
# test_tail.rb
|
3
|
-
#
|
4
|
-
# Test case for the File.tail method. This test should be run via
|
5
|
-
# the 'rake test_tail' task.
|
6
|
-
#####################################################################
|
7
|
-
require 'test-unit'
|
8
|
-
require 'ptools'
|
9
|
-
|
10
|
-
class TC_FileTail < Test::Unit::TestCase
|
11
|
-
def self.startup
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
File.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
fh.
|
23
|
-
}
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
File.open(
|
38
|
-
|
39
|
-
fh.puts test_tail_fmt_str % (n+1).to_s
|
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
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
@
|
113
|
-
@
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
File.delete(
|
119
|
-
File.delete(
|
120
|
-
File.delete(
|
121
|
-
File.delete(
|
122
|
-
|
123
|
-
end
|
1
|
+
#####################################################################
|
2
|
+
# test_tail.rb
|
3
|
+
#
|
4
|
+
# Test case for the File.tail method. This test should be run via
|
5
|
+
# the 'rake test_tail' task.
|
6
|
+
#####################################################################
|
7
|
+
require 'test-unit'
|
8
|
+
require 'ptools'
|
9
|
+
|
10
|
+
class TC_FileTail < Test::Unit::TestCase
|
11
|
+
def self.startup
|
12
|
+
@@dirname = File.dirname(__FILE__)
|
13
|
+
|
14
|
+
@@test_file1 = File.join(@@dirname, 'test_file1.txt')
|
15
|
+
@@test_file64 = File.join(@@dirname, 'test_file64.txt')
|
16
|
+
@@test_file128 = File.join(@@dirname, 'test_file128.txt')
|
17
|
+
|
18
|
+
@@test_file_trail = File.join(@@dirname, 'test_file_trail.txt')
|
19
|
+
@@test_file_trail_nl = File.join(@@dirname, 'test_file_trail_nl.txt')
|
20
|
+
|
21
|
+
File.open(@@test_file1, 'w'){ |fh|
|
22
|
+
25.times{ |n| fh.puts "line#{n+1}" }
|
23
|
+
}
|
24
|
+
|
25
|
+
# Trailing newline test
|
26
|
+
File.open(@@test_file_trail, 'w'){ |fh|
|
27
|
+
2.times{ |n| fh.puts "trail#{n+1}" }
|
28
|
+
fh.write "trail3"
|
29
|
+
}
|
30
|
+
File.open(@@test_file_trail_nl, 'w'){ |fh|
|
31
|
+
3.times{ |n| fh.puts "trail#{n+1}" }
|
32
|
+
}
|
33
|
+
|
34
|
+
# Larger files
|
35
|
+
test_tail_fmt_str = "line data data data data data data data %5s"
|
36
|
+
|
37
|
+
File.open(@@test_file64, 'w'){ |fh|
|
38
|
+
2000.times{ |n|
|
39
|
+
fh.puts test_tail_fmt_str % (n+1).to_s
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
File.open(@@test_file128, 'w'){ |fh|
|
44
|
+
4500.times{ |n|
|
45
|
+
fh.puts test_tail_fmt_str % (n+1).to_s
|
46
|
+
}
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def setup
|
51
|
+
@test_file = @@test_file1
|
52
|
+
@test_trail = @@test_file_trail
|
53
|
+
@test_trail_nl = @@test_file_trail_nl
|
54
|
+
@test_file_64 = @@test_file64
|
55
|
+
@test_file_128 = @@test_file128
|
56
|
+
|
57
|
+
@expected_tail1 = %w{
|
58
|
+
line16 line17 line18 line19 line20
|
59
|
+
line21 line22 line23 line24 line25
|
60
|
+
}
|
61
|
+
|
62
|
+
@expected_tail2 = ["line21","line22","line23","line24","line25"]
|
63
|
+
|
64
|
+
@expected_tail_more = []
|
65
|
+
25.times{ |n| @expected_tail_more.push "line#{n+1}" }
|
66
|
+
|
67
|
+
@expected_tail_trail = %w{ trail2 trail3 }
|
68
|
+
|
69
|
+
@test_tail_fmt_str = "line data data data data data data data %5s"
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_tail_basic
|
73
|
+
assert_respond_to(File, :tail)
|
74
|
+
assert_nothing_raised{ File.tail(@test_file) }
|
75
|
+
assert_nothing_raised{ File.tail(@test_file, 5) }
|
76
|
+
assert_nothing_raised{ File.tail(@test_file){} }
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_tail_expected_return_values
|
80
|
+
assert_kind_of(Array, File.tail(@test_file))
|
81
|
+
assert_equal(@expected_tail1, File.tail(@test_file))
|
82
|
+
assert_equal(@expected_tail2, File.tail(@test_file, 5))
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_more_lines_than_file
|
86
|
+
assert_equal( @expected_tail_more, File.tail(@test_file, 30) )
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_tail_expected_errors
|
90
|
+
assert_raises(ArgumentError){ File.tail }
|
91
|
+
assert_raises(ArgumentError){ File.tail(@test_file, 5, 5) }
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_no_trailing_newline
|
95
|
+
assert_equal( @expected_tail_trail, File.tail(@test_trail, 2) )
|
96
|
+
assert_equal( @expected_tail_trail, File.tail(@test_trail_nl, 2) )
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_tail_larger_than_64k
|
100
|
+
expected_tail_64k=[]
|
101
|
+
2000.times{ |n| expected_tail_64k.push( @test_tail_fmt_str % (n+1).to_s ) }
|
102
|
+
assert_equal( expected_tail_64k, File.tail(@test_file_64, 2000) )
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_tail_larger_than_128k
|
106
|
+
expected_tail_128k = []
|
107
|
+
4500.times{ |n| expected_tail_128k.push( @test_tail_fmt_str % (n+1).to_s ) }
|
108
|
+
assert_equal( expected_tail_128k, File.tail(@test_file_128, 4500) )
|
109
|
+
end
|
110
|
+
|
111
|
+
def teardown
|
112
|
+
@test_file = nil
|
113
|
+
@expected_tail1 = nil
|
114
|
+
@expected_tail2 = nil
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.shutdown
|
118
|
+
File.delete(@@test_file1) if File.exist?(@@test_file1)
|
119
|
+
File.delete(@@test_file64) if File.exist?(@@test_file64)
|
120
|
+
File.delete(@@test_file128) if File.exist?(@@test_file128)
|
121
|
+
File.delete(@@test_file_trail_nl) if File.exist?(@@test_file_trail_nl)
|
122
|
+
File.delete(@@test_file_trail) if File.exist?(@@test_file_trail)
|
123
|
+
end
|
124
|
+
end
|