ptools 1.1.1 → 1.1.2

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.
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.1.2 - 28-Apr-2007
2
+ * Fixed a require line that could cause problems on MS Windows.
3
+ * Added a Rakefile which includes tasks for installation and testing.
4
+ * Some cleanup and improvement in the various test files.
5
+
1
6
  == 1.1.1 - 24-Aug-2006
2
7
  * Added the File.binary? method, based on code from Ryan Davis.
3
8
 
data/README CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  == Prerequisites
6
6
  Ruby 1.8.0 or later is recommended but not required.
7
+ On MS Windows you will need win32-file 0.5.4 or later.
7
8
 
8
9
  == Installation
9
10
  === Gem
@@ -60,7 +61,7 @@
60
61
  Ruby's
61
62
 
62
63
  == Copyright
63
- (C) 2003-2006 Daniel J. Berger
64
+ (C) 2003-2007 Daniel J. Berger
64
65
  All Rights Reserved.
65
66
 
66
67
  == Warranty
@@ -70,5 +71,5 @@
70
71
 
71
72
  == Author
72
73
  Daniel J. Berger
73
- djberg96 at gmail dot com
74
+ djberg96 at nospam at gmail dot com
74
75
  imperator on IRC (irc.freenode.net)
data/Rakefile ADDED
@@ -0,0 +1,91 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ desc 'Install the ptools package (non-gem)'
5
+ task :install do
6
+ ruby 'install.rb'
7
+ end
8
+
9
+ Rake::TestTask.new do |t|
10
+ t.libs << 'test'
11
+ t.verbose = true
12
+ t.warning = true
13
+ t.test_files = FileList['test/ts_all.rb']
14
+ end
15
+
16
+ Rake::TestTask.new('test_binary') do |t|
17
+ t.libs << 'test'
18
+ t.verbose = true
19
+ t.warning = true
20
+ t.test_files = FileList['test/tc_binary.rb']
21
+ end
22
+
23
+ Rake::TestTask.new('test_constants') do |t|
24
+ t.libs << 'test'
25
+ t.verbose = true
26
+ t.warning = true
27
+ t.test_files = FileList['test/tc_constants.rb']
28
+ end
29
+
30
+ Rake::TestTask.new('test_head') do |t|
31
+ t.libs << 'test'
32
+ t.verbose = true
33
+ t.warning = true
34
+ t.test_files = FileList['test/tc_head.rb']
35
+ end
36
+
37
+ Rake::TestTask.new('test_middle') do |t|
38
+ t.libs << 'test'
39
+ t.verbose = true
40
+ t.warning = true
41
+ t.test_files = FileList['test/tc_middle.rb']
42
+ end
43
+
44
+ Rake::TestTask.new('test_nlconvert') do |t|
45
+ t.libs << 'test'
46
+ t.verbose = true
47
+ t.warning = true
48
+ t.test_files = FileList['test/tc_nlconvert.rb']
49
+ end
50
+
51
+ Rake::TestTask.new('test_null') do |t|
52
+ t.libs << 'test'
53
+ t.verbose = true
54
+ t.warning = true
55
+ t.test_files = FileList['test/tc_null.rb']
56
+ end
57
+
58
+ Rake::TestTask.new('test_tail') do |t|
59
+ t.libs << 'test'
60
+ t.verbose = true
61
+ t.warning = true
62
+ t.test_files = FileList['test/tc_tail.rb']
63
+ end
64
+
65
+ Rake::TestTask.new('test_touch') do |t|
66
+ t.libs << 'test'
67
+ t.verbose = true
68
+ t.warning = true
69
+ t.test_files = FileList['test/tc_touch.rb']
70
+ end
71
+
72
+ Rake::TestTask.new('test_wc') do |t|
73
+ t.libs << 'test'
74
+ t.verbose = true
75
+ t.warning = true
76
+ t.test_files = FileList['test/tc_wc.rb']
77
+ end
78
+
79
+ Rake::TestTask.new('test_whereis') do |t|
80
+ t.libs << 'test'
81
+ t.verbose = true
82
+ t.warning = true
83
+ t.test_files = FileList['test/tc_whereis.rb']
84
+ end
85
+
86
+ Rake::TestTask.new('test_which') do |t|
87
+ t.libs << 'test'
88
+ t.verbose = true
89
+ t.warning = true
90
+ t.test_files = FileList['test/tc_which.rb']
91
+ end
data/lib/ptools.rb CHANGED
@@ -1,7 +1,7 @@
1
- require 'win32/file/stat' if PLATFORM.match('mswin')
1
+ require 'win32/file' if RUBY_PLATFORM.match('mswin')
2
2
 
