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/test/test_touch.rb
CHANGED
@@ -1,55 +1,55 @@
|
|
1
|
-
#####################################################################
|
2
|
-
# tc_touch.rb
|
3
|
-
#
|
4
|
-
# Test case for the File.touch method. This test should be run
|
5
|
-
# via the 'rake test_touch task'.
|
6
|
-
#####################################################################
|
7
|
-
require 'rubygems'
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
11
|
-
require 'ptools'
|
12
|
-
|
13
|
-
class TC_FileTouch < Test::Unit::TestCase
|
14
|
-
def self.startup
|
15
|
-
Dir.chdir('test') if File.exists?('test')
|
16
|
-
File.open('test_file1.txt', 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
|
17
|
-
end
|
18
|
-
|
19
|
-
def setup
|
20
|
-
@test_file = 'delete.this'
|
21
|
-
@xfile = 'test_file1.txt'
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_touch_basic
|
25
|
-
assert_respond_to(File, :touch)
|
26
|
-
assert_nothing_raised{ File.touch(@test_file) }
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_touch_expected_results
|
30
|
-
assert_equal(File, File.touch(@test_file))
|
31
|
-
assert_equal(true, File.exists?(@test_file))
|
32
|
-
assert_equal(0, File.size(@test_file))
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_touch_existing_file
|
36
|
-
stat = File.stat(@xfile)
|
37
|
-
sleep 1
|
38
|
-
assert_nothing_raised{ File.touch(@xfile) }
|
39
|
-
assert_equal(true, File.size(@xfile) == stat.size)
|
40
|
-
assert_equal(false, File.mtime(@xfile) == stat.mtime)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_touch_expected_errors
|
44
|
-
assert_raises(ArgumentError){ File.touch }
|
45
|
-
end
|
46
|
-
|
47
|
-
def teardown
|
48
|
-
File.delete(@test_file) if File.exists?(@test_file)
|
49
|
-
@test_file = nil
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.shutdown
|
53
|
-
File.delete('test_file1.txt') if File.exists?('test_file1.txt')
|
54
|
-
end
|
55
|
-
end
|
1
|
+
#####################################################################
|
2
|
+
# tc_touch.rb
|
3
|
+
#
|
4
|
+
# Test case for the File.touch method. This test should be run
|
5
|
+
# via the 'rake test_touch task'.
|
6
|
+
#####################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'ptools'
|
12
|
+
|
13
|
+
class TC_FileTouch < Test::Unit::TestCase
|
14
|
+
def self.startup
|
15
|
+
Dir.chdir('test') if File.exists?('test')
|
16
|
+
File.open('test_file1.txt', 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup
|
20
|
+
@test_file = 'delete.this'
|
21
|
+
@xfile = 'test_file1.txt'
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_touch_basic
|
25
|
+
assert_respond_to(File, :touch)
|
26
|
+
assert_nothing_raised{ File.touch(@test_file) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_touch_expected_results
|
30
|
+
assert_equal(File, File.touch(@test_file))
|
31
|
+
assert_equal(true, File.exists?(@test_file))
|
32
|
+
assert_equal(0, File.size(@test_file))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_touch_existing_file
|
36
|
+
stat = File.stat(@xfile)
|
37
|
+
sleep 1
|
38
|
+
assert_nothing_raised{ File.touch(@xfile) }
|
39
|
+
assert_equal(true, File.size(@xfile) == stat.size)
|
40
|
+
assert_equal(false, File.mtime(@xfile) == stat.mtime)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_touch_expected_errors
|
44
|
+
assert_raises(ArgumentError){ File.touch }
|
45
|
+
end
|
46
|
+
|
47
|
+
def teardown
|
48
|
+
File.delete(@test_file) if File.exists?(@test_file)
|
49
|
+
@test_file = nil
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.shutdown
|
53
|
+
File.delete('test_file1.txt') if File.exists?('test_file1.txt')
|
54
|
+
end
|
55
|
+
end
|
data/test/test_wc.rb
CHANGED
@@ -1,76 +1,76 @@
|
|
1
|
-
#####################################################################
|
2
|
-
# test_wc.rb
|
3
|
-
#
|
4
|
-
# Test case for the File.wc method. This test should be run via
|
5
|
-
# the 'rake test_wc' task.
|
6
|
-
#####################################################################
|
7
|
-
require 'rubygems'
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
11
|
-
require 'ptools'
|
12
|
-
|
13
|
-
class TC_FileWC < 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
|
-
@@test_file = 'test_file1.txt'
|
18
|
-
end
|
19
|
-
|
20
|
-
def setup
|
21
|
-
@test_file = 'test_file1.txt'
|
22
|
-
end
|
23
|
-
|
24
|
-
test "wc method basic functionality" do
|
25
|
-
assert_respond_to(File, :wc)
|
26
|
-
assert_nothing_raised{ File.wc(@test_file) }
|
27
|
-
end
|
28
|
-
|
29
|
-
test "wc accepts specific optional arguments" do
|
30
|
-
assert_nothing_raised{ File.wc(@test_file, 'bytes') }
|
31
|
-
assert_nothing_raised{ File.wc(@test_file, 'chars') }
|
32
|
-
assert_nothing_raised{ File.wc(@test_file, 'words') }
|
33
|
-
assert_nothing_raised{ File.wc(@test_file, 'lines') }
|
34
|
-
end
|
35
|
-
|
36
|
-
test "argument to wc ignores the case of the option argument" do
|
37
|
-
assert_nothing_raised{ File.wc(@test_file, 'LINES') }
|
38
|
-
end
|
39
|
-
|
40
|
-
test "wc with no option returns expected results" do
|
41
|
-
assert_kind_of(Array, File.wc(@test_file))
|
42
|
-
assert_equal([166,166,25,25], File.wc(@test_file))
|
43
|
-
end
|
44
|
-
|
45
|
-
test "wc with bytes option returns the expected result" do
|
46
|
-
assert_equal(166, File.wc(@test_file, 'bytes'), "Wrong number of bytes")
|
47
|
-
end
|
48
|
-
|
49
|
-
test "wc with chars option returns the expected result" do
|
50
|
-
assert_equal(166, File.wc(@test_file, 'chars'), "Wrong number of chars")
|
51
|
-
end
|
52
|
-
|
53
|
-
test "wc with words option returns the expected result" do
|
54
|
-
assert_equal(25, File.wc(@test_file, 'words'), "Wrong number of words")
|
55
|
-
end
|
56
|
-
|
57
|
-
test "wc with lines option returns the expected result" do
|
58
|
-
assert_equal(25, File.wc(@test_file, 'lines'), "Wrong number of lines")
|
59
|
-
end
|
60
|
-
|
61
|
-
test "wc requires at least on argument" do
|
62
|
-
assert_raises(ArgumentError){ File.wc }
|
63
|
-
end
|
64
|
-
|
65
|
-
test "an invalid option raises an error" do
|
66
|
-
assert_raises(ArgumentError){ File.wc(@test_file, 'bogus') }
|
67
|
-
end
|
68
|
-
|
69
|
-
def teardown
|
70
|
-
@test_file = nil
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.shutdown
|
74
|
-
File.delete(@@test_file) if File.exists?(@@test_file)
|
75
|
-
end
|
76
|
-
end
|
1
|
+
#####################################################################
|
2
|
+
# test_wc.rb
|
3
|
+
#
|
4
|
+
# Test case for the File.wc method. This test should be run via
|
5
|
+
# the 'rake test_wc' task.
|
6
|
+
#####################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'ptools'
|
12
|
+
|
13
|
+
class TC_FileWC < 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
|
+
@@test_file = 'test_file1.txt'
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@test_file = 'test_file1.txt'
|
22
|
+
end
|
23
|
+
|
24
|
+
test "wc method basic functionality" do
|
25
|
+
assert_respond_to(File, :wc)
|
26
|
+
assert_nothing_raised{ File.wc(@test_file) }
|
27
|
+
end
|
28
|
+
|
29
|
+
test "wc accepts specific optional arguments" do
|
30
|
+
assert_nothing_raised{ File.wc(@test_file, 'bytes') }
|
31
|
+
assert_nothing_raised{ File.wc(@test_file, 'chars') }
|
32
|
+
assert_nothing_raised{ File.wc(@test_file, 'words') }
|
33
|
+
assert_nothing_raised{ File.wc(@test_file, 'lines') }
|
34
|
+
end
|
35
|
+
|
36
|
+
test "argument to wc ignores the case of the option argument" do
|
37
|
+
assert_nothing_raised{ File.wc(@test_file, 'LINES') }
|
38
|
+
end
|
39
|
+
|
40
|
+
test "wc with no option returns expected results" do
|
41
|
+
assert_kind_of(Array, File.wc(@test_file))
|
42
|
+
assert_equal([166,166,25,25], File.wc(@test_file))
|
43
|
+
end
|
44
|
+
|
45
|
+
test "wc with bytes option returns the expected result" do
|
46
|
+
assert_equal(166, File.wc(@test_file, 'bytes'), "Wrong number of bytes")
|
47
|
+
end
|
48
|
+
|
49
|
+
test "wc with chars option returns the expected result" do
|
50
|
+
assert_equal(166, File.wc(@test_file, 'chars'), "Wrong number of chars")
|
51
|
+
end
|
52
|
+
|
53
|
+
test "wc with words option returns the expected result" do
|
54
|
+
assert_equal(25, File.wc(@test_file, 'words'), "Wrong number of words")
|
55
|
+
end
|
56
|
+
|
57
|
+
test "wc with lines option returns the expected result" do
|
58
|
+
assert_equal(25, File.wc(@test_file, 'lines'), "Wrong number of lines")
|
59
|
+
end
|
60
|
+
|
61
|
+
test "wc requires at least on argument" do
|
62
|
+
assert_raises(ArgumentError){ File.wc }
|
63
|
+
end
|
64
|
+
|
65
|
+
test "an invalid option raises an error" do
|
66
|
+
assert_raises(ArgumentError){ File.wc(@test_file, 'bogus') }
|
67
|
+
end
|
68
|
+
|
69
|
+
def teardown
|
70
|
+
@test_file = nil
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.shutdown
|
74
|
+
File.delete(@@test_file) if File.exists?(@@test_file)
|
75
|
+
end
|
76
|
+
end
|
data/test/test_whereis.rb
CHANGED
@@ -1,98 +1,98 @@
|
|
1
|
-
######################################################################
|
2
|
-
# test_whereis.rb
|
3
|
-
#
|
4
|
-
# Tests for the File.whereis method.
|
5
|
-
######################################################################
|
6
|
-
require 'rubygems'
|
7
|
-
require 'test-unit'
|
8
|
-
require 'ptools'
|
9
|
-
require 'rbconfig'
|
10
|
-
|
11
|
-
class TC_Ptools_Whereis < Test::Unit::TestCase
|
12
|
-
def self.startup
|
13
|
-
@@windows = File::ALT_SEPARATOR
|
14
|
-
@@ruby = RUBY_PLATFORM == 'java' ? 'jruby' : 'ruby'
|
15
|
-
end
|
16
|
-
|
17
|
-
def setup
|
18
|
-
@bin_dir = RbConfig::CONFIG['bindir']
|
19
|
-
@expected_locs = [File.join(@bin_dir, @@ruby)]
|
20
|
-
|
21
|
-
if @@windows
|
22
|
-
@expected_locs[0] << '.exe'
|
23
|
-
@expected_locs[0].tr!("/", "\\")
|
24
|
-
end
|
25
|
-
|
26
|
-
unless @@windows
|
27
|
-
@expected_locs << "/usr/local/bin/#{@@ruby}"
|
28
|
-
@expected_locs << "/opt/sfw/bin/#{@@ruby}"
|
29
|
-
@expected_locs << "/opt/bin/#{@@ruby}"
|
30
|
-
@expected_locs << "/usr/bin/#{@@ruby}"
|
31
|
-
end
|
32
|
-
|
33
|
-
@actual_locs = nil
|
34
|
-
end
|
35
|
-
|
36
|
-
test "whereis basic functionality" do
|
37
|
-
assert_respond_to(File, :whereis)
|
38
|
-
assert_nothing_raised{ File.whereis('ruby') }
|
39
|
-
assert_kind_of([Array, NilClass], File.whereis('ruby'))
|
40
|
-
end
|
41
|
-
|
42
|
-
test "whereis accepts an optional second argument" do
|
43
|
-
assert_nothing_raised{ File.whereis('ruby', '/usr/bin:/usr/local/bin') }
|
44
|
-
end
|
45
|
-
|
46
|
-
test "whereis returns expected values" do
|
47
|
-
assert_nothing_raised{ @actual_locs = File.whereis(@@ruby) }
|
48
|
-
assert_kind_of(Array, @actual_locs)
|
49
|
-
assert_true((@expected_locs & @actual_locs).size > 0)
|
50
|
-
end
|
51
|
-
|
52
|
-
test "whereis returns nil if program not found" do
|
53
|
-
assert_nil(File.whereis('xxxyyy'))
|
54
|
-
end
|
55
|
-
|
56
|
-
test "whereis returns nil if program cannot be found in provided path" do
|
57
|
-
assert_nil(File.whereis(@@ruby, '/foo/bar'))
|
58
|
-
end
|
59
|
-
|
60
|
-
test "whereis returns single element array or nil if absolute path is provided" do
|
61
|
-
absolute = File.join(@bin_dir, @@ruby)
|
62
|
-
absolute << '.exe' if @@windows
|
63
|
-
|
64
|
-
assert_equal([absolute], File.whereis(absolute))
|
65
|
-
assert_nil(File.whereis("/foo/bar/baz/#{@@ruby}"))
|
66
|
-
end
|
67
|
-
|
68
|
-
test "whereis works with an explicit extension on ms windows" do
|
69
|
-
omit_unless(@@windows, 'test skipped except on MS Windows')
|
70
|
-
assert_not_nil(File.whereis(@@ruby + '.exe'))
|
71
|
-
end
|
72
|
-
|
73
|
-
test "whereis requires at least one argument" do
|
74
|
-
assert_raise(ArgumentError){ File.whereis }
|
75
|
-
end
|
76
|
-
|
77
|
-
test "whereis returns unique paths only" do
|
78
|
-
assert_true(File.whereis(@@ruby) == File.whereis(@@ruby).uniq)
|
79
|
-
end
|
80
|
-
|
81
|
-
test "whereis accepts a maximum of two arguments" do
|
82
|
-
assert_raise(ArgumentError){ File.whereis(@@ruby, 'foo', 'bar') }
|
83
|
-
end
|
84
|
-
|
85
|
-
test "the second argument to whereis cannot be nil or empty" do
|
86
|
-
assert_raise(ArgumentError){ File.whereis(@@ruby, nil) }
|
87
|
-
assert_raise(ArgumentError){ File.whereis(@@ruby, '') }
|
88
|
-
end
|
89
|
-
|
90
|
-
def teardown
|
91
|
-
@expected_locs = nil
|
92
|
-
@actual_locs = nil
|
93
|
-
end
|
94
|
-
|
95
|
-
def self.shutdown
|
96
|
-
@@windows = nil
|
97
|
-
end
|
98
|
-
end
|
1
|
+
######################################################################
|
2
|
+
# test_whereis.rb
|
3
|
+
#
|
4
|
+
# Tests for the File.whereis method.
|
5
|
+
######################################################################
|
6
|
+
require 'rubygems'
|
7
|
+
require 'test-unit'
|
8
|
+
require 'ptools'
|
9
|
+
require 'rbconfig'
|
10
|
+
|
11
|
+
class TC_Ptools_Whereis < Test::Unit::TestCase
|
12
|
+
def self.startup
|
13
|
+
@@windows = File::ALT_SEPARATOR
|
14
|
+
@@ruby = RUBY_PLATFORM == 'java' ? 'jruby' : 'ruby'
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup
|
18
|
+
@bin_dir = RbConfig::CONFIG['bindir']
|
19
|
+
@expected_locs = [File.join(@bin_dir, @@ruby)]
|
20
|
+
|
21
|
+
if @@windows
|
22
|
+
@expected_locs[0] << '.exe'
|
23
|
+
@expected_locs[0].tr!("/", "\\")
|
24
|
+
end
|
25
|
+
|
26
|
+
unless @@windows
|
27
|
+
@expected_locs << "/usr/local/bin/#{@@ruby}"
|
28
|
+
@expected_locs << "/opt/sfw/bin/#{@@ruby}"
|
29
|
+
@expected_locs << "/opt/bin/#{@@ruby}"
|
30
|
+
@expected_locs << "/usr/bin/#{@@ruby}"
|
31
|
+
end
|
32
|
+
|
33
|
+
@actual_locs = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
test "whereis basic functionality" do
|
37
|
+
assert_respond_to(File, :whereis)
|
38
|
+
assert_nothing_raised{ File.whereis('ruby') }
|
39
|
+
assert_kind_of([Array, NilClass], File.whereis('ruby'))
|
40
|
+
end
|
41
|
+
|
42
|
+
test "whereis accepts an optional second argument" do
|
43
|
+
assert_nothing_raised{ File.whereis('ruby', '/usr/bin:/usr/local/bin') }
|
44
|
+
end
|
45
|
+
|
46
|
+
test "whereis returns expected values" do
|
47
|
+
assert_nothing_raised{ @actual_locs = File.whereis(@@ruby) }
|
48
|
+
assert_kind_of(Array, @actual_locs)
|
49
|
+
assert_true((@expected_locs & @actual_locs).size > 0)
|
50
|
+
end
|
51
|
+
|
52
|
+
test "whereis returns nil if program not found" do
|
53
|
+
assert_nil(File.whereis('xxxyyy'))
|
54
|
+
end
|
55
|
+
|
56
|
+
test "whereis returns nil if program cannot be found in provided path" do
|
57
|
+
assert_nil(File.whereis(@@ruby, '/foo/bar'))
|
58
|
+
end
|
59
|
+
|
60
|
+
test "whereis returns single element array or nil if absolute path is provided" do
|
61
|
+
absolute = File.join(@bin_dir, @@ruby)
|
62
|
+
absolute << '.exe' if @@windows
|
63
|
+
|
64
|
+
assert_equal([absolute], File.whereis(absolute))
|
65
|
+
assert_nil(File.whereis("/foo/bar/baz/#{@@ruby}"))
|
66
|
+
end
|
67
|
+
|
68
|
+
test "whereis works with an explicit extension on ms windows" do
|
69
|
+
omit_unless(@@windows, 'test skipped except on MS Windows')
|
70
|
+
assert_not_nil(File.whereis(@@ruby + '.exe'))
|
71
|
+
end
|
72
|
+
|
73
|
+
test "whereis requires at least one argument" do
|
74
|
+
assert_raise(ArgumentError){ File.whereis }
|
75
|
+
end
|
76
|
+
|
77
|
+
test "whereis returns unique paths only" do
|
78
|
+
assert_true(File.whereis(@@ruby) == File.whereis(@@ruby).uniq)
|
79
|
+
end
|
80
|
+
|
81
|
+
test "whereis accepts a maximum of two arguments" do
|
82
|
+
assert_raise(ArgumentError){ File.whereis(@@ruby, 'foo', 'bar') }
|
83
|
+
end
|
84
|
+
|
85
|
+
test "the second argument to whereis cannot be nil or empty" do
|
86
|
+
assert_raise(ArgumentError){ File.whereis(@@ruby, nil) }
|
87
|
+
assert_raise(ArgumentError){ File.whereis(@@ruby, '') }
|
88
|
+
end
|
89
|
+
|
90
|
+
def teardown
|
91
|
+
@expected_locs = nil
|
92
|
+
@actual_locs = nil
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.shutdown
|
96
|
+
@@windows = nil
|
97
|
+
end
|
98
|
+
end
|