ptools 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGES +7 -0
- data/Rakefile +6 -1
- data/lib/ptools.rb +5 -5
- data/ptools.gemspec +4 -4
- data/test/test_binary.rb +2 -2
- data/test/test_constants.rb +1 -1
- data/test/test_head.rb +34 -37
- data/test/test_image.rb +26 -29
- data/test/test_is_sparse.rb +2 -5
- data/test/test_middle.rb +48 -51
- data/test/test_nlconvert.rb +4 -4
- data/test/test_tail.rb +43 -46
- data/test/test_touch.rb +43 -46
- data/test/test_wc.rb +5 -8
- data/test/test_which.rb +2 -5
- metadata +42 -59
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 16f06f25547577f77bf9f56f263bd4bd29bd2c2c
|
4
|
+
data.tar.gz: 6d86459c2c74ea62fe50b674ba1a866aef4059b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c2ed19fd3d1e598a5599b2f3893f922c2fd132702dc5af72153a1e87bcdd4dfb9e5dc8c8f5ffdd34d19eaf8c55429186e87527633ab2bb2027f3fb329864a6f9
|
7
|
+
data.tar.gz: 2ce7328135836e1b821664167099de0d434c451e4269ab838141638be4c9f67e21096904ff69244fb973370629a3289a95056779801abaea9fba7d67b6d6a834
|
data/CHANGES
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 1.2.3 - 19-Feb-2014
|
2
|
+
* Fixed a bug where File.binary? would return true for unicode text. Thanks go
|
3
|
+
to Ben Hollis for the spot.
|
4
|
+
* Updated the win32-file and test-unit dependencies.
|
5
|
+
* Replace all instances of File.exists? with File.exist? because the former
|
6
|
+
is deprecated in Ruby 2.1 and later.
|
7
|
+
|
1
8
|
== 1.2.2 - 6-Apr-2012
|
2
9
|
* Yet another sparse file test fix for OSX, which does not support
|
3
10
|
sparse file generation on HFS+.
|
data/Rakefile
CHANGED
@@ -18,7 +18,12 @@ namespace 'gem' do
|
|
18
18
|
task :create => [:clean] do
|
19
19
|
Dir["*.gem"].each{ |f| File.delete(f) } # Clean first
|
20
20
|
spec = eval(IO.read('ptools.gemspec'))
|
21
|
-
Gem::
|
21
|
+
if Gem::VERSION < "2.0.0"
|
22
|
+
Gem::Builder.new(spec).build
|
23
|
+
else
|
24
|
+
require 'rubygems/package'
|
25
|
+
Gem::Package.build(spec)
|
26
|
+
end
|
22
27
|
end
|
23
28
|
|
24
29
|
desc 'Install the ptools gem'
|
data/lib/ptools.rb
CHANGED
@@ -3,7 +3,7 @@ require 'win32/file' if File::ALT_SEPARATOR
|
|
3
3
|
|
4
4
|
class File
|
5
5
|
# The version of the ptools library.
|
6
|
-
PTOOLS_VERSION = '1.2.
|
6
|
+
PTOOLS_VERSION = '1.2.3'
|
7
7
|
|
8
8
|
# :stopdoc:
|
9
9
|
|
@@ -88,7 +88,7 @@ class File
|
|
88
88
|
# based on Perl's -B switch).
|
89
89
|
#
|
90
90
|
def self.binary?(file)
|
91
|
-
s = (File.read(file, File.stat(file).blksize) || "").split(//)
|
91
|
+
s = (File.read(file, File.stat(file).blksize) || "").encode('US-ASCII', :undef => :replace).split(//)
|
92
92
|
((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
|
93
93
|
end
|
94
94
|
|
@@ -123,7 +123,7 @@ class File
|
|
123
123
|
|
124
124
|
# Iterate over each path glob the dir + program.
|
125
125
|
path.split(File::PATH_SEPARATOR).each{ |dir|
|
126
|
-
next unless File.
|
126
|
+
next unless File.exist?(dir) # In case of bogus second argument
|
127
127
|
file = File.join(dir, program)
|
128
128
|
|
129
129
|
# Dir[] doesn't handle backslashes properly, so convert them. Also, if
|
@@ -182,7 +182,7 @@ class File
|
|
182
182
|
|
183
183
|
# Iterate over each path glob the dir + program.
|
184
184
|
path.split(File::PATH_SEPARATOR).each{ |dir|
|
185
|
-
next unless File.
|
185
|
+
next unless File.exist?(dir) # In case of bogus second argument
|
186
186
|
file = File.join(dir, program)
|
187
187
|
|
188
188
|
# Dir[] doesn't handle backslashes properly, so convert them. Also, if
|
@@ -332,7 +332,7 @@ class File
|
|
332
332
|
# byte file +filename+ if it doesn't already exist.
|
333
333
|
#
|
334
334
|
def self.touch(filename)
|
335
|
-
if File.
|
335
|
+
if File.exist?(filename)
|
336
336
|
time = Time.now
|
337
337
|
File.utime(time, time, filename)
|
338
338
|
else
|
data/ptools.gemspec
CHANGED
@@ -3,11 +3,11 @@ require 'rbconfig'
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.name = 'ptools'
|
6
|
-
gem.version = '1.2.
|
6
|
+
gem.version = '1.2.3'
|
7
7
|
gem.license = 'Artistic 2.0'
|
8
8
|
gem.author = 'Daniel J. Berger'
|
9
9
|
gem.email = 'djberg96@gmail.com'
|
10
|
-
gem.homepage = '
|
10
|
+
gem.homepage = 'https://github.com/djberg96/ptools'
|
11
11
|
gem.summary = 'Extra methods for the File class'
|
12
12
|
gem.test_files = Dir['test/test*']
|
13
13
|
gem.files = Dir['**/*'] << '.gemtest'
|
@@ -21,10 +21,10 @@ Gem::Specification.new do |gem|
|
|
21
21
|
File.null to return the null device on your platform, and so on.
|
22
22
|
EOF
|
23
23
|
|
24
|
-
gem.add_development_dependency('test-unit', '>= 2.
|
24
|
+
gem.add_development_dependency('test-unit', '>= 2.5.0')
|
25
25
|
|
26
26
|
if File::ALT_SEPARATOR
|
27
27
|
gem.platform = Gem::Platform.new(['universal', 'mingw32'])
|
28
|
-
gem.add_dependency('win32-file', '>= 0.
|
28
|
+
gem.add_dependency('win32-file', '>= 0.7.0')
|
29
29
|
end
|
30
30
|
end
|
data/test/test_binary.rb
CHANGED
@@ -18,7 +18,7 @@ class TC_Ptools_Binary < Test::Unit::TestCase
|
|
18
18
|
@@bin_file = '/bin/ls'
|
19
19
|
end
|
20
20
|
|
21
|
-
Dir.chdir('test') if File.
|
21
|
+
Dir.chdir('test') if File.exist?('test')
|
22
22
|
|
23
23
|
File.open(@@txt_file, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
|
24
24
|
end
|
@@ -42,6 +42,6 @@ class TC_Ptools_Binary < Test::Unit::TestCase
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.shutdown
|
45
|
-
File.delete(@@txt_file) if File.
|
45
|
+
File.delete(@@txt_file) if File.exist?(@@txt_file)
|
46
46
|
end
|
47
47
|
end
|
data/test/test_constants.rb
CHANGED
@@ -15,7 +15,7 @@ class TC_Ptools_Constants < Test::Unit::TestCase
|
|
15
15
|
end
|
16
16
|
|
17
17
|
test "PTOOLS_VERSION constant is set to expected value" do
|
18
|
-
assert_equal('1.2.
|
18
|
+
assert_equal('1.2.3', File::PTOOLS_VERSION)
|
19
19
|
end
|
20
20
|
|
21
21
|
test "IMAGE_EXT constant is set to array of values" do
|
data/test/test_head.rb
CHANGED
@@ -1,51 +1,48 @@
|
|
1
1
|
######################################################################
|
2
2
|
# test_head.rb
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# Test case for the File.head method. This test should be run via
|
5
5
|
# the 'rake test_head' task.
|
6
6
|
######################################################################
|
7
|
-
require '
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
7
|
+
require 'test-unit'
|
11
8
|
require 'ptools'
|
12
9
|
|
13
10
|
class TC_FileHead < Test::Unit::TestCase
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
11
|
+
def self.startup
|
12
|
+
Dir.chdir('test') if File.exist?('test')
|
13
|
+
File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@test_file = 'test_file1.txt'
|
18
|
+
@expected_head1 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
|
19
|
+
@expected_head1.push("line6\n","line7\n","line8\n","line9\n","line10\n")
|
20
|
+
@expected_head2 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
|
21
|
+
end
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
def test_head_basic
|
24
|
+
assert_respond_to(File, :head)
|
25
|
+
assert_nothing_raised{ File.head(@test_file) }
|
26
|
+
assert_nothing_raised{ File.head(@test_file, 5) }
|
27
|
+
assert_nothing_raised{ File.head(@test_file){} }
|
28
|
+
end
|
32
29
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
def test_head_expected_results
|
31
|
+
assert_kind_of(Array, File.head(@test_file))
|
32
|
+
assert_equal(@expected_head1, File.head(@test_file))
|
33
|
+
assert_equal(@expected_head2, File.head(@test_file, 5))
|
34
|
+
end
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
def test_head_expected_errors
|
37
|
+
assert_raises(ArgumentError){ File.head(@test_file, 5, "foo") }
|
38
|
+
assert_raises(Errno::ENOENT){ File.head("bogus") }
|
39
|
+
end
|
43
40
|
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
def teardown
|
42
|
+
@test_file = nil
|
43
|
+
end
|
47
44
|
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
def self.shutdown
|
46
|
+
File.delete('test_file1.txt') if File.exist?('test_file1.txt')
|
47
|
+
end
|
51
48
|
end
|
data/test/test_image.rb
CHANGED
@@ -1,43 +1,40 @@
|
|
1
1
|
#####################################################################
|
2
2
|
# test_image.rb
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# Test case for the File.image? method. You should run this test
|
5
5
|
# via the 'rake test_image' task.
|
6
6
|
#####################################################################
|
7
|
-
require '
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
7
|
+
require 'test-unit'
|
11
8
|
require 'ptools'
|
12
9
|
|
13
10
|
class TC_Ptools_Image < Test::Unit::TestCase
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
def self.startup
|
12
|
+
Dir.chdir('test') if File.exist?('test')
|
13
|
+
File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@text_file = 'test_file1.txt'
|
18
|
+
end
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
def test_image_basic
|
21
|
+
assert_respond_to(File, :image?)
|
22
|
+
assert_nothing_raised{ File.image?(@text_file) }
|
23
|
+
end
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
def test_image_expected_results
|
26
|
+
assert_equal(false, File.image?(@text_file))
|
27
|
+
end
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
def test_image_expected_errors
|
30
|
+
assert_raises(Errno::ENOENT, ArgumentError){ File.image?('bogus') }
|
31
|
+
end
|
35
32
|
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
def teardown
|
34
|
+
@text_file = nil
|
35
|
+
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
def self.shutdown
|
38
|
+
File.delete('test_file1.txt') if File.exist?('test_file1.txt')
|
39
|
+
end
|
43
40
|
end
|
data/test/test_is_sparse.rb
CHANGED
@@ -4,15 +4,12 @@
|
|
4
4
|
# Test case for the File.sparse? method. You should run this test
|
5
5
|
# via the 'rake test:is_sparse' task.
|
6
6
|
#####################################################################
|
7
|
-
require '
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
7
|
+
require 'test-unit'
|
11
8
|
require 'ptools'
|
12
9
|
|
13
10
|
class TC_IsSparse < Test::Unit::TestCase
|
14
11
|
def self.startup
|
15
|
-
Dir.chdir("test") if File.
|
12
|
+
Dir.chdir("test") if File.exist?("test")
|
16
13
|
@@win = RbConfig::CONFIG['host_os'] =~ /windows|mswin|dos|cygwin|mingw/i
|
17
14
|
@@osx = RbConfig::CONFIG['host_os'] =~ /darwin|osx/i
|
18
15
|
@@sun = RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
|
data/test/test_middle.rb
CHANGED
@@ -4,58 +4,55 @@
|
|
4
4
|
# Test case for the File.middle method. You should run this test
|
5
5
|
# via the 'rake test_middle' task.
|
6
6
|
#####################################################################
|
7
|
-
require '
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
7
|
+
require 'test-unit'
|
11
8
|
require 'ptools'
|
12
9
|
|
13
10
|
class TC_FileMiddle < Test::Unit::TestCase
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
11
|
+
def self.startup
|
12
|
+
Dir.chdir('test') if File.exist?('test')
|
13
|
+
File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@test_file = 'test_file1.txt'
|
18
|
+
|
19
|
+
@expected_middle1 = ["line10\n", "line11\n", "line12\n", "line13\n", "line14\n"]
|
20
|
+
@expected_middle1.push("line15\n","line16\n", "line17\n", "line18\n")
|
21
|
+
@expected_middle1.push("line19\n","line20\n")
|
22
|
+
|
23
|
+
@expected_middle2 = ["line14\n","line15\n","line16\n","line17\n"]
|
24
|
+
@expected_middle2.push("line18\n","line19\n","line20\n")
|
25
|
+
|
26
|
+
@expected_middle3 = ["line5\n","line6\n","line7\n"]
|
27
|
+
@expected_middle3.push("line8\n","line9\n","line10\n")
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_method_basic
|
31
|
+
assert_respond_to(File, :middle)
|
32
|
+
assert_nothing_raised{ File.middle(@test_file) }
|
33
|
+
assert_nothing_raised{ File.middle(@test_file, 14) }
|
34
|
+
assert_nothing_raised{ File.middle(@test_file, 5, 10) }
|
35
|
+
assert_nothing_raised{ File.middle(@test_file){} }
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_middle_expected_results
|
39
|
+
assert_kind_of(Array, File.middle(@test_file))
|
40
|
+
assert_equal(@expected_middle1, File.middle(@test_file))
|
41
|
+
assert_equal(@expected_middle2, File.middle(@test_file, 14))
|
42
|
+
assert_equal(@expected_middle3, File.middle(@test_file, 5, 10))
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_middle_expected_errors
|
46
|
+
assert_raises(ArgumentError){ File.middle }
|
47
|
+
assert_raises(ArgumentError){ File.middle(@test_file, 5, 10, 15) }
|
48
|
+
assert_raises(NoMethodError){ File.middle(@test_file, "foo") }
|
49
|
+
assert_raises(Errno::ENOENT){ File.middle("bogus") }
|
50
|
+
end
|
51
|
+
|
52
|
+
def teardown
|
53
|
+
@test_file = nil
|
54
|
+
@expected_middle1 = nil
|
55
|
+
@expected_middle2 = nil
|
56
|
+
@expected_middle3 = nil
|
57
|
+
end
|
61
58
|
end
|
data/test/test_nlconvert.rb
CHANGED
@@ -10,7 +10,7 @@ require 'ptools'
|
|
10
10
|
|
11
11
|
class TC_Ptools_NLConvert < Test::Unit::TestCase
|
12
12
|
def self.startup
|
13
|
-
Dir.chdir('test') if File.
|
13
|
+
Dir.chdir('test') if File.exist?('test')
|
14
14
|
@@test_file1 = 'test_nl_convert1.txt'
|
15
15
|
@@test_file2 = 'test_nl_convert2.txt'
|
16
16
|
File.open(@@test_file1, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
|
@@ -83,7 +83,7 @@ class TC_Ptools_NLConvert < Test::Unit::TestCase
|
|
83
83
|
|
84
84
|
def teardown
|
85
85
|
[@dos_file, @mac_file, @unix_file].each{ |file|
|
86
|
-
File.delete(file) if File.
|
86
|
+
File.delete(file) if File.exist?(file)
|
87
87
|
}
|
88
88
|
@dos_file = nil
|
89
89
|
@mac_file = nil
|
@@ -93,7 +93,7 @@ class TC_Ptools_NLConvert < Test::Unit::TestCase
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def self.shutdown
|
96
|
-
File.delete(@@test_file1) if File.
|
97
|
-
File.delete(@@test_file2) if File.
|
96
|
+
File.delete(@@test_file1) if File.exist?(@@test_file1)
|
97
|
+
File.delete(@@test_file2) if File.exist?(@@test_file2)
|
98
98
|
end
|
99
99
|
end
|
data/test/test_tail.rb
CHANGED
@@ -4,53 +4,50 @@
|
|
4
4
|
# Test case for the File.tail method. This test should be run via
|
5
5
|
# the 'rake test_tail' task.
|
6
6
|
#####################################################################
|
7
|
-
require '
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
7
|
+
require 'test-unit'
|
11
8
|
require 'ptools'
|
12
9
|
|
13
10
|
class TC_FileTail < Test::Unit::TestCase
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
11
|
+
def self.startup
|
12
|
+
Dir.chdir('test') if File.exist?('test')
|
13
|
+
File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@test_file = 'test_file1.txt'
|
18
|
+
|
19
|
+
@expected_tail1 = ["line16\n","line17\n","line18\n","line19\n"]
|
20
|
+
@expected_tail1.push("line20\n","line21\n","line22\n", "line23\n")
|
21
|
+
@expected_tail1.push("line24\n","line25\n")
|
22
|
+
|
23
|
+
@expected_tail2 = ["line21\n","line22\n","line23\n","line24\n","line25\n"]
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_tail_basic
|
27
|
+
assert_respond_to(File, :tail)
|
28
|
+
assert_nothing_raised{ File.tail(@test_file) }
|
29
|
+
assert_nothing_raised{ File.tail(@test_file, 5) }
|
30
|
+
assert_nothing_raised{ File.tail(@test_file){} }
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_tail_expected_return_values
|
34
|
+
assert_kind_of(Array, File.tail(@test_file))
|
35
|
+
assert_equal(@expected_tail1, File.tail(@test_file))
|
36
|
+
assert_equal(@expected_tail2, File.tail(@test_file, 5))
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_tail_expected_errors
|
40
|
+
assert_raises(ArgumentError){ File.tail }
|
41
|
+
assert_raises(ArgumentError){ File.tail(@test_file, 5, 5) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def teardown
|
45
|
+
@test_file = nil
|
46
|
+
@expected_tail1 = nil
|
47
|
+
@expected_tail2 = nil
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.shutdown
|
51
|
+
File.delete('test_file1.txt') if File.exist?('test_file1.txt')
|
52
|
+
end
|
56
53
|
end
|
data/test/test_touch.rb
CHANGED
@@ -1,55 +1,52 @@
|
|
1
1
|
#####################################################################
|
2
|
-
#
|
2
|
+
# test_touch.rb
|
3
3
|
#
|
4
4
|
# Test case for the File.touch method. This test should be run
|
5
5
|
# via the 'rake test_touch task'.
|
6
6
|
#####################################################################
|
7
|
-
require '
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
7
|
+
require 'test-unit'
|
11
8
|
require 'ptools'
|
12
9
|
|
13
10
|
class TC_FileTouch < Test::Unit::TestCase
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
11
|
+
def self.startup
|
12
|
+
Dir.chdir('test') if File.exist?('test')
|
13
|
+
File.open('test_file1.txt', 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@test_file = 'delete.this'
|
18
|
+
@xfile = 'test_file1.txt'
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_touch_basic
|
22
|
+
assert_respond_to(File, :touch)
|
23
|
+
assert_nothing_raised{ File.touch(@test_file) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_touch_expected_results
|
27
|
+
assert_equal(File, File.touch(@test_file))
|
28
|
+
assert_equal(true, File.exist?(@test_file))
|
29
|
+
assert_equal(0, File.size(@test_file))
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_touch_existing_file
|
33
|
+
stat = File.stat(@xfile)
|
34
|
+
sleep 1
|
35
|
+
assert_nothing_raised{ File.touch(@xfile) }
|
36
|
+
assert_equal(true, File.size(@xfile) == stat.size)
|
37
|
+
assert_equal(false, File.mtime(@xfile) == stat.mtime)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_touch_expected_errors
|
41
|
+
assert_raises(ArgumentError){ File.touch }
|
42
|
+
end
|
43
|
+
|
44
|
+
def teardown
|
45
|
+
File.delete(@test_file) if File.exist?(@test_file)
|
46
|
+
@test_file = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.shutdown
|
50
|
+
File.delete('test_file1.txt') if File.exist?('test_file1.txt')
|
51
|
+
end
|
55
52
|
end
|
data/test/test_wc.rb
CHANGED
@@ -4,20 +4,17 @@
|
|
4
4
|
# Test case for the File.wc method. This test should be run via
|
5
5
|
# the 'rake test_wc' task.
|
6
6
|
#####################################################################
|
7
|
-
require '
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
7
|
+
require 'test-unit'
|
11
8
|
require 'ptools'
|
12
9
|
|
13
10
|
class TC_FileWC < Test::Unit::TestCase
|
14
11
|
def self.startup
|
15
|
-
Dir.chdir('test') if File.
|
12
|
+
Dir.chdir('test') if File.exist?('test')
|
16
13
|
File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
|
17
14
|
@@test_file = 'test_file1.txt'
|
18
15
|
end
|
19
|
-
|
20
|
-
def setup
|
16
|
+
|
17
|
+
def setup
|
21
18
|
@test_file = 'test_file1.txt'
|
22
19
|
end
|
23
20
|
|
@@ -71,6 +68,6 @@ class TC_FileWC < Test::Unit::TestCase
|
|
71
68
|
end
|
72
69
|
|
73
70
|
def self.shutdown
|
74
|
-
File.delete(@@test_file) if File.
|
71
|
+
File.delete(@@test_file) if File.exist?(@@test_file)
|
75
72
|
end
|
76
73
|
end
|
data/test/test_which.rb
CHANGED
@@ -7,10 +7,7 @@
|
|
7
7
|
# NOTE: I make the assumption that Ruby (or JRuby) is in your
|
8
8
|
# PATH for these tests.
|
9
9
|
#####################################################################
|
10
|
-
require '
|
11
|
-
gem 'test-unit'
|
12
|
-
|
13
|
-
require 'test/unit'
|
10
|
+
require 'test-unit'
|
14
11
|
require 'rbconfig'
|
15
12
|
require 'fileutils'
|
16
13
|
require 'ptools'
|
@@ -21,7 +18,7 @@ class TC_FileWhich < Test::Unit::TestCase
|
|
21
18
|
@@dir = File.join(Dir.pwd, 'tempdir')
|
22
19
|
@@non_exe = File.join(Dir.pwd, 'tempfile')
|
23
20
|
|
24
|
-
Dir.mkdir(@@dir) unless File.
|
21
|
+
Dir.mkdir(@@dir) unless File.exist?(@@dir)
|
25
22
|
FileUtils.touch(@@non_exe)
|
26
23
|
File.chmod(775, @@dir)
|
27
24
|
File.chmod(644, @@non_exe)
|
metadata
CHANGED
@@ -1,55 +1,48 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ptools
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 2
|
9
|
-
- 2
|
10
|
-
version: 1.2.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.3
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Daniel J. Berger
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2014-02-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: test-unit
|
22
|
-
|
23
|
-
|
24
|
-
none: false
|
25
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
26
17
|
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 2
|
31
|
-
- 4
|
32
|
-
- 0
|
33
|
-
version: 2.4.0
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.5.0
|
34
20
|
type: :development
|
35
|
-
|
36
|
-
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.5.0
|
27
|
+
description: |2
|
28
|
+
The ptools (power tools) library provides several handy methods to
|
29
|
+
Ruby's core File class, such as File.which for finding executables,
|
30
|
+
File.null to return the null device on your platform, and so on.
|
37
31
|
email: djberg96@gmail.com
|
38
32
|
executables: []
|
39
|
-
|
40
33
|
extensions: []
|
41
|
-
|
42
|
-
extra_rdoc_files:
|
34
|
+
extra_rdoc_files:
|
43
35
|
- README
|
44
36
|
- CHANGES
|
45
37
|
- MANIFEST
|
46
|
-
files:
|
38
|
+
files:
|
39
|
+
- ".gemtest"
|
47
40
|
- CHANGES
|
48
|
-
- lib/ptools.rb
|
49
41
|
- MANIFEST
|
50
|
-
- ptools.gemspec
|
51
|
-
- Rakefile
|
52
42
|
- README
|
43
|
+
- Rakefile
|
44
|
+
- lib/ptools.rb
|
45
|
+
- ptools.gemspec
|
53
46
|
- test/test_binary.rb
|
54
47
|
- test/test_constants.rb
|
55
48
|
- test/test_head.rb
|
@@ -63,41 +56,31 @@ files:
|
|
63
56
|
- test/test_wc.rb
|
64
57
|
- test/test_whereis.rb
|
65
58
|
- test/test_which.rb
|
66
|
-
|
67
|
-
|
68
|
-
licenses:
|
59
|
+
homepage: https://github.com/djberg96/ptools
|
60
|
+
licenses:
|
69
61
|
- Artistic 2.0
|
62
|
+
metadata: {}
|
70
63
|
post_install_message:
|
71
64
|
rdoc_options: []
|
72
|
-
|
73
|
-
require_paths:
|
65
|
+
require_paths:
|
74
66
|
- lib
|
75
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
-
|
77
|
-
requirements:
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
78
69
|
- - ">="
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
version: "0"
|
84
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
-
none: false
|
86
|
-
requirements:
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
87
74
|
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
|
90
|
-
segments:
|
91
|
-
- 0
|
92
|
-
version: "0"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
93
77
|
requirements: []
|
94
|
-
|
95
78
|
rubyforge_project: shards
|
96
|
-
rubygems_version:
|
79
|
+
rubygems_version: 2.2.2
|
97
80
|
signing_key:
|
98
|
-
specification_version:
|
81
|
+
specification_version: 4
|
99
82
|
summary: Extra methods for the File class
|
100
|
-
test_files:
|
83
|
+
test_files:
|
101
84
|
- test/test_binary.rb
|
102
85
|
- test/test_constants.rb
|
103
86
|
- test/test_head.rb
|