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 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
@@ -53,7 +53,7 @@
53
53
  Artistic 2.0
54
54
 
55
55
  == Copyright
56
- (C) 2003-2011 Daniel J. Berger
56
+ (C) 2003-2012 Daniel J. Berger
57
57
  All Rights Reserved.
58
58
 
59
59
  == Warranty
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rake'
2
2
  require 'rake/clean'
3
3
  require 'rake/testtask'
4
4
  require 'rbconfig'
5
- include Config
5
+ include RbConfig
6
6
 
7
7
  CLEAN.include("**/*.gem", "**/*.rbc", "**/*coverage*")
8
8
 
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.1'
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/.bmp .gif .jpg .jpeg .png/
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 Config::CONFIG['host_os']
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
- return found
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.file?(old_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
- if platform =~ /dos|windows|win32|mswin|cygwin|mingw/i
281
- format = "\cM\cJ"
282
- elsif platform =~ /unix|linux|bsd/i
283
- format = "\cJ"
284
- elsif platform =~ /mac|apple|macintosh|osx/i
285
- format = "\cM"
286
- else
287
- raise ArgumentError, "Invalid platform string"
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
- class << self
394
- # Already provided by win32-file on MS Windows
395
- unless respond_to?(:sparse?)
396
- # Returns whether or not +file+ is a sparse file.
397
- #
398
- # A sparse file is a any file where its size is greater than the number
399
- # of 512k blocks it consumes, i.e. its apparent and actual file size is
400
- # not the same.
401
- #
402
- # See http://en.wikipedia.org/wiki/Sparse_file for more information.
403
- #
404
- def sparse?(file)
405
- stats = File.stat(file)
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.1'
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.7')
24
+ gem.add_development_dependency('test-unit', '>= 2.4.0')
26
25
 
27
- if Config::CONFIG['host_os'] =~ /mswin|win32|msdos|cygwin|mingw|windows/i
28
- gem.platform = Gem::Platform::CURRENT
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
- # tc_binary.rb
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
- gem 'test-unit'
9
-
10
- require 'test/unit'
8
+ require 'test-unit'
11
9
  require 'ptools'
12
10
 
13
- class TC_Binary < 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
- @text_file = 'test_file1.txt'
21
- end
22
-
23
- def test_binary_basic
24
- assert_respond_to(File, :binary?)
25
- assert_nothing_raised{ File.binary?(@text_file) }
26
- end
27
-
28
- def test_binary_expected_results
29
- assert_equal(false, File.binary?(@text_file))
30
- end
31
-
32
- def test_binary_expected_errors
33
- assert_raise_kind_of(SystemCallError){ File.binary?('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
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
@@ -5,28 +5,34 @@
5
5
  # test case should be run via the 'rake test_constants' task.
6
6
  #####################################################################
7
7
  require 'rubygems'
8
- gem 'test-unit'
9
-
10
- require 'test/unit'
8
+ require 'test-unit'
11
9
  require 'rbconfig'
12
10
  require 'ptools'
13
11
 
14
- class TC_Constants < Test::Unit::TestCase
15
- def test_version
16
- assert_equal('1.2.1', File::PTOOLS_VERSION)
17
- end
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
- def test_image_ext
20
- assert_equal(%w/.bmp .gif .jpeg .jpg .png/, File::IMAGE_EXT.sort)
21
- end
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
- def test_windows
24
- omit_unless(Config::CONFIG['host_os'].match('mswin'), "Skipping on Unix systems")
25
- assert_not_nil(File::IS_WINDOWS)
26
- end
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
- def test_win32exts
29
- omit_unless(Config::CONFIG['host_os'].match('mswin'), "Skipping on Unix systems")
30
- assert_not_nil(File::WIN32EXTS)
31
- end
35
+ def self.shutdown
36
+ @@windows = nil
37
+ end
32
38
  end
@@ -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 = Config::CONFIG['host_os'] =~ /windows|mswin|dos|cygwin|mingw/i
17
- @@osx = Config::CONFIG['host_os'] =~ /darwin|osx/i
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
@@ -5,12 +5,10 @@
5
5
  # test via the 'rake test_nlconvert' task.
6
6
  #####################################################################
7
7
  require 'rubygems'
8
- gem 'test-unit'
9
-
10
- require 'test/unit'
8
+ require 'test-unit'
11
9
  require 'ptools'
12
10
 
13
- class TC_FileNLConvert < Test::Unit::TestCase
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
- gem 'test-unit'
8
-
9
- require 'test/unit'
7
+ require 'test-unit'
10
8
  require 'ptools'
11
9
  require 'rbconfig'
12
- include Config
13
10
 
14
- class TC_FileWhereis < Test::Unit::TestCase
11
+ class TC_Ptools_Whereis < Test::Unit::TestCase
15
12
  def self.startup
16
- @@windows = Config::CONFIG['host_os'] =~ /mswin|win32|msdos|cygwin|mingw/i
13
+ @@windows = File::ALT_SEPARATOR
17
14
  @@ruby = RUBY_PLATFORM == 'java' ? 'jruby' : 'ruby'
18
15
  end
19
16
 
20
17
  def setup
21
- @expected_locs = [File.join(CONFIG['bindir'], @@ruby)]
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(CONFIG['bindir'], @@ruby)
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 = Config::CONFIG['host_os'] =~ /mswin|msdos|win32|cygwin|mingw/i
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(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
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: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 1
10
- version: 1.2.1
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: 2011-05-20 00:00:00 -06:00
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: 1
28
+ hash: 31
30
29
  segments:
31
30
  - 2
31
+ - 4
32
32
  - 0
33
- - 7
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/test_nlconvert.rb
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/test_constants.rb
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
- - MANIFEST
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.6.2
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/test_nlconvert.rb
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/test_constants.rb
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