ptools 1.2.6-universal-mingw32 → 1.2.7-universal-mingw32
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 +13 -5
 - data/CHANGES +154 -146
 - data/Gemfile +12 -12
 - data/MANIFEST +3 -0
 - data/README +64 -64
 - data/Rakefile +142 -142
 - data/lib/ptools.rb +465 -431
 - data/ptools.gemspec +30 -30
 - data/test/test_binary.rb +65 -65
 - data/test/test_constants.rb +38 -38
 - data/test/test_head.rb +48 -48
 - data/test/test_image.rb +57 -57
 - data/test/test_is_sparse.rb +53 -53
 - data/test/test_middle.rb +58 -58
 - data/test/test_nlconvert.rb +110 -99
 - data/test/test_tail.rb +53 -53
 - data/test/test_touch.rb +52 -52
 - data/test/test_wc.rb +73 -73
 - data/test/test_which.rb +126 -110
 - data/test/txt/english.txt +1 -1
 - data/test/txt/korean.txt +1 -1
 - metadata +14 -15
 
    
        data/test/test_touch.rb
    CHANGED
    
    | 
         @@ -1,52 +1,52 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #####################################################################
         
     | 
| 
       2 
     | 
    
         
            -
            # test_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 'test-unit'
         
     | 
| 
       8 
     | 
    
         
            -
            require 'ptools'
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
            class TC_FileTouch < Test::Unit::TestCase
         
     | 
| 
       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
         
     | 
| 
       52 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            #####################################################################
         
     | 
| 
      
 2 
     | 
    
         
            +
            # test_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 'test-unit'
         
     | 
| 
      
 8 
     | 
    
         
            +
            require 'ptools'
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            class TC_FileTouch < Test::Unit::TestCase
         
     | 
| 
      
 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
         
     | 
| 
      
 52 
     | 
    
         
            +
            end
         
     | 
    
        data/test/test_wc.rb
    CHANGED
    
    | 
         @@ -1,73 +1,73 @@ 
     | 
|
| 
       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.exist?('test')
         
     | 
| 
       13 
     | 
    
         
            -
                File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
         
     | 
| 
       14 
     | 
    
         
            -
                @@test_file = 'test_file1.txt'
         
     | 
| 
       15 
     | 
    
         
            -
              end
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
              def setup
         
     | 
| 
       18 
     | 
    
         
            -
                @test_file = 'test_file1.txt'
         
     | 
| 
       19 
     | 
    
         
            -
              end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
              test "wc method basic functionality" do
         
     | 
| 
       22 
     | 
    
         
            -
                assert_respond_to(File, :wc)
         
     | 
| 
       23 
     | 
    
         
            -
                assert_nothing_raised{ File.wc(@test_file) }
         
     | 
| 
       24 
     | 
    
         
            -
              end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
              test "wc accepts specific optional arguments" do
         
     | 
| 
       27 
     | 
    
         
            -
                assert_nothing_raised{ File.wc(@test_file, 'bytes') }
         
     | 
| 
       28 
     | 
    
         
            -
                assert_nothing_raised{ File.wc(@test_file, 'chars') }
         
     | 
| 
       29 
     | 
    
         
            -
                assert_nothing_raised{ File.wc(@test_file, 'words') }
         
     | 
| 
       30 
     | 
    
         
            -
                assert_nothing_raised{ File.wc(@test_file, 'lines') }
         
     | 
| 
       31 
     | 
    
         
            -
              end
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
              test "argument to wc ignores the case of the option argument" do
         
     | 
| 
       34 
     | 
    
         
            -
                assert_nothing_raised{ File.wc(@test_file, 'LINES') }
         
     | 
| 
       35 
     | 
    
         
            -
              end
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
              test "wc with no option returns expected results" do
         
     | 
| 
       38 
     | 
    
         
            -
                assert_kind_of(Array, File.wc(@test_file))
         
     | 
| 
       39 
     | 
    
         
            -
                assert_equal([166,166,25,25], File.wc(@test_file))
         
     | 
| 
       40 
     | 
    
         
            -
              end
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
              test "wc with bytes option returns the expected result" do
         
     | 
| 
       43 
     | 
    
         
            -
                assert_equal(166, File.wc(@test_file, 'bytes'), "Wrong number of bytes")
         
     | 
| 
       44 
     | 
    
         
            -
              end
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
              test "wc with chars option returns the expected result" do
         
     | 
| 
       47 
     | 
    
         
            -
                assert_equal(166, File.wc(@test_file, 'chars'), "Wrong number of chars")
         
     | 
| 
       48 
     | 
    
         
            -
              end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
              test "wc with words option returns the expected result" do
         
     | 
| 
       51 
     | 
    
         
            -
                assert_equal(25, File.wc(@test_file, 'words'), "Wrong number of words")
         
     | 