3
3
  class File
4
- PTOOLS_VERSION = '1.1.1'
4
+ PTOOLS_VERSION = '1.1.2'
5
5
  IS_WINDOWS = RUBY_PLATFORM.match('mswin') ? true : false
6
6
 
7
7
  WIN32EXTS = ENV['PATHEXT'].split(';').map{ |e| e.downcase } rescue %w/.exe .com .bat/
data/test/tc_binary.rb CHANGED
@@ -1,22 +1,15 @@
1
- ##########################################
1
+ #####################################################################
2
2
  # tc_binary.rb
3
3
  #
4
- # Test case for the File.binary? method.
5
- ##########################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == 'test' or base =~ /ptools/
9
- Dir.chdir('..') if base == 'test'
10
- $LOAD_PATH.unshift(Dir.pwd)
11
- $LOAD_PATH.unshift(Dir.pwd + '/lib')
12
- Dir.chdir('test') if Dir.pwd != 'test'
13
- end
14
-
4
+ # Test case for the File.binary? method. You should run this test
5
+ # via the 'rake test_binary' task.
6
+ #####################################################################
15
7
  require 'test/unit'
16
8
  require 'ptools'
17
9
 
18
10
  class TC_Binary < Test::Unit::TestCase
19
11
  def setup
12
+ Dir.chdir('test') unless File.basename(Dir.pwd) == 'test'
20
13
  @text_file = 'test_file1.txt'
21
14
  end
22
15
 
@@ -30,9 +23,10 @@ class TC_Binary < Test::Unit::TestCase
30
23
  end
31
24
 
32
25
  def test_binary_expected_errors
33
- assert_raises(Errno::ENOENT){ File.binary?('bogus') }
26
+ assert_raises(Errno::ENOENT, ArgumentError){ File.binary?('bogus') }
34
27
  end
35
28
 
36
29
  def teardown
30
+ @text_file = nil
37
31
  end
38
32
  end
data/test/tc_constants.rb CHANGED
@@ -1,23 +1,15 @@
1
- ##################################################
1
+ #####################################################################
2
2
  # tc_constants.rb
3
3
  #
4
- # Tests whatever constant that have been defined
5
- ##################################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == "test" or base =~ /ptools/
9
- Dir.chdir("..") if base == "test"
10
- $LOAD_PATH.unshift(Dir.pwd)
11
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
12
- Dir.chdir("test") if Dir.pwd != "test"
13
- end
14
-
15
- require "test/unit"
16
- require "ptools"
4
+ # Tests the constants that have been defined for our package. This
5
+ # test case should be run via the 'rake test_constants' task.
6
+ #####################################################################
7
+ require 'test/unit'
8
+ require 'ptools'
17
9
 
18
10
  class TC_Constants < Test::Unit::TestCase
19
11
  def test_version
20
- assert_equal("1.1.1", File::PTOOLS_VERSION, "Bad VERSION")
12
+ assert_equal("1.1.2", File::PTOOLS_VERSION)
21
13
  end
22
14
 
23
15
  def test_windows
data/test/tc_head.rb CHANGED
@@ -1,22 +1,15 @@
1
- ##########################################
1
+ ######################################################################
2
2
  # tc_head.rb
3
3
  #
4
- # Test case for the File.head method.
5
- ##########################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == "test" or base =~ /ptools/
9
- Dir.chdir("..") if base == "test"
10
- $LOAD_PATH.unshift(Dir.pwd)
11
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
12
- Dir.chdir("test") if Dir.pwd != "test"
13
- end
14
-
15
- require "test/unit"
16
- require "ptools"
4
+ # Test case for the File.head method. This test should be run via
5
+ # the 'rake test_head' task.
6
+ ######################################################################
7
+ require 'test/unit'
8
+ require 'ptools'
17
9
 
18
10
  class TC_FileHead < Test::Unit::TestCase
