ptools 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +8 -0
- data/README +1 -1
- data/Rakefile +1 -1
- data/lib/ptools.rb +34 -33
- data/ptools.gemspec +4 -5
- data/test/test_binary.rb +39 -35
- data/test/test_constants.rb +24 -18
- data/test/test_is_sparse.rb +7 -3
- data/test/test_nlconvert.rb +2 -4
- data/test/test_whereis.rb +8 -9
- data/test/test_which.rb +5 -2
- metadata +30 -32
data/CHANGES
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 1.2.2 - 6-Apr-2012
|
2
|
+
* Yet another sparse file test fix for OSX, which does not support
|
3
|
+
sparse file generation on HFS+.
|
4
|
+
* Fixed a bug in the File.whereis method on Windows when dealing with
|
5
|
+
absolute paths.
|
6
|
+
* Some Config vs RbConfig fixes to silence 1.9.3 warnings.
|
7
|
+
* Refactored and cleaned up some tests.
|
8
|
+
|
1
9
|
== 1.2.1 - 20-May-2011
|
2
10
|
* Added an (empty) .gemtest file so that it can be used with test.rubygems.org.
|
3
11
|
* Fixed a sparse file test.
|
data/README
CHANGED
data/Rakefile
CHANGED
data/lib/ptools.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
require 'rbconfig'
|
2
|
-
|
3
|
-
if File::ALT_SEPARATOR
|
4
|
-
require 'win32/file'
|
5
|
-
end
|
2
|
+
require 'win32/file' if File::ALT_SEPARATOR
|
6
3
|
|
7
4
|
class File
|
8
5
|
# The version of the ptools library.
|
9
|
-
PTOOLS_VERSION = '1.2.
|
6
|
+
PTOOLS_VERSION = '1.2.2'
|
10
7
|
|
11
8
|
# :stopdoc:
|
12
9
|
|
@@ -22,7 +19,7 @@ class File
|
|
22
19
|
MSWINDOWS = false
|
23
20
|
end
|
24
21
|
|
25
|
-
IMAGE_EXT = %w
|
22
|
+
IMAGE_EXT = %w[.bmp .gif .jpg .jpeg .png]
|
26
23
|
|
27
24
|
# :startdoc:
|
28
25
|
|
@@ -62,7 +59,7 @@ class File
|
|
62
59
|
# http://en.wikipedia.org/wiki//dev/null
|
63
60
|
#
|
64
61
|
def self.null
|
65
|
-
case
|
62
|
+
case RbConfig::CONFIG['host_os']
|
66
63
|
when /mswin|win32|msdos|cygwin|mingw|windows/i
|
67
64
|
'NUL'
|
68
65
|
when /amiga/i
|
@@ -170,9 +167,14 @@ class File
|
|
170
167
|
# Bail out early if an absolute path is provided.
|
171
168
|
if program =~ /^\/|^[a-z]:[\\\/]/i
|
172
169
|
program += WIN32EXTS if MSWINDOWS && File.extname(program).empty?
|
170
|
+
program = program.tr("\\", '/') if MSWINDOWS
|
173
171
|
found = Dir[program]
|
174
172
|
if found[0] && File.executable?(found[0]) && !File.directory?(found[0])
|
175
|
-
|
173
|
+
if File::ALT_SEPARATOR
|
174
|
+
return found.map{ |f| f.tr('/', "\\") }
|
175
|
+
else
|
176
|
+
return found
|
177
|
+
end
|
176
178
|
else
|
177
179
|
return nil
|
178
180
|
end
|
@@ -273,21 +275,22 @@ class File
|
|
273
275
|
# ArgumentError is raised.
|
274
276
|
#
|
275
277
|
def self.nl_convert(old_file, new_file = old_file, platform = 'dos')
|
276
|
-
unless File.
|
278
|
+
unless File::Stat.new(old_file).file?
|
277
279
|
raise ArgumentError, 'Only valid for plain text files'
|
278
280
|
end
|
279
281
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
282
|
+
case platform
|
283
|
+
when /dos|windows|win32|mswin|cygwin|mingw/i
|
284
|
+
format = "\cM\cJ"
|
285
|
+
when /unix|linux|bsd/i
|
286
|
+
format = "\cJ"
|
287
|
+
when /mac|apple|macintosh|osx/i
|
288
|
+
format = "\cM"
|
289
|
+
else
|
290
|
+
raise ArgumentError, "Invalid platform string"
|
288
291
|
end
|
289
292
|
|
290
|
-
orig = $\
|
293
|
+
orig = $\ # AKA $OUTPUT_RECORD_SEPARATOR
|
291
294
|
$\ = format
|
292
295
|
|
293
296
|
if old_file == new_file
|
@@ -390,21 +393,19 @@ class File
|
|
390
393
|
end
|
391
394
|
end
|
392
395
|
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
stats.size > stats.blocks * 512
|
407
|
-
end
|
396
|
+
# Already provided by win32-file on MS Windows
|
397
|
+
unless respond_to?(:sparse?)
|
398
|
+
# Returns whether or not +file+ is a sparse file.
|
399
|
+
#
|
400
|
+
# A sparse file is a any file where its size is greater than the number
|
401
|
+
# of 512k blocks it consumes, i.e. its apparent and actual file size is
|
402
|
+
# not the same.
|
403
|
+
#
|
404
|
+
# See http://en.wikipedia.org/wiki/Sparse_file for more information.
|
405
|
+
#
|
406
|
+
def self.sparse?(file)
|
407
|
+
stats = File.stat(file)
|
408
|
+
stats.size > stats.blocks * 512
|
408
409
|
end
|
409
410
|
end
|
410
411
|
|
data/ptools.gemspec
CHANGED
@@ -3,14 +3,13 @@ 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.2'
|
7
7
|
gem.license = 'Artistic 2.0'
|
8
8
|
gem.author = 'Daniel J. Berger'
|
9
9
|
gem.email = 'djberg96@gmail.com'
|
10
10
|
gem.homepage = 'http://www.rubyforge.org/projects/shards'
|
11
11
|
gem.summary = 'Extra methods for the File class'
|
12
12
|
gem.test_files = Dir['test/test*']
|
13
|
-
gem.has_rdoc = true
|
14
13
|
gem.files = Dir['**/*'] << '.gemtest'
|
15
14
|
|
16
15
|
gem.rubyforge_project = 'shards'
|
@@ -22,10 +21,10 @@ Gem::Specification.new do |gem|
|
|
22
21
|
File.null to return the null device on your platform, and so on.
|
23
22
|
EOF
|
24
23
|
|
25
|
-
gem.add_development_dependency('test-unit', '>= 2.0
|
24
|
+
gem.add_development_dependency('test-unit', '>= 2.4.0')
|
26
25
|
|
27
|
-
if
|
28
|
-
gem.platform = Gem::Platform
|
26
|
+
if File::ALT_SEPARATOR
|
27
|
+
gem.platform = Gem::Platform.new(['universal', 'mingw32'])
|
29
28
|
gem.add_dependency('win32-file', '>= 0.5.4')
|
30
29
|
end
|
31
30
|
end
|
data/test/test_binary.rb
CHANGED
@@ -1,43 +1,47 @@
|
|
1
1
|
#####################################################################
|
2
|
-
#
|
3
|
-
#
|
2
|
+
# test_binary.rb
|
3
|
+
#
|
4
4
|
# Test case for the File.binary? method. You should run this test
|
5
5
|
# via the 'rake test_binary' task.
|
6
6
|
#####################################################################
|
7
7
|
require 'rubygems'
|
8
|
-
|
9
|
-
|
10
|
-
require 'test/unit'
|
8
|
+
require 'test-unit'
|
11
9
|
require 'ptools'
|
12
10
|
|
13
|
-
class
|
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
|
-
|
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
|
43
47
|
end
|
data/test/test_constants.rb
CHANGED
@@ -5,28 +5,34 @@
|
|
5
5
|
# test case should be run via the 'rake test_constants' task.
|
6
6
|
#####################################################################
|
7
7
|
require 'rubygems'
|
8
|
-
|
9
|
-
|
10
|
-
require 'test/unit'
|
8
|
+
require 'test-unit'
|
11
9
|
require 'rbconfig'
|
12
10
|
require 'ptools'
|
13
11
|
|
14
|
-
class
|
15
|
-
|
16
|
-
|
17
|
-
|
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.2', 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
|
18
24
|
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
22
29
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
27
34
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
35
|
+
def self.shutdown
|
36
|
+
@@windows = nil
|
37
|
+
end
|
32
38
|
end
|
data/test/test_is_sparse.rb
CHANGED
@@ -13,17 +13,20 @@ require 'ptools'
|
|
13
13
|
class TC_IsSparse < Test::Unit::TestCase
|
14
14
|
def self.startup
|
15
15
|
Dir.chdir("test") if File.exists?("test")
|
16
|
-
@@win =
|
17
|
-
@@osx =
|
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
|
18
19
|
end
|
19
20
|
|
20
21
|
def setup
|
21
|
-
@sparse_file = '/var/log/lastlog'
|
22
|
+
@sparse_file = @@sun ? '/var/adm/lastlog' : '/var/log/lastlog'
|
22
23
|
@non_sparse_file = File.expand_path(File.basename(__FILE__))
|
23
24
|
end
|
24
25
|
|
25
26
|
test "is_sparse basic functionality" do
|
26
27
|
omit_if(@@win, "File.sparse? tests skipped on MS Windows")
|
28
|
+
omit_if(@@osx, "File.sparse? tests skipped on OS X")
|
29
|
+
|
27
30
|
assert_respond_to(File, :sparse?)
|
28
31
|
assert_nothing_raised{ File.sparse?(@sparse_file) }
|
29
32
|
assert_boolean(File.sparse?(@sparse_file))
|
@@ -32,6 +35,7 @@ class TC_IsSparse < Test::Unit::TestCase
|
|
32
35
|
test "is_sparse returns the expected results" do
|
33
36
|
omit_if(@@win, "File.sparse? tests skipped on MS Windows")
|
34
37
|
omit_if(@@osx, "File.sparse? tests skipped on OS X")
|
38
|
+
|
35
39
|
assert_true(File.sparse?(@sparse_file))
|
36
40
|
assert_false(File.sparse?(@non_sparse_file))
|
37
41
|
end
|
data/test/test_nlconvert.rb
CHANGED
@@ -5,12 +5,10 @@
|
|
5
5
|
# test via the 'rake test_nlconvert' task.
|
6
6
|
#####################################################################
|
7
7
|
require 'rubygems'
|
8
|
-
|
9
|
-
|
10
|
-
require 'test/unit'
|
8
|
+
require 'test-unit'
|
11
9
|
require 'ptools'
|
12
10
|
|
13
|
-
class
|
11
|
+
class TC_Ptools_NLConvert < Test::Unit::TestCase
|
14
12
|
def self.startup
|
15
13
|
Dir.chdir('test') if File.exists?('test')
|
16
14
|
@@test_file1 = 'test_nl_convert1.txt'
|
data/test/test_whereis.rb
CHANGED
@@ -4,27 +4,25 @@
|
|
4
4
|
# Tests for the File.whereis method.
|
5
5
|
######################################################################
|
6
6
|
require 'rubygems'
|
7
|
-
|
8
|
-
|
9
|
-
require 'test/unit'
|
7
|
+
require 'test-unit'
|
10
8
|
require 'ptools'
|
11
9
|
require 'rbconfig'
|
12
|
-
include Config
|
13
10
|
|
14
|
-
class
|
11
|
+
class TC_Ptools_Whereis < Test::Unit::TestCase
|
15
12
|
def self.startup
|
16
|
-
@@windows =
|
13
|
+
@@windows = File::ALT_SEPARATOR
|
17
14
|
@@ruby = RUBY_PLATFORM == 'java' ? 'jruby' : 'ruby'
|
18
15
|
end
|
19
16
|
|
20
17
|
def setup
|
21
|
-
@
|
18
|
+
@bin_dir = RbConfig::CONFIG['bindir']
|
19
|
+
@expected_locs = [File.join(@bin_dir, @@ruby)]
|
22
20
|
|
23
21
|
if @@windows
|
24
22
|
@expected_locs[0] << '.exe'
|
25
23
|
@expected_locs[0].tr!("/", "\\")
|
26
24
|
end
|
27
|
-
|
25
|
+
|
28
26
|
unless @@windows
|
29
27
|
@expected_locs << "/usr/local/bin/#{@@ruby}"
|
30
28
|
@expected_locs << "/opt/sfw/bin/#{@@ruby}"
|
@@ -60,8 +58,9 @@ class TC_FileWhereis < Test::Unit::TestCase
|
|
60
58
|
end
|
61
59
|
|
62
60
|
test "whereis returns single element array or nil if absolute path is provided" do
|
63
|
-
absolute = File.join(
|
61
|
+
absolute = File.join(@bin_dir, @@ruby)
|
64
62
|
absolute << '.exe' if @@windows
|
63
|
+
|
65
64
|
assert_equal([absolute], File.whereis(absolute))
|
66
65
|
assert_nil(File.whereis("/foo/bar/baz/#{@@ruby}"))
|
67
66
|
end
|
data/test/test_which.rb
CHANGED
@@ -17,7 +17,7 @@ require 'ptools'
|
|
17
17
|
|
18
18
|
class TC_FileWhich < Test::Unit::TestCase
|
19
19
|
def self.startup
|
20
|
-
@@windows =
|
20
|
+
@@windows = File::ALT_SEPARATOR
|
21
21
|
@@dir = File.join(Dir.pwd, 'tempdir')
|
22
22
|
@@non_exe = File.join(Dir.pwd, 'tempfile')
|
23
23
|
|
@@ -31,7 +31,10 @@ class TC_FileWhich < Test::Unit::TestCase
|
|
31
31
|
@ruby = RUBY_PLATFORM.match('java') ? 'jruby' : 'ruby'
|
32
32
|
@ruby = 'rbx' if defined?(Rubinius)
|
33
33
|
|
34
|
-
@exe = File.join(
|
34
|
+
@exe = File.join(
|
35
|
+
RbConfig::CONFIG['bindir'],
|
36
|
+
RbConfig::CONFIG['ruby_install_name']
|
37
|
+
)
|
35
38
|
|
36
39
|
if @@windows
|
37
40
|
@exe.tr!('/','\\')
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ptools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 2
|
10
|
+
version: 1.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel J. Berger
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
18
|
+
date: 2012-04-06 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: test-unit
|
@@ -26,12 +25,12 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
28
|
+
hash: 31
|
30
29
|
segments:
|
31
30
|
- 2
|
31
|
+
- 4
|
32
32
|
- 0
|
33
|
-
|
34
|
-
version: 2.0.7
|
33
|
+
version: 2.4.0
|
35
34
|
type: :development
|
36
35
|
version_requirements: *id001
|
37
36
|
description: " The ptools (power tools) library provides several handy methods to\n Ruby's core File class, such as File.which for finding executables,\n File.null to return the null device on your platform, and so on.\n"
|
@@ -45,27 +44,26 @@ extra_rdoc_files:
|
|
45
44
|
- CHANGES
|
46
45
|
- MANIFEST
|
47
46
|
files:
|
47
|
+
- CHANGES
|
48
|
+
- lib/ptools.rb
|
49
|
+
- MANIFEST
|
50
|
+
- ptools.gemspec
|
48
51
|
- Rakefile
|
49
52
|
- README
|
50
|
-
- ptools.gemspec
|
51
|
-
- lib/ptools.rb
|
52
|
-
- CHANGES
|
53
|
-
- test/test_whereis.rb
|
54
|
-
- test/test_middle.rb
|
55
53
|
- test/test_binary.rb
|
56
|
-
- test/
|
57
|
-
- test/test_touch.rb
|
58
|
-
- test/test_which.rb
|
59
|
-
- test/test_null.rb
|
54
|
+
- test/test_constants.rb
|
60
55
|
- test/test_head.rb
|
61
|
-
- test/test_is_sparse.rb
|
62
|
-
- test/test_wc.rb
|
63
56
|
- test/test_image.rb
|
64
|
-
- test/
|
57
|
+
- test/test_is_sparse.rb
|
58
|
+
- test/test_middle.rb
|
59
|
+
- test/test_nlconvert.rb
|
60
|
+
- test/test_null.rb
|
65
61
|
- test/test_tail.rb
|
66
|
-
-
|
62
|
+
- test/test_touch.rb
|
63
|
+
- test/test_wc.rb
|
64
|
+
- test/test_whereis.rb
|
65
|
+
- test/test_which.rb
|
67
66
|
- .gemtest
|
68
|
-
has_rdoc: true
|
69
67
|
homepage: http://www.rubyforge.org/projects/shards
|
70
68
|
licenses:
|
71
69
|
- Artistic 2.0
|
@@ -95,21 +93,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
93
|
requirements: []
|
96
94
|
|
97
95
|
rubyforge_project: shards
|
98
|
-
rubygems_version: 1.
|
96
|
+
rubygems_version: 1.8.10
|
99
97
|
signing_key:
|
100
98
|
specification_version: 3
|
101
99
|
summary: Extra methods for the File class
|
102
100
|
test_files:
|
103
|
-
- test/test_whereis.rb
|
104
|
-
- test/test_middle.rb
|
105
101
|
- test/test_binary.rb
|
106
|
-
- test/
|
107
|
-
- test/test_touch.rb
|
108
|
-
- test/test_which.rb
|
109
|
-
- test/test_null.rb
|
102
|
+
- test/test_constants.rb
|
110
103
|
- test/test_head.rb
|
111
|
-
- test/test_is_sparse.rb
|
112
|
-
- test/test_wc.rb
|
113
104
|
- test/test_image.rb
|
114
|
-
- test/
|
105
|
+
- test/test_is_sparse.rb
|
106
|
+
- test/test_middle.rb
|
107
|
+
- test/test_nlconvert.rb
|
108
|
+
- test/test_null.rb
|
115
109
|
- test/test_tail.rb
|
110
|
+
- test/test_touch.rb
|
111
|
+
- test/test_wc.rb
|
112
|
+
- test/test_whereis.rb
|
113
|
+
- test/test_which.rb
|