| 
       52 
     | 
    
         
            -
              end
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
              test "wc with lines option returns the expected result" do
         
     | 
| 
       55 
     | 
    
         
            -
                assert_equal(25, File.wc(@test_file, 'lines'), "Wrong number of lines")
         
     | 
| 
       56 
     | 
    
         
            -
              end
         
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
              test "wc requires at least on argument" do
         
     | 
| 
       59 
     | 
    
         
            -
                assert_raises(ArgumentError){ File.wc }
         
     | 
| 
       60 
     | 
    
         
            -
              end
         
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
              test "an invalid option raises an error" do
         
     | 
| 
       63 
     | 
    
         
            -
                assert_raises(ArgumentError){ File.wc(@test_file, 'bogus') }
         
     | 
| 
       64 
     | 
    
         
            -
              end
         
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
              def teardown
         
     | 
| 
       67 
     | 
    
         
            -
                @test_file = nil
         
     | 
| 
       68 
     | 
    
         
            -
              end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
              def self.shutdown
         
     | 
| 
       71 
     | 
    
         
            -
                File.delete(@@test_file) if File.exist?(@@test_file)
         
     | 
| 
       72 
     | 
    
         
            -
              end
         
     | 
| 
       73 
     | 
    
         
            -
            end
         
     | 
| 
      
 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.exist?('test')
         
     | 
| 
      
 13 
     | 
    
         
            +
                File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
         
     | 
| 
      
 14 
     | 
    
         
            +
                @@test_file = 'test_file1.txt'
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 18 
     | 
    
         
            +
                @test_file = 'test_file1.txt'
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              test "wc method basic functionality" do
         
     | 
| 
      
 22 
     | 
    
         
            +
                assert_respond_to(File, :wc)
         
     | 
| 
      
 23 
     | 
    
         
            +
                assert_nothing_raised{ File.wc(@test_file) }
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              test "wc accepts specific optional arguments" do
         
     | 
| 
      
 27 
     | 
    
         
            +
                assert_nothing_raised{ File.wc(@test_file, 'bytes') }
         
     | 
| 
      
 28 
     | 
    
         
            +
                assert_nothing_raised{ File.wc(@test_file, 'chars') }
         
     | 
| 
      
 29 
     | 
    
         
            +
                assert_nothing_raised{ File.wc(@test_file, 'words') }
         
     | 
| 
      
 30 
     | 
    
         
            +
                assert_nothing_raised{ File.wc(@test_file, 'lines') }
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
              test "argument to wc ignores the case of the option argument" do
         
     | 
| 
      
 34 
     | 
    
         
            +
                assert_nothing_raised{ File.wc(@test_file, 'LINES') }
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
              test "wc with no option returns expected results" do
         
     | 
| 
      
 38 
     | 
    
         
            +
                assert_kind_of(Array, File.wc(@test_file))
         
     | 
| 
      
 39 
     | 
    
         
            +
                assert_equal([166,166,25,25], File.wc(@test_file))
         
     | 
| 
      
 40 
     | 
    
         
            +
              end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
              test "wc with bytes option returns the expected result" do
         
     | 
| 
      
 43 
     | 
    
         
            +
                assert_equal(166, File.wc(@test_file, 'bytes'), "Wrong number of bytes")
         
     | 
| 
      
 44 
     | 
    
         
            +
              end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
              test "wc with chars option returns the expected result" do
         
     | 
| 
      
 47 
     | 
    
         
            +
                assert_equal(166, File.wc(@test_file, 'chars'), "Wrong number of chars")
         
     | 
| 
      
 48 
     | 
    
         
            +
              end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
              test "wc with words option returns the expected result" do
         
     | 
| 
      
 51 
     | 
    
         
            +
                assert_equal(25, File.wc(@test_file, 'words'), "Wrong number of words")
         
     | 
| 
      
 52 
     | 
    
         
            +
              end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
              test "wc with lines option returns the expected result" do
         
     | 
| 
      
 55 
     | 
    
         
            +
                assert_equal(25, File.wc(@test_file, 'lines'), "Wrong number of lines")
         
     | 
| 
      
 56 
     | 
    
         
            +
              end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
              test "wc requires at least on argument" do
         
     | 
| 
      
 59 
     | 
    
         
            +
                assert_raises(ArgumentError){ File.wc }
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
              test "an invalid option raises an error" do
         
     | 
| 
      
 63 
     | 
    
         
            +
                assert_raises(ArgumentError){ File.wc(@test_file, 'bogus') }
         
     | 
| 
      
 64 
     | 
    
         
            +
              end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
              def teardown
         
     | 
| 
      
 67 
     | 
    
         
            +
                @test_file = nil
         
     | 
| 
      
 68 
     | 
    
         
            +
              end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
              def self.shutdown
         
     | 