19
11
  def setup
12
+ Dir.chdir('test') unless File.basename(Dir.pwd) == 'test'
20
13
  @test_file = 'test_file1.txt'
21
14
 
22
15
  @expected_head1 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
data/test/tc_middle.rb CHANGED
@@ -1,22 +1,15 @@
1
- ##########################################
1
+ #####################################################################
2
2
  # tc_middle.rb
3
3
  #
4
- # Test case for the File.middle method
5
- ##########################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == "test" or base =~ /ptools/
9
- Dir.chdir("..") if base == "test"
10
- $LOAD_PATH.unshift(Dir.pwd)
11
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
12
- Dir.chdir("test") if Dir.pwd != "test"
13
- end
14
-
15
- require "test/unit"
16
- require "ptools"
4
+ # Test case for the File.middle method. You should run this test
5
+ # via the 'rake test_middle' task.
6
+ #####################################################################
7
+ require 'test/unit'
8
+ require 'ptools'
17
9
 
18
10
  class TC_FileMiddle < Test::Unit::TestCase
19
11
  def setup
12
+ Dir.chdir('test') unless File.basename(Dir.pwd) == 'test'
20
13
  @test_file = 'test_file1.txt'
21
14
 
22
15
  @expected_middle1 = ["line10\n", "line11\n", "line12\n", "line13\n", "line14\n"]
@@ -54,5 +47,8 @@ class TC_FileMiddle < Test::Unit::TestCase
54
47
 
55
48
  def teardown
56
49
  @test_file = nil
50
+ @expected_middle1 = nil
51
+ @expected_middle2 = nil
52
+ @expected_middle3 = nil
57
53
  end
58
54
  end
data/test/tc_nlconvert.rb CHANGED
@@ -1,22 +1,15 @@
1
- #############################################
1
+ #####################################################################
2
2
  # tc_nlconvert.rb
3
3
  #
4
- # Test case for the File.nl_convert method.
5
- #############################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == "test" or base =~ /ptools/
9
- Dir.chdir("..") if base == "test"
10
- $LOAD_PATH.unshift(Dir.pwd)
11
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
12
- Dir.chdir("test") if Dir.pwd != "test"
13
- end
14
-
15
- require "test/unit"
16
- require "ptools"
4
+ # Test case for the File.nl_convert method. You should run this
5
+ # test via the 'rake test_nlconvert' task.
6
+ #####################################################################
7
+ require 'test/unit'
8
+ require 'ptools'
17
9
 
18
10
  class TC_FileNLConvert < Test::Unit::TestCase
19
11
  def setup
12
+ Dir.chdir('test') unless File.basename(Dir.pwd) == 'test'
20
13
  @test_file1 = 'test_file1.txt'
21
14
  @test_file2 = 'test_file2.txt'
22
15
  @dos_file = 'dos_test_file.txt'
@@ -42,10 +35,10 @@ class TC_FileNLConvert < Test::Unit::TestCase
42
35
  end
43
36
 
44
37
  def test_nl_convert_to_mac
45
- if PLATFORM.match("mswin")
46
- msg = "test may fail on MS Windows"
38
+ if RUBY_PLATFORM.match("mswin")
39
+ msg = "** test may fail on MS Windows **"
47
40
  else
48
- msg = "mac file should be the same size (or larger), but isn't"
41
+ msg = "** mac file should be the same size (or larger), but isn't **"
49
42
  end
50
43
 
51
44
  assert_nothing_raised{ File.nl_convert(@test_file1, @mac_file, "mac") }
@@ -77,5 +70,10 @@ class TC_FileNLConvert < Test::Unit::TestCase
77
70
  [@dos_file, @mac_file, @unix_file].each{ |file|
78
71
  File.delete(file) if File.exists?(file)
79
72
  }
73
+ @dos_file = nil
74
+ @mac_file = nil
75
+ @unix_file = nil
76
+ @test_file1 = nil
77
+ @test_file2 = nil
80
78
  end
81
79
  end
data/test/tc_null.rb CHANGED
@@ -1,19 +1,11 @@
1
- ##########################################
1
+ #####################################################################
2
2
  # tc_null.rb
3
3
  #
