ptools 1.1.9-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +105 -0
- data/MANIFEST +17 -0
- data/README +64 -0
- data/Rakefile +110 -0
- data/lib/ptools.rb +406 -0
- data/ptools.gemspec +31 -0
- data/test/test_binary.rb +43 -0
- data/test/test_constants.rb +32 -0
- data/test/test_head.rb +51 -0
- data/test/test_image.rb +43 -0
- data/test/test_middle.rb +61 -0
- data/test/test_nlconvert.rb +89 -0
- data/test/test_null.rb +37 -0
- data/test/test_tail.rb +56 -0
- data/test/test_touch.rb +55 -0
- data/test/test_wc.rb +50 -0
- data/test/test_whereis.rb +98 -0
- data/test/test_which.rb +109 -0
- metadata +104 -0
data/test/test_touch.rb
ADDED
@@ -0,0 +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
|
data/test/test_wc.rb
ADDED
@@ -0,0 +1,50 @@
|
|
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 'test/unit'
|
8
|
+
require 'ptools'
|
9
|
+
|
10
|
+
class TC_FileWC < Test::Unit::TestCase
|
11
|
+
def self.startup
|
12
|
+
Dir.chdir('test') if File.exists?('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
|
+
end
|
19
|
+
|
20
|
+
def test_wc_basic
|
21
|
+
assert_respond_to(File, :wc)
|
22
|
+
assert_nothing_raised{ File.wc(@test_file) }
|
23
|
+
assert_nothing_raised{ File.wc(@test_file, 'bytes') }
|
24
|
+
assert_nothing_raised{ File.wc(@test_file, 'chars') }
|
25
|
+
assert_nothing_raised{ File.wc(@test_file, 'words') }
|
26
|
+
assert_nothing_raised{ File.wc(@test_file, 'LINES') }
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_wc_results
|
30
|
+
assert_kind_of(Array, File.wc(@test_file))
|
31
|
+
assert_equal([166,166,25,25], File.wc(@test_file))
|
32
|
+
assert_equal(166, File.wc(@test_file,'bytes'), "Wrong number of bytes")
|
33
|
+
assert_equal(166, File.wc(@test_file,'chars'), "Wrong number of chars")
|
34
|
+
assert_equal(25, File.wc(@test_file,'words'), "Wrong number of words")
|
35
|
+
assert_equal(25, File.wc(@test_file,'lines'), "Wrong number of lines")
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_wc_expected_errors
|
39
|
+
assert_raises(ArgumentError){ File.wc }
|
40
|
+
assert_raises(ArgumentError){ File.wc(@test_file, "bogus") }
|
41
|
+
end
|
42
|
+
|
43
|
+
def teardown
|
44
|
+
@test_file = nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.shutdown
|
48
|
+
File.delete('test_file1.txt') if File.exists?('test_file1.txt')
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
######################################################################
|
2
|
+
# test_whereis.rb
|
3
|
+
#
|
4
|
+
# Tests for the File.whereis method.
|
5
|
+
######################################################################
|
6
|
+
require 'rubygems'
|
7
|
+
gem 'test-unit'
|
8
|
+
|
9
|
+
require 'test/unit'
|
10
|
+
require 'ptools'
|
11
|
+
require 'rbconfig'
|
12
|
+
include Config
|
13
|
+
|
14
|
+
class TC_FileWhereis < Test::Unit::TestCase
|
15
|
+
def self.startup
|
16
|
+
@@windows = Config::CONFIG['host_os'] =~ /mswin|win32|msdos|cygwin|mingw/i
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup
|
20
|
+
@expected_locs = [File.join(CONFIG['bindir'], 'ruby')]
|
21
|
+
|
22
|
+
if @@windows
|
23
|
+
@expected_locs[0] << '.exe'
|
24
|
+
@expected_locs[0].tr!("/", "\\")
|
25
|
+
end
|
26
|
+
|
27
|
+
unless @@windows
|
28
|
+
@expected_locs << '/usr/local/bin/ruby'
|
29
|
+
@expected_locs << '/opt/sfw/bin/ruby'
|
30
|
+
@expected_locs << '/opt/bin/ruby'
|
31
|
+
@expected_locs << '/usr/bin/ruby'
|
32
|
+
end
|
33
|
+
|
34
|
+
@actual_locs = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
test "whereis basic functionality" do
|
38
|
+
assert_respond_to(File, :whereis)
|
39
|
+
assert_nothing_raised{ File.whereis('ruby') }
|
40
|
+
assert_kind_of([Array, NilClass], File.whereis('ruby'))
|
41
|
+
end
|
42
|
+
|
43
|
+
test "whereis accepts an optional second argument" do
|
44
|
+
assert_nothing_raised{ File.whereis('ruby', '/usr/bin:/usr/local/bin') }
|
45
|
+
end
|
46
|
+
|
47
|
+
test "whereis returns expected values" do
|
48
|
+
assert_nothing_raised{ @actual_locs = File.whereis('ruby') }
|
49
|
+
assert_kind_of(Array, @actual_locs)
|
50
|
+
assert_true((@expected_locs & @actual_locs).size > 0)
|
51
|
+
end
|
52
|
+
|
53
|
+
test "whereis returns nil if program not found" do
|
54
|
+
assert_nil(File.whereis('xxxyyy'))
|
55
|
+
end
|
56
|
+
|
57
|
+
test "whereis returns nil if program cannot be found in provided path" do
|
58
|
+
assert_nil(File.whereis('ruby', '/foo/bar'))
|
59
|
+
end
|
60
|
+
|
61
|
+
test "whereis returns single element array or nil if absolute path is provided" do
|
62
|
+
absolute = File.join(CONFIG['bindir'], 'ruby')
|
63
|
+
absolute << '.exe' if @@windows
|
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
|
data/test/test_which.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
#####################################################################
|
2
|
+
# test_which.rb
|
3
|
+
#
|
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 (or JRuby) is in your
|
8
|
+
# PATH for these tests.
|
9
|
+
#####################################################################
|
10
|
+
require 'rubygems'
|
11
|
+
gem 'test-unit'
|
12
|
+
|
13
|
+
require 'test/unit'
|
14
|
+
require 'rbconfig'
|
15
|
+
require 'fileutils'
|
16
|
+
require 'ptools'
|
17
|
+
include Config
|
18
|
+
|
19
|
+
class TC_FileWhich < Test::Unit::TestCase
|
20
|
+
def self.startup
|
21
|
+
@@windows = Config::CONFIG['host_os'] =~ /mswin|msdos|win32|cygwin|mingw/i
|
22
|
+
@@dir = File.join(Dir.pwd, 'tempdir')
|
23
|
+
@@non_exe = File.join(Dir.pwd, 'tempfile')
|
24
|
+
|
25
|
+
Dir.mkdir(@@dir) unless File.exists?(@@dir)
|
26
|
+
FileUtils.touch(@@non_exe)
|
27
|
+
File.chmod(775, @@dir)
|
28
|
+
File.chmod(644, @@non_exe)
|
29
|
+
end
|
30
|
+
|
31
|
+
def setup
|
32
|
+
@ruby = RUBY_PLATFORM.match('java') ? 'jruby' : 'ruby'
|
33
|
+
@exe = File.join(CONFIG['bindir'], CONFIG['ruby_install_name'])
|
34
|
+
|
35
|
+
if @@windows
|
36
|
+
@exe.tr!('/','\\')
|
37
|
+
@exe << ".exe"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
test "which basic functionality" do
|
42
|
+
assert_respond_to(File, :which)
|
43
|
+
assert_nothing_raised{ File.which(@ruby) }
|
44
|
+
assert_kind_of(String, File.which(@ruby))
|
45
|
+
end
|
46
|
+
|
47
|
+
test "which accepts an optional path to search" do
|
48
|
+
assert_nothing_raised{ File.which(@ruby, "/usr/bin:/usr/local/bin") }
|
49
|
+
end
|
50
|
+
|
51
|
+
test "which returns nil if not found" do
|
52
|
+
assert_equal(nil, File.which(@ruby, '/bogus/path'))
|
53
|
+
assert_equal(nil, File.which('blahblahblah'))
|
54
|
+
end
|
55
|
+
|
56
|
+
test "which handles executables without extensions on windows" do
|
57
|
+
omit_unless(@@windows, "test skipped unless MS Windows")
|
58
|
+
assert_not_nil(File.which('ruby'))
|
59
|
+
assert_not_nil(File.which('notepad'))
|
60
|
+
end
|
61
|
+
|
62
|
+
test "which handles executables that already contain extensions on windows" do
|
63
|
+
omit_unless(@@windows, "test skipped unless MS Windows")
|
64
|
+
assert_not_nil(File.which('ruby.exe'))
|
65
|
+
assert_not_nil(File.which('notepad.exe'))
|
66
|
+
end
|
67
|
+
|
68
|
+
test "which returns argument if an existent absolute path is provided" do
|
69
|
+
assert_equal(@exe, File.which(@ruby))
|
70
|
+
end
|
71
|
+
|
72
|
+
test "which returns nil if a non-existent absolute path is provided" do
|
73
|
+
assert_nil(File.which('/foo/bar/baz/ruby'))
|
74
|
+
end
|
75
|
+
|
76
|
+
test "which does not pickup files that are not executable" do
|
77
|
+
assert_nil(File.which(@@non_exe))
|
78
|
+
end
|
79
|
+
|
80
|
+
test "which does not pickup executable directories" do
|
81
|
+
assert_nil(File.which(@@dir))
|
82
|
+
end
|
83
|
+
|
84
|
+
test "which accepts a minimum of one argument" do
|
85
|
+
assert_raises(ArgumentError){ File.which }
|
86
|
+
end
|
87
|
+
|
88
|
+
test "which accepts a maximum of two arguments" do
|
89
|
+
assert_raises(ArgumentError){ File.which(@ruby, "foo", "bar") }
|
90
|
+
end
|
91
|
+
|
92
|
+
test "the second argument cannot be nil or empty" do
|
93
|
+
assert_raises(ArgumentError){ File.which(@ruby, nil) }
|
94
|
+
assert_raises(ArgumentError){ File.which(@ruby, '') }
|
95
|
+
end
|
96
|
+
|
97
|
+
def teardown
|
98
|
+
@exe = nil
|
99
|
+
@ruby = nil
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.shutdown
|
103
|
+
FileUtils.rm(@@non_exe)
|
104
|
+
FileUtils.rm_rf(@@dir)
|
105
|
+
@@windows = nil
|
106
|
+
@@dir = nil
|
107
|
+
@@non_exe = nil
|
108
|
+
end
|
109
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ptools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.9
|
5
|
+
platform: x86-mingw32
|
6
|
+
authors:
|
7
|
+
- Daniel J. Berger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-03-25 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: test-unit
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.0.7
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: win32-file
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.5.4
|
34
|
+
version:
|
35
|
+
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"
|
36
|
+
email: djberg96@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README
|
43
|
+
- CHANGES
|
44
|
+
- MANIFEST
|
45
|
+
files:
|
46
|
+
- CHANGES
|
47
|
+
- lib/ptools.rb
|
48
|
+
- MANIFEST
|
49
|
+
- ptools.gemspec
|
50
|
+
- Rakefile
|
51
|
+
- README
|
52
|
+
- test/test_binary.rb
|
53
|
+
- test/test_constants.rb
|
54
|
+
- test/test_head.rb
|
55
|
+
- test/test_image.rb
|
56
|
+
- test/test_middle.rb
|
57
|
+
- test/test_nlconvert.rb
|
58
|
+
- test/test_null.rb
|
59
|
+
- test/test_tail.rb
|
60
|
+
- test/test_touch.rb
|
61
|
+
- test/test_wc.rb
|
62
|
+
- test/test_whereis.rb
|
63
|
+
- test/test_which.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://www.rubyforge.org/projects/shards
|
66
|
+
licenses:
|
67
|
+
- Artistic 2.0
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project: shards
|
88
|
+
rubygems_version: 1.3.5
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Extra methods for the File class
|
92
|
+
test_files:
|
93
|
+
- test/test_binary.rb
|
94
|
+
- test/test_constants.rb
|
95
|
+
- test/test_head.rb
|
96
|
+
- test/test_image.rb
|
97
|
+
- test/test_middle.rb
|
98
|
+
- test/test_nlconvert.rb
|
99
|
+
- test/test_null.rb
|
100
|
+
- test/test_tail.rb
|
101
|
+
- test/test_touch.rb
|
102
|
+
- test/test_wc.rb
|
103
|
+
- test/test_whereis.rb
|
104
|
+
- test/test_which.rb
|