| 
      
 71 
     | 
    
         
            +
                File.delete(@@test_file) if File.exist?(@@test_file)
         
     | 
| 
      
 72 
     | 
    
         
            +
              end
         
     | 
| 
      
 73 
     | 
    
         
            +
            end
         
     | 
    
        data/test/test_which.rb
    CHANGED
    
    | 
         @@ -1,110 +1,126 @@ 
     | 
|
| 
       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 'test-unit'
         
     | 
| 
       11 
     | 
    
         
            -
            require 'rbconfig'
         
     | 
| 
       12 
     | 
    
         
            -
            require 'fileutils'
         
     | 
| 
       13 
     | 
    
         
            -
            require 'ptools'
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                @@ 
     | 
| 
       19 
     | 
    
         
            -
                @@ 
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                 
     | 
| 
       23 
     | 
    
         
            -
                 
     | 
| 
       24 
     | 
    
         
            -
                File.chmod( 
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                @ruby = ' 
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                  RbConfig::CONFIG[' 
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                  @exe 
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                 
     | 
| 
       45 
     | 
    
         
            -
                 
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
                assert_equal(nil, File.which(' 
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                 
     | 
| 
       60 
     | 
    
         
            -
                assert_not_nil(File.which(' 
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
                 
     | 
| 
       66 
     | 
    
         
            -
                assert_not_nil(File.which(' 
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
                assert_raises(ArgumentError){ File.which(@ruby,  
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
                 
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
      
 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 'test-unit'
         
     | 
| 
      
 11 
     | 
    
         
            +
            require 'rbconfig'
         
     | 
| 
      
 12 
     | 
    
         
            +
            require 'fileutils'
         
     | 
| 
      
 13 
     | 
    
         
            +
            require 'ptools'
         
     | 
| 
      
 14 
     | 
    
         
            +
            require 'tempfile'
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            class TC_FileWhich < Test::Unit::TestCase
         
     | 
| 
      
 17 
     | 
    
         
            +
              def self.startup
         
     | 
| 
      
 18 
     | 
    
         
            +
                @@windows = File::ALT_SEPARATOR
         
     | 
| 
      
 19 
     | 
    
         
            +
                @@dir = File.join(Dir.pwd, 'tempdir')
         
     | 
| 
      
 20 
     | 
    
         
            +
                @@non_exe = File.join(Dir.pwd, 'tempfile')
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                Dir.mkdir(@@dir) unless File.exist?(@@dir)
         
     | 
| 
      
 23 
     | 
    
         
            +
                FileUtils.touch(@@non_exe)
         
     | 
| 
      
 24 
     | 
    
         
            +
                File.chmod(775, @@dir)
         
     | 
| 
      
 25 
     | 
    
         
            +
                File.chmod(644, @@non_exe)
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 29 
     | 
    
         
            +
                @ruby = RUBY_PLATFORM.match('java') ? 'jruby' : 'ruby'
         
     | 
| 
      
 30 
     | 
    
         
            +
                @ruby = 'rbx' if defined?(Rubinius)
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                @exe = File.join(
         
     | 
| 
      
 33 
     | 
    
         
            +
                  RbConfig::CONFIG['bindir'],
         
     | 
| 
      
 34 
     | 
    
         
            +
                  RbConfig::CONFIG['ruby_install_name']
         
     | 
| 
      
 35 
     | 
    
         
            +
                )
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                if @@windows
         
     | 
| 
      
 38 
     | 
    
         
            +
                  @exe.tr!('/','\\')
         
     | 
| 
      
 39 
     | 
    
         
            +
                  @exe << ".exe"
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
              test "which method basic functionality" do
         
     | 
| 
      
 44 
     | 
    
         
            +
                assert_respond_to(File, :which)
         
     | 
| 
      
 45 
     | 
    
         
            +
                assert_nothing_raised{ File.which(@ruby) }
         
     | 
| 
      
 46 
     | 
    
         
            +
                assert_kind_of(String, File.which(@ruby))
         
     | 
| 
      
 47 
     | 
    
         
            +
              end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
              test "which accepts an optional path to search" do
         
     | 
| 
      
 50 
     | 
    
         
            +
                assert_nothing_raised{ File.which(@ruby, "/usr/bin:/usr/local/bin") }
         
     | 
| 
      
 51 
     | 
    
         
            +
              end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
              test "which returns nil if not found" do
         
     | 
| 
      
 54 
     | 
    
         
            +
                assert_equal(nil, File.which(@ruby, '/bogus/path'))
         
     | 
| 
      
 55 
     | 
    
         
            +
                assert_equal(nil, File.which('blahblahblah'))
         
     | 
| 
      
 56 
     | 
    
         
            +
              end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
              test "which handles executables without extensions on windows" do
         
     | 
| 
      
 59 
     | 
    
         
            +
                omit_unless(@@windows, "test skipped unless MS Windows")
         
     | 
| 
      
 60 
     | 
    
         
            +
                assert_not_nil(File.which('ruby'))
         
     | 
| 
      
 61 
     | 
    
         
            +
                assert_not_nil(File.which('notepad'))
         
     | 
| 
      
 62 
     | 
    
         
            +
              end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
              test "which handles executables that already contain extensions on windows" do
         
     | 
| 
      
 65 
     | 
    
         
            +
                omit_unless(@@windows, "test skipped unless MS Windows")
         
     | 
| 
      
 66 
     | 
    
         
            +
                assert_not_nil(File.which('ruby.exe'))
         
     | 
| 
      
 67 
     | 
    
         
            +
                assert_not_nil(File.which('notepad.exe'))
         
     | 
| 
      
 68 
     | 
    
         
            +
              end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
              test "which returns argument if an existent absolute path is provided" do
         
     | 
| 
      
 71 
     | 
    
         
            +
                assert_equal(@exe, File.which(@ruby), "=> May fail on a symlink")
         
     | 
| 
      
 72 
     | 
    
         
            +
              end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
              test "which returns nil if a non-existent absolute path is provided" do
         
     | 
| 
      
 75 
     | 
    
         
            +
                assert_nil(File.which('/foo/bar/baz/ruby'))
         
     | 
| 
      
 76 
     | 
    
         
            +
              end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
              test "which does not pickup files that are not executable" do
         
     | 
| 
      
 79 
     | 
    
         
            +
                assert_nil(File.which(@@non_exe))
         
     | 
| 
      
 80 
     | 
    
         
            +
              end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
              test "which does not pickup executable directories" do
         
     | 
| 
      
 83 
     | 
    
         
            +
                assert_nil(File.which(@@dir))
         
     | 
| 
      
 84 
     | 
    
         
            +
              end
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
              test "which accepts a minimum of one argument" do
         
     | 
| 
      
 87 
     | 
    
         
            +
                assert_raises(ArgumentError){ File.which }
         
     | 
| 
      
 88 
     | 
    
         
            +
              end
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
              test "which accepts a maximum of two arguments" do
         
     | 
| 
      
 91 
     | 
    
         
            +
                assert_raises(ArgumentError){ File.which(@ruby, "foo", "bar") }
         
     | 
| 
      
 92 
     | 
    
         
            +
              end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
              test "the second argument cannot be nil or empty" do
         
     | 
| 
      
 95 
     | 
    
         
            +
                assert_raises(ArgumentError){ File.which(@ruby, nil) }
         
     | 
| 
      
 96 
     | 
    
         
            +
                assert_raises(ArgumentError){ File.which(@ruby, '') }
         
     | 
| 
      
 97 
     | 
    
         
            +
              end
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
              test "resolves with with ~" do
         
     | 
| 
      
 100 
     | 
    
         
            +
                omit_if(@@windows, "~ tests skipped on MS Windows")
         
     | 
| 
      
 101 
     | 
    
         
            +
                begin
         
     | 
| 
      
 102 
     | 
    
         
            +
                  old_home = ENV['HOME']
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                  ENV['HOME'] = Dir::Tmpname.tmpdir
         
     | 
| 
      
 105 
     | 
    
         
            +
                  program = Tempfile.new(['program', '.sh'])
         
     | 
| 
      
 106 
     | 
    
         
            +
                  File.chmod(755, program.path)
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
                  assert_not_nil(File.which(File.basename(program.path), '~/'))
         
     | 
| 
      
 109 
     | 
    
         
            +
                ensure
         
     | 
| 
      
 110 
     | 
    
         
            +
                  ENV['HOME'] = old_home
         
     | 
| 
      
 111 
     | 
    
         
            +
                end
         
     | 
| 
      
 112 
     | 
    
         
            +
              end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
              def teardown
         
     | 
| 
      
 115 
     | 
    
         
            +
                @exe  = nil
         
     | 
| 
      
 116 
     | 
    
         
            +
                @ruby = nil
         
     | 
| 
      
 117 
     | 
    
         
            +
              end
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
              def self.shutdown
         
     | 
| 
      
 120 
     | 
    
         
            +
                FileUtils.rm(@@non_exe)
         
     | 
| 
      
 121 
     | 
    
         
            +
                FileUtils.rm_rf(@@dir)
         
     | 
| 
      
 122 
     | 
    
         
            +
                @@windows = nil
         
     | 
| 
      
 123 
     | 
    
         
            +
                @@dir = nil
         
     | 
| 
      
 124 
     | 
    
         
            +
                @@non_exe = nil
         
     | 
| 
      
 125 
     | 
    
         
            +
              end
         
     | 
| 
      
 126 
     | 
    
         
            +
            end
         
     |