4
- # Test case for the File.null method.
5
- ##########################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == "test" or base =~ /ptools/
9
- Dir.chdir("..") if base == "test"
10
- $LOAD_PATH.unshift(Dir.pwd)
11
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
12
- Dir.chdir("test") if Dir.pwd != "test"
13
- end
14
-
15
- require "test/unit"
16
- require "ptools"
4
+ # Test case for the File.null method. You should run this test via
5
+ # the 'rake test_null' task.
6
+ #####################################################################
7
+ require 'test/unit'
8
+ require 'ptools'
17
9
 
18
10
  class TC_Null < Test::Unit::TestCase
19
11
  def setup
data/test/tc_tail.rb CHANGED
@@ -1,22 +1,15 @@
1
- ########################################
1
+ #####################################################################
2
2
  # tc_tail.rb
3
3
  #
4
- # Test case for the File.tail method.
5
- ########################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == "test" or base =~ /ptools/
9
- Dir.chdir("..") if base == "test"
10
- $LOAD_PATH.unshift(Dir.pwd)
11
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
12
- Dir.chdir("test") if Dir.pwd != "test"
13
- end
14
-
15
- require "test/unit"
16
- require "ptools"
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'
17
9
 
18
10
  class TC_FileTail < Test::Unit::TestCase
19
11
  def setup
12
+ Dir.chdir('test') unless File.basename(Dir.pwd) == 'test'
20
13
  @test_file = 'test_file1.txt'
21
14
 
22
15
  @expected_tail1 = ["line16\n","line17\n","line18\n","line19\n"]
@@ -46,5 +39,7 @@ class TC_FileTail < Test::Unit::TestCase
46
39
 
47
40
  def teardown
48
41
  @test_file = nil
42
+ @expected_tail1 = nil
43
+ @expected_tail2 = nil
49
44
  end
50
45
  end
data/test/tc_touch.rb CHANGED
@@ -1,22 +1,15 @@
1
- ###########################################
1
+ #####################################################################
2
2
  # tc_touch.rb
3
3
  #
4
- # Test case for the File.touch method.
5
- ###########################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == "test" or base =~ /ptools/
9
- Dir.chdir("..") if base == "test"
10
- $LOAD_PATH.unshift(Dir.pwd)
11
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
12
- Dir.chdir("test") if Dir.pwd != "test"
13
- end
14
-
15
- require "test/unit"
16
- require "ptools"
4
+ # Test case for the File.touch method. This test should be run
5
+ # via the 'rake test_touch task'.
6
+ #####################################################################
7
+ require 'test/unit'
8
+ require 'ptools'
17
9
 
18
10
  class TC_FileTouch < Test::Unit::TestCase
19
11
  def setup
12
+ Dir.chdir('test') unless File.basename(Dir.pwd) == 'test'
20
13
  @test_file = "delete.this"
21
14
  end
22
15
 
@@ -37,5 +30,6 @@ class TC_FileTouch < Test::Unit::TestCase
37
30
 
38
31
  def teardown
39
32
  File.delete(@test_file) if File.exists?(@test_file)
33
+ @test_file = nil
40
34
  end
41
35
  end
data/test/tc_wc.rb CHANGED
@@ -1,22 +1,15 @@
1
- ####################################
1
+ #####################################################################
2
2
  # tc_wc.rb
3
3
  #
4
- # Test case for the File.wc method.
5
- ####################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == "test" or base =~ /ptools/
9
- Dir.chdir("..") if base == "test"
10
- $LOAD_PATH.unshift(Dir.pwd)
11
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
12
- Dir.chdir("test") if Dir.pwd != "test"
13
- end
14
-
15
- require "test/unit"
16
- require "ptools"
4
+ # Test case for the File.wc method. This test should be run via
5
+ # the 'rake test_wc' task.
6
+ #####################################################################
7
+ require 'test/unit'
8
+ require 'ptools'
17
9
 
18
10
  class TC_FileWC < Test::Unit::TestCase
19
11
  def setup
12
+ Dir.chdir('test') if File.exists?('test')
20
13
  @test_file = 'test_file1.txt'
21
14
  end
22
15
 
data/test/tc_whereis.rb CHANGED
@@ -1,30 +1,24 @@
1
- ##########################################
1
+ ######################################################################
2
2
  # tc_whereis.rb
3
3
  #
4
- # Test case for the File.whereis method.
5
- ##########################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == "test" or base =~ /ptools/
9
- Dir.chdir("..") if base == "test"
10
- $LOAD_PATH.unshift(Dir.pwd)
11
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
12
- Dir.chdir("test") if Dir.pwd != "test"
13
- end
14
-
15
- require "test/unit"
16
- require "ptools"
4
+ # Test case for the File.whereis method. This test should be run
5
+ # via the 'rake test_whereis' task.
6
+ ######################################################################
7
+ require 'test/unit'
8
+ require 'ptools'
9
+ require 'rbconfig'
10
+ include Config
17
11
 
18
12
  class TC_FileWhereis < Test::Unit::TestCase
19
-
20
13
  def setup
21
- # Change this to suit your system
22
- @expected_locs = ['/usr/local/bin/ruby','/opt/sfw/bin/ruby']
23
- @expected_locs.push('/opt/bin/ruby', '/usr/bin/ruby')
24
-
25
- # MS Windows - change as needed
26
- if File::ALT_SEPARATOR
14
+ @expected_locs = [CONFIG['bindir']]
15
+ if RUBY_PLATFORM.match('mswin')
27
16
  @expected_locs = ["c:\\ruby\\bin\\ruby.exe"]
17
+ else
18
+ @expected_locs << '/usr/local/bin/ruby'
19
+ @expected_locs << '/opt/sfw/bin/ruby'
20
+ @expected_locs << '/opt/bin/ruby'
21
+ @expected_locs << '/usr/bin/ruby'
28
22
  end
29
23
  end
30
24
 
@@ -45,7 +39,7 @@ class TC_FileWhereis < Test::Unit::TestCase
45
39
 
46
40
  def test_whereis_expected_errors
47
41
  assert_raises(ArgumentError){ File.whereis }
48
- assert_raises(ArgumentError){ File.whereis("ruby","foo","bar") }
42
+ assert_raises(ArgumentError){ File.whereis("ruby", "foo", "bar") }
49
43
  end
50
44
 
51
45
  def teardown
data/test/tc_which.rb CHANGED
@@ -1,30 +1,22 @@
1
- ########################################
1
+ #####################################################################
2
2
  # tc_which.rb
3
3
  #
4
- # Test case for the File.which method.
5
- ########################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == "test" or base =~ /ptools/
9
- Dir.chdir("..") if base == "test"
10
- $LOAD_PATH.unshift(Dir.pwd)
11
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
12
- Dir.chdir("test") if Dir.pwd != "test"
13
- end
14
-
15
- require 'rbconfig'
4
+ # Test case for the File.which method. You should run this test
5
+ # via the 'rake test_which' rake task.
6
+ #
7
+ # NOTE: I make the assumption that Ruby is in your PATH for these
8
+ # tests.
9
+ #####################################################################
16
10
  require 'test/unit'
11
+ require 'rbconfig'
17
12
  require 'ptools'
18
-
19
- # I make the assumption that Ruby is in your PATH for these tests
13
+ include Config
20
14
 
21
15
  class TC_FileWhich < Test::Unit::TestCase
22
- include Config
23
-
24
16
  def setup
25
17
  @exe = File.join(CONFIG["bindir"], CONFIG["ruby_install_name"])
26
18
 
27
- if File::ALT_SEPARATOR
19
+ if RUBY_PLATFORM.match('mswin')
28
20
  @exe.tr!('/','\\')
29
21
  @exe << ".exe"
30
22
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: ptools
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.1.1
7
- date: 2006-08-23 00:00:00 -06:00
6
+ version: 1.1.2
7
+ date: 2007-04-28 00:00:00 -06:00
8
8
  summary: Extra methods for the File class
9
9
  require_paths:
10
10
  - lib
@@ -32,6 +32,7 @@ files:
32
32
  - lib/ptools.rb
33
33
  - CHANGES
34
34
  - MANIFEST
35
+ - Rakefile
35
36
  - README
36
37
  - test/tc_binary.rb
37
38
  - test/tc_constants.rb
@@ -54,6 +55,7 @@ rdoc_options: []
54
55
  extra_rdoc_files:
55
56
  - README
56
57
  - CHANGES
58
+ - MANIFEST
57
59
  executables: []
58
60
 
59
61
  extensions: []