rake 0.4.8
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.
Potentially problematic release.
This version of rake might be problematic. Click here for more details.
- data/CHANGES +132 -0
 - data/MIT-LICENSE +21 -0
 - data/README +209 -0
 - data/Rakefile +215 -0
 - data/TODO +19 -0
 - data/bin/rake +8 -0
 - data/doc/example/Rakefile1 +38 -0
 - data/doc/example/Rakefile2 +35 -0
 - data/doc/example/a.c +6 -0
 - data/doc/example/b.c +6 -0
 - data/doc/example/main.c +11 -0
 - data/doc/glossary.rdoc +51 -0
 - data/doc/proto_rake.rdoc +127 -0
 - data/doc/rakefile.rdoc +234 -0
 - data/doc/rational.rdoc +151 -0
 - data/install.rb +88 -0
 - data/lib/rake.rb +983 -0
 - data/lib/rake/clean.rb +31 -0
 - data/lib/rake/contrib/compositepublisher.rb +24 -0
 - data/lib/rake/contrib/ftptools.rb +139 -0
 - data/lib/rake/contrib/publisher.rb +75 -0
 - data/lib/rake/contrib/rubyforgepublisher.rb +18 -0
 - data/lib/rake/contrib/sshpublisher.rb +47 -0
 - data/lib/rake/contrib/sys.rb +207 -0
 - data/lib/rake/gempackagetask.rb +98 -0
 - data/lib/rake/packagetask.rb +152 -0
 - data/lib/rake/rdoctask.rb +128 -0
 - data/lib/rake/runtest.rb +23 -0
 - data/lib/rake/tasklib.rb +24 -0
 - data/lib/rake/testtask.rb +118 -0
 - data/test/contrib/testsys.rb +47 -0
 - data/test/data/rbext/rakefile.rb +3 -0
 - data/test/filecreation.rb +26 -0
 - data/test/functional.rb +82 -0
 - data/test/testclean.rb +13 -0
 - data/test/testfilelist.rb +255 -0
 - data/test/testfileutils.rb +55 -0
 - data/test/testftp.rb +55 -0
 - data/test/testpackagetask.rb +81 -0
 - data/test/testtasks.rb +371 -0
 - data/test/testtesttask.rb +71 -0
 - metadata +91 -0
 
| 
         @@ -0,0 +1,47 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'test/filecreation'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'rake/contrib/sys'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            class TestSys < Test::Unit::TestCase
         
     | 
| 
      
 8 
     | 
    
         
            +
              include FileCreation
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            #   def test_delete
         
     | 
| 
      
 11 
     | 
    
         
            +
            #     create_file("testdata/a")
         
     | 
| 
      
 12 
     | 
    
         
            +
            #     Sys.delete_all("testdata/a")
         
     | 
| 
      
 13 
     | 
    
         
            +
            #     assert ! File.exist?("testdata/a")
         
     | 
| 
      
 14 
     | 
    
         
            +
            #   end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            #   def test_copy
         
     | 
| 
      
 17 
     | 
    
         
            +
            #     create_file("testdata/a")
         
     | 
| 
      
 18 
     | 
    
         
            +
            #     Sys.copy("testdata/a", "testdata/b")
         
     | 
| 
      
 19 
     | 
    
         
            +
            #     assert File.exist?("testdata/b")
         
     | 
| 
      
 20 
     | 
    
         
            +
            #   end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
            #   def test_for_files
         
     | 
| 
      
 23 
     | 
    
         
            +
            #     test_files = ["testdata/a.pl", "testdata/c.pl", "testdata/b.rb"]
         
     | 
| 
      
 24 
     | 
    
         
            +
            #     test_files.each { |fn| create_file(fn) }
         
     | 
| 
      
 25 
     | 
    
         
            +
            #     list = []
         
     | 
| 
      
 26 
     | 
    
         
            +
            #     Sys.for_files("testdata/*.pl", "testdata/*.rb") { |fn|
         
     | 
| 
      
 27 
     | 
    
         
            +
            #       list << fn
         
     | 
| 
      
 28 
     | 
    
         
            +
            #     }
         
     | 
| 
      
 29 
     | 
    
         
            +
            #     assert_equal test_files.sort, list.sort
         
     | 
| 
      
 30 
     | 
    
         
            +
            #   end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
            #   def test_indir
         
     | 
| 
      
 33 
     | 
    
         
            +
            #     here = Dir.pwd
         
     | 
| 
      
 34 
     | 
    
         
            +
            #     Sys.makedirs("testdata/dir")
         
     | 
| 
      
 35 
     | 
    
         
            +
            #     assert_equal "#{here}/testdata/dir", Sys.indir("testdata/dir") { Dir.pwd }
         
     | 
| 
      
 36 
     | 
    
         
            +
            #     assert_equal here, Dir.pwd
         
     | 
| 
      
 37 
     | 
    
         
            +
            #   end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
              def test_split_all
         
     | 
| 
      
 40 
     | 
    
         
            +
                assert_equal ['a'], Sys.split_all('a')
         
     | 
| 
      
 41 
     | 
    
         
            +
                assert_equal ['..'], Sys.split_all('..')
         
     | 
| 
      
 42 
     | 
    
         
            +
                assert_equal ['/'], Sys.split_all('/')
         
     | 
| 
      
 43 
     | 
    
         
            +
                assert_equal ['a', 'b'], Sys.split_all('a/b')
         
     | 
| 
      
 44 
     | 
    
         
            +
                assert_equal ['/', 'a', 'b'], Sys.split_all('/a/b')
         
     | 
| 
      
 45 
     | 
    
         
            +
                assert_equal ['..', 'a', 'b'], Sys.split_all('../a/b')
         
     | 
| 
      
 46 
     | 
    
         
            +
              end
         
     | 
| 
      
 47 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,26 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'ftools'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            module FileCreation
         
     | 
| 
      
 6 
     | 
    
         
            +
              def create_timed_files(oldfile, newfile)
         
     | 
| 
      
 7 
     | 
    
         
            +
                return if File.exist?(oldfile) && File.exist?(newfile)
         
     | 
| 
      
 8 
     | 
    
         
            +
                old_time = create_file(oldfile)
         
     | 
| 
      
 9 
     | 
    
         
            +
                while create_file(newfile) <= old_time
         
     | 
| 
      
 10 
     | 
    
         
            +
                  sleep(0.1)
         
     | 
| 
      
 11 
     | 
    
         
            +
                  File.delete(newfile) rescue nil
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              def create_file(name)
         
     | 
| 
      
 16 
     | 
    
         
            +
                dirname = File.dirname(name)
         
     | 
| 
      
 17 
     | 
    
         
            +
                FileUtils.mkdir_p(dirname) unless File.exist?(dirname)
         
     | 
| 
      
 18 
     | 
    
         
            +
                open(name, "w") {|f| f.puts "HI" } unless File.exist?(name)
         
     | 
| 
      
 19 
     | 
    
         
            +
                File.new(name).mtime
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              def delete_file(name)
         
     | 
| 
      
 23 
     | 
    
         
            +
                File.delete(name) rescue nil
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
            end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
    
        data/test/functional.rb
    ADDED
    
    | 
         @@ -0,0 +1,82 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            begin
         
     | 
| 
      
 4 
     | 
    
         
            +
              require 'rubygems'
         
     | 
| 
      
 5 
     | 
    
         
            +
              require_gem 'session'
         
     | 
| 
      
 6 
     | 
    
         
            +
            rescue LoadError
         
     | 
| 
      
 7 
     | 
    
         
            +
              puts "UNABLE TO RUN FUNCTIONAL TESTS"
         
     | 
| 
      
 8 
     | 
    
         
            +
              puts "No Session Found"
         
     | 
| 
      
 9 
     | 
    
         
            +
            end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 12 
     | 
    
         
            +
            require 'fileutils'
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            class FunctionalTest < Test::Unit::TestCase
         
     | 
| 
      
 15 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 16 
     | 
    
         
            +
                @rake_path = File.expand_path("bin/rake")
         
     | 
| 
      
 17 
     | 
    
         
            +
                lib_path = File.expand_path("lib")
         
     | 
| 
      
 18 
     | 
    
         
            +
                @ruby_options = "-I#{lib_path} -I."
         
     | 
| 
      
 19 
     | 
    
         
            +
                @verbose = true if ENV['VERBOSE']
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              def test_rake_default
         
     | 
| 
      
 23 
     | 
    
         
            +
                Dir.chdir("test/data/default") do rake end
         
     | 
| 
      
 24 
     | 
    
         
            +
                assert_match /^DEFAULT$/, @out
         
     | 
| 
      
 25 
     | 
    
         
            +
                assert_status
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              def test_rake_error_on_bad_task
         
     | 
| 
      
 29 
     | 
    
         
            +
                Dir.chdir("test/data/default") do rake "xyz" end
         
     | 
| 
      
 30 
     | 
    
         
            +
                assert_match /rake aborted/, @out
         
     | 
| 
      
 31 
     | 
    
         
            +
                assert_status(1)
         
     | 
| 
      
 32 
     | 
    
         
            +
              end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
              def test_env_availabe_at_top_scope
         
     | 
| 
      
 35 
     | 
    
         
            +
                Dir.chdir("test/data/default") do rake "TESTTOPSCOPE=1" end
         
     | 
| 
      
 36 
     | 
    
         
            +
                assert_match /^TOPSCOPE$/, @out
         
     | 
| 
      
 37 
     | 
    
         
            +
                assert_status
         
     | 
| 
      
 38 
     | 
    
         
            +
              end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
              def test_env_availabe_at_task_scope
         
     | 
| 
      
 41 
     | 
    
         
            +
                Dir.chdir("test/data/default") do rake "TESTTASKSCOPE=1 task_scope" end
         
     | 
| 
      
 42 
     | 
    
         
            +
                assert_match /^TASKSCOPE$/, @out
         
     | 
| 
      
 43 
     | 
    
         
            +
                assert_status
         
     | 
| 
      
 44 
     | 
    
         
            +
              end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
              def test_multi_desc
         
     | 
| 
      
 47 
     | 
    
         
            +
                Dir.chdir("test/data/multidesc") do rake "-T" end
         
     | 
| 
      
 48 
     | 
    
         
            +
                assert_match %r{^rake a *# A / A2 *$}, @out
         
     | 
| 
      
 49 
     | 
    
         
            +
                assert_match %r{^rake b *# B *$}, @out
         
     | 
| 
      
 50 
     | 
    
         
            +
                assert_no_match %r{^rake c}, @out
         
     | 
| 
      
 51 
     | 
    
         
            +
              end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
              def test_rbext
         
     | 
| 
      
 54 
     | 
    
         
            +
                Dir.chdir("test/data/rbext") do rake "-N" end
         
     | 
| 
      
 55 
     | 
    
         
            +
                assert_match %r{^OK$}, @out
         
     | 
| 
      
 56 
     | 
    
         
            +
              end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
              def test_nosearch
         
     | 
| 
      
 59 
     | 
    
         
            +
                Dir.chdir("test/data/nosearch") do rake "-N" end
         
     | 
| 
      
 60 
     | 
    
         
            +
                assert_match %r{^No Rakefile found}, @out
         
     | 
| 
      
 61 
     | 
    
         
            +
              end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
              private
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
              def rake(options="")
         
     | 
| 
      
 66 
     | 
    
         
            +
                shell = Session::Shell.new
         
     | 
| 
      
 67 
     | 
    
         
            +
                command = "ruby #{@ruby_options} #{@rake_path} #{options}"
         
     | 
| 
      
 68 
     | 
    
         
            +
                puts "COMMAND: [#{command}]" if @verbose
         
     | 
| 
      
 69 
     | 
    
         
            +
                @out, @err = shell.execute command
         
     | 
| 
      
 70 
     | 
    
         
            +
                @status = shell.exit_status
         
     | 
| 
      
 71 
     | 
    
         
            +
                puts "STATUS:  [#{@status}]" if @verbose
         
     | 
| 
      
 72 
     | 
    
         
            +
                puts "OUTPUT:  [#{@out}]" if @verbose
         
     | 
| 
      
 73 
     | 
    
         
            +
                puts "ERROR:   [#{@err}]" if @verbose
         
     | 
| 
      
 74 
     | 
    
         
            +
                puts "PWD:     [#{Dir.pwd}]" if @verbose
         
     | 
| 
      
 75 
     | 
    
         
            +
                shell.close
         
     | 
| 
      
 76 
     | 
    
         
            +
              end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
              def assert_status(expected_status=0)
         
     | 
| 
      
 79 
     | 
    
         
            +
                assert_equal expected_status, @status
         
     | 
| 
      
 80 
     | 
    
         
            +
              end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
            end
         
     | 
    
        data/test/testclean.rb
    ADDED
    
    | 
         @@ -0,0 +1,13 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'rake/clean'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            class TestClean < Test::Unit::TestCase
         
     | 
| 
      
 7 
     | 
    
         
            +
              def test_clean
         
     | 
| 
      
 8 
     | 
    
         
            +
                assert Task['clean'], "Should define clean"
         
     | 
| 
      
 9 
     | 
    
         
            +
                assert Task['clobber'], "Should define clobber"
         
     | 
| 
      
 10 
     | 
    
         
            +
                assert Task['clobber'].prerequisites.include?("clean"),
         
     | 
| 
      
 11 
     | 
    
         
            +
                  "Clobber should require clean"
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,255 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'rake'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            class TestFileList < Test::Unit::TestCase
         
     | 
| 
      
 7 
     | 
    
         
            +
              FileList = Rake::FileList
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 10 
     | 
    
         
            +
                create_test_data
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              def teardown
         
     | 
| 
      
 14 
     | 
    
         
            +
                FileList.select_default_ignore_patterns
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              def test_create
         
     | 
| 
      
 18 
     | 
    
         
            +
                fl = FileList.new
         
     | 
| 
      
 19 
     | 
    
         
            +
                assert_equal 0, fl.size
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              def test_create_with_args
         
     | 
| 
      
 23 
     | 
    
         
            +
                fl = FileList.new("testdata/*.c", "x")
         
     | 
| 
      
 24 
     | 
    
         
            +
                assert_equal ["testdata/abc.c", "testdata/x.c", "testdata/xyz.c", "x"].sort,
         
     | 
| 
      
 25 
     | 
    
         
            +
                  fl.sort
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              def test_create_with_block
         
     | 
| 
      
 29 
     | 
    
         
            +
                fl = FileList.new { |f| f.include("x") }
         
     | 
| 
      
 30 
     | 
    
         
            +
                assert_equal ["x"], fl.resolve
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
              def test_create_with_brackets
         
     | 
| 
      
 34 
     | 
    
         
            +
                fl = FileList["testdata/*.c", "x"]
         
     | 
| 
      
 35 
     | 
    
         
            +
                assert_equal ["testdata/abc.c", "testdata/x.c", "testdata/xyz.c", "x"].sort,
         
     | 
| 
      
 36 
     | 
    
         
            +
                  fl.sort
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
              def test_append
         
     | 
| 
      
 40 
     | 
    
         
            +
                fl = FileList.new
         
     | 
| 
      
 41 
     | 
    
         
            +
                fl << "a.rb" << "b.rb"
         
     | 
| 
      
 42 
     | 
    
         
            +
                assert_equal ['a.rb', 'b.rb'], fl
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              def test_add_many
         
     | 
| 
      
 46 
     | 
    
         
            +
                fl = FileList.new
         
     | 
| 
      
 47 
     | 
    
         
            +
                fl.include %w(a d c )
         
     | 
| 
      
 48 
     | 
    
         
            +
                fl.include('x', 'y')
         
     | 
| 
      
 49 
     | 
    
         
            +
                assert_equal ['a', 'd', 'c', 'x', 'y'], fl.resolve
         
     | 
| 
      
 50 
     | 
    
         
            +
              end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
              def test_add_return
         
     | 
| 
      
 53 
     | 
    
         
            +
                f = FileList.new
         
     | 
| 
      
 54 
     | 
    
         
            +
                g = f << "x"
         
     | 
| 
      
 55 
     | 
    
         
            +
                assert_equal f.id, g.id
         
     | 
| 
      
 56 
     | 
    
         
            +
                h = f.include("y")
         
     | 
| 
      
 57 
     | 
    
         
            +
                assert_equal f.id, h.id
         
     | 
| 
      
 58 
     | 
    
         
            +
              end
         
     | 
| 
      
 59 
     | 
    
         
            +
              
         
     | 
| 
      
 60 
     | 
    
         
            +
              def test_match
         
     | 
| 
      
 61 
     | 
    
         
            +
                fl = FileList.new
         
     | 
| 
      
 62 
     | 
    
         
            +
                fl.include('test/test*.rb')
         
     | 
| 
      
 63 
     | 
    
         
            +
                assert fl.include?("test/testfilelist.rb")
         
     | 
| 
      
 64 
     | 
    
         
            +
                assert fl.size > 3
         
     | 
| 
      
 65 
     | 
    
         
            +
                fl.each { |fn| assert_match /\.rb$/, fn }
         
     | 
| 
      
 66 
     | 
    
         
            +
              end
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
              def test_add_matching
         
     | 
| 
      
 69 
     | 
    
         
            +
                fl = FileList.new
         
     | 
| 
      
 70 
     | 
    
         
            +
                fl << "a.java"
         
     | 
| 
      
 71 
     | 
    
         
            +
                fl.include("test/*.rb")
         
     | 
| 
      
 72 
     | 
    
         
            +
                assert_equal "a.java", fl[0]
         
     | 
| 
      
 73 
     | 
    
         
            +
                assert fl.size > 2
         
     | 
| 
      
 74 
     | 
    
         
            +
                assert fl.include?("test/testfilelist.rb")
         
     | 
| 
      
 75 
     | 
    
         
            +
              end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
              def test_multiple_patterns
         
     | 
| 
      
 78 
     | 
    
         
            +
                create_test_data
         
     | 
| 
      
 79 
     | 
    
         
            +
                fl = FileList.new
         
     | 
| 
      
 80 
     | 
    
         
            +
                fl.include('*.c', '*xist*')
         
     | 
| 
      
 81 
     | 
    
         
            +
                assert_equal [], fl
         
     | 
| 
      
 82 
     | 
    
         
            +
                fl.include('testdata/*.c', 'testdata/*xist*')
         
     | 
| 
      
 83 
     | 
    
         
            +
                assert_equal [
         
     | 
| 
      
 84 
     | 
    
         
            +
                  'testdata/x.c', 'testdata/xyz.c', 'testdata/abc.c', 'testdata/existing'
         
     | 
| 
      
 85 
     | 
    
         
            +
                ].sort, fl.sort
         
     | 
| 
      
 86 
     | 
    
         
            +
              end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
              def test_reject
         
     | 
| 
      
 89 
     | 
    
         
            +
                fl = FileList.new
         
     | 
| 
      
 90 
     | 
    
         
            +
                fl.include %w(testdata/x.c testdata/abc.c testdata/xyz.c testdata/existing)
         
     | 
| 
      
 91 
     | 
    
         
            +
                fl.reject! { |fn| fn =~ %r{/x} }
         
     | 
| 
      
 92 
     | 
    
         
            +
                assert_equal [
         
     | 
| 
      
 93 
     | 
    
         
            +
                  'testdata/abc.c', 'testdata/existing'
         
     | 
| 
      
 94 
     | 
    
         
            +
                ], fl
         
     | 
| 
      
 95 
     | 
    
         
            +
              end
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
              def test_exclude
         
     | 
| 
      
 98 
     | 
    
         
            +
                fl = FileList['testdata/x.c', 'testdata/abc.c', 'testdata/xyz.c', 'testdata/existing']
         
     | 
| 
      
 99 
     | 
    
         
            +
                fl.each { |fn| touch fn, :verbose => false }
         
     | 
| 
      
 100 
     | 
    
         
            +
                x = fl.exclude(%r{/x.+\.})
         
     | 
| 
      
 101 
     | 
    
         
            +
                assert_equal FileList, x.class
         
     | 
| 
      
 102 
     | 
    
         
            +
                assert_equal [
         
     | 
| 
      
 103 
     | 
    
         
            +
                  'testdata/x.c', 'testdata/abc.c', 'testdata/existing'
         
     | 
| 
      
 104 
     | 
    
         
            +
                ], fl
         
     | 
| 
      
 105 
     | 
    
         
            +
                assert_equal fl.id, x.id
         
     | 
| 
      
 106 
     | 
    
         
            +
                fl.exclude('testdata/*.c')
         
     | 
| 
      
 107 
     | 
    
         
            +
                assert_equal ['testdata/existing'], fl
         
     | 
| 
      
 108 
     | 
    
         
            +
                fl.exclude('testdata/existing')
         
     | 
| 
      
 109 
     | 
    
         
            +
                assert_equal [], fl
         
     | 
| 
      
 110 
     | 
    
         
            +
              end
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
              def test_exclude_return_on_create
         
     | 
| 
      
 113 
     | 
    
         
            +
                fl = FileList['testdata/*'].exclude(/.*\.c$/)
         
     | 
| 
      
 114 
     | 
    
         
            +
                assert_equal FileList, fl.class
         
     | 
| 
      
 115 
     | 
    
         
            +
              end
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
      
 117 
     | 
    
         
            +
              def test_default_exclude
         
     | 
| 
      
 118 
     | 
    
         
            +
                fl = FileList.new
         
     | 
| 
      
 119 
     | 
    
         
            +
                fl.clear_exclude
         
     | 
| 
      
 120 
     | 
    
         
            +
                fl.include("**/*~", "**/*.bak", "**/core")
         
     | 
| 
      
 121 
     | 
    
         
            +
                assert fl.member?("testdata/core"), "Should include core"
         
     | 
| 
      
 122 
     | 
    
         
            +
                assert fl.member?("testdata/x.bak"), "Should include .bak files"
         
     | 
| 
      
 123 
     | 
    
         
            +
              end
         
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
      
 125 
     | 
    
         
            +
              def test_unique
         
     | 
| 
      
 126 
     | 
    
         
            +
                fl = FileList.new
         
     | 
| 
      
 127 
     | 
    
         
            +
                fl << "x.c" << "a.c" << "b.rb" << "a.c"
         
     | 
| 
      
 128 
     | 
    
         
            +
                assert_equal ['x.c', 'a.c', 'b.rb', 'a.c'], fl
         
     | 
| 
      
 129 
     | 
    
         
            +
                fl.uniq!
         
     | 
| 
      
 130 
     | 
    
         
            +
                assert_equal ['x.c', 'a.c', 'b.rb'], fl
         
     | 
| 
      
 131 
     | 
    
         
            +
              end
         
     | 
| 
      
 132 
     | 
    
         
            +
             
     | 
| 
      
 133 
     | 
    
         
            +
              def test_to_string
         
     | 
| 
      
 134 
     | 
    
         
            +
                fl = FileList.new
         
     | 
| 
      
 135 
     | 
    
         
            +
                fl << "a.java" << "b.java"
         
     | 
| 
      
 136 
     | 
    
         
            +
                assert_equal  "a.java b.java", fl.to_s
         
     | 
| 
      
 137 
     | 
    
         
            +
                assert_equal  "a.java b.java", "#{fl}"
         
     | 
| 
      
 138 
     | 
    
         
            +
              end
         
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
              def test_to_s_pending
         
     | 
| 
      
 141 
     | 
    
         
            +
                fl = FileList['testdata/abc.*']
         
     | 
| 
      
 142 
     | 
    
         
            +
                assert_equal  %{testdata/abc.c}, fl.to_s
         
     | 
| 
      
 143 
     | 
    
         
            +
              end
         
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
      
 145 
     | 
    
         
            +
              def test_inspect_pending
         
     | 
| 
      
 146 
     | 
    
         
            +
                fl = FileList['testdata/abc.*']
         
     | 
| 
      
 147 
     | 
    
         
            +
                assert_equal  %{["testdata/abc.c"]}, fl.inspect
         
     | 
| 
      
 148 
     | 
    
         
            +
              end
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
              def test_sub
         
     | 
| 
      
 151 
     | 
    
         
            +
                fl = FileList["testdata/*.c"]
         
     | 
| 
      
 152 
     | 
    
         
            +
                f2 = fl.sub(/\.c$/, ".o")
         
     | 
| 
      
 153 
     | 
    
         
            +
                assert_equal FileList, f2.class
         
     | 
| 
      
 154 
     | 
    
         
            +
                assert_equal ["testdata/abc.o", "testdata/x.o", "testdata/xyz.o"].sort,
         
     | 
| 
      
 155 
     | 
    
         
            +
                  f2.sort
         
     | 
| 
      
 156 
     | 
    
         
            +
                f3 = fl.gsub(/\.c$/, ".o")
         
     | 
| 
      
 157 
     | 
    
         
            +
                assert_equal FileList, f3.class
         
     | 
| 
      
 158 
     | 
    
         
            +
                assert_equal ["testdata/abc.o", "testdata/x.o", "testdata/xyz.o"].sort,
         
     | 
| 
      
 159 
     | 
    
         
            +
                  f3.sort
         
     | 
| 
      
 160 
     | 
    
         
            +
              end
         
     | 
| 
      
 161 
     | 
    
         
            +
             
     | 
| 
      
 162 
     | 
    
         
            +
              def test_sub!
         
     | 
| 
      
 163 
     | 
    
         
            +
                f = "x/a.c"
         
     | 
| 
      
 164 
     | 
    
         
            +
                fl = FileList[f, "x/b.c"]
         
     | 
| 
      
 165 
     | 
    
         
            +
                res = fl.sub!(/\.c$/, ".o")
         
     | 
| 
      
 166 
     | 
    
         
            +
                assert_equal ["x/a.o", "x/b.o"].sort, fl.sort
         
     | 
| 
      
 167 
     | 
    
         
            +
                assert_equal "x/a.c", f
         
     | 
| 
      
 168 
     | 
    
         
            +
                assert_equal fl.id, res.id
         
     | 
| 
      
 169 
     | 
    
         
            +
              end
         
     | 
| 
      
 170 
     | 
    
         
            +
             
     | 
| 
      
 171 
     | 
    
         
            +
              def test_sub_with_block
         
     | 
| 
      
 172 
     | 
    
         
            +
                fl = FileList["src/org/onestepback/a.java", "src/org/onestepback/b.java"]
         
     | 
| 
      
 173 
     | 
    
         
            +
            # The block version doesn't work the way I want it to ...
         
     | 
| 
      
 174 
     | 
    
         
            +
            #    f2 = fl.sub(%r{^src/(.*)\.java$}) { |x|  "classes/" + $1 + ".class" }
         
     | 
| 
      
 175 
     | 
    
         
            +
                f2 = fl.sub(%r{^src/(.*)\.java$}, "classes/\\1.class")
         
     | 
| 
      
 176 
     | 
    
         
            +
                assert_equal [
         
     | 
| 
      
 177 
     | 
    
         
            +
                  "classes/org/onestepback/a.class",
         
     | 
| 
      
 178 
     | 
    
         
            +
                  "classes/org/onestepback/b.class"
         
     | 
| 
      
 179 
     | 
    
         
            +
                ].sort,
         
     | 
| 
      
 180 
     | 
    
         
            +
                  f2.sort
         
     | 
| 
      
 181 
     | 
    
         
            +
              end
         
     | 
| 
      
 182 
     | 
    
         
            +
             
     | 
| 
      
 183 
     | 
    
         
            +
              def test_gsub
         
     | 
| 
      
 184 
     | 
    
         
            +
                create_test_data
         
     | 
| 
      
 185 
     | 
    
         
            +
                fl = FileList["testdata/*.c"]
         
     | 
| 
      
 186 
     | 
    
         
            +
                f2 = fl.gsub(/a/, "A")
         
     | 
| 
      
 187 
     | 
    
         
            +
                assert_equal ["testdAtA/Abc.c", "testdAtA/x.c", "testdAtA/xyz.c"].sort,
         
     | 
| 
      
 188 
     | 
    
         
            +
                  f2.sort
         
     | 
| 
      
 189 
     | 
    
         
            +
              end
         
     | 
| 
      
 190 
     | 
    
         
            +
             
     | 
| 
      
 191 
     | 
    
         
            +
              def test_ignore_special
         
     | 
| 
      
 192 
     | 
    
         
            +
                f = FileList['testdata/*']
         
     | 
| 
      
 193 
     | 
    
         
            +
                assert ! f.include?("testdata/CVS"), "Should not contain CVS"
         
     | 
| 
      
 194 
     | 
    
         
            +
                assert ! f.include?("testdata/.dummy"), "Should not contain dot files"
         
     | 
| 
      
 195 
     | 
    
         
            +
                assert ! f.include?("testdata/x.bak"), "Should not contain .bak files"
         
     | 
| 
      
 196 
     | 
    
         
            +
                assert ! f.include?("testdata/x~"), "Should not contain ~ files"
         
     | 
| 
      
 197 
     | 
    
         
            +
                assert ! f.include?("testdata/core"), "Should not contain core files"
         
     | 
| 
      
 198 
     | 
    
         
            +
              end
         
     | 
| 
      
 199 
     | 
    
         
            +
             
     | 
| 
      
 200 
     | 
    
         
            +
              def test_clear_ignore_patterns
         
     | 
| 
      
 201 
     | 
    
         
            +
                f = FileList['testdata/*']
         
     | 
| 
      
 202 
     | 
    
         
            +
                f.clear_exclude
         
     | 
| 
      
 203 
     | 
    
         
            +
                assert f.include?("testdata/abc.c")
         
     | 
| 
      
 204 
     | 
    
         
            +
                assert f.include?("testdata/xyz.c")
         
     | 
| 
      
 205 
     | 
    
         
            +
                assert f.include?("testdata/CVS")
         
     | 
| 
      
 206 
     | 
    
         
            +
                assert f.include?("testdata/x.bak")
         
     | 
| 
      
 207 
     | 
    
         
            +
                assert f.include?("testdata/x~")
         
     | 
| 
      
 208 
     | 
    
         
            +
              end
         
     | 
| 
      
 209 
     | 
    
         
            +
             
     | 
| 
      
 210 
     | 
    
         
            +
              def test_exclude_with_alternate_file_seps
         
     | 
| 
      
 211 
     | 
    
         
            +
                fl = FileList.new
         
     | 
| 
      
 212 
     | 
    
         
            +
                assert fl.exclude?("x/CVS/y")
         
     | 
| 
      
 213 
     | 
    
         
            +
                assert fl.exclude?("x\\CVS\\y")
         
     | 
| 
      
 214 
     | 
    
         
            +
                assert fl.exclude?("x/core")
         
     | 
| 
      
 215 
     | 
    
         
            +
                assert fl.exclude?("x\\core")
         
     | 
| 
      
 216 
     | 
    
         
            +
              end
         
     | 
| 
      
 217 
     | 
    
         
            +
             
     | 
| 
      
 218 
     | 
    
         
            +
              def test_add_default_exclude_list
         
     | 
| 
      
 219 
     | 
    
         
            +
                fl = FileList.new
         
     | 
| 
      
 220 
     | 
    
         
            +
                fl.exclude(/~\d+$/)
         
     | 
| 
      
 221 
     | 
    
         
            +
                assert fl.exclude?("x/CVS/y")
         
     | 
| 
      
 222 
     | 
    
         
            +
                assert fl.exclude?("x\\CVS\\y")
         
     | 
| 
      
 223 
     | 
    
         
            +
                assert fl.exclude?("x/core")
         
     | 
| 
      
 224 
     | 
    
         
            +
                assert fl.exclude?("x\\core")
         
     | 
| 
      
 225 
     | 
    
         
            +
                assert fl.exclude?("x/abc~1")
         
     | 
| 
      
 226 
     | 
    
         
            +
              end
         
     | 
| 
      
 227 
     | 
    
         
            +
             
     | 
| 
      
 228 
     | 
    
         
            +
              def test_basic_array_functions
         
     | 
| 
      
 229 
     | 
    
         
            +
                f = FileList['b', 'c', 'a']
         
     | 
| 
      
 230 
     | 
    
         
            +
                assert_equal 'b', f.first
         
     | 
| 
      
 231 
     | 
    
         
            +
                assert_equal 'b', f[0]
         
     | 
| 
      
 232 
     | 
    
         
            +
                assert_equal 'a', f.last
         
     | 
| 
      
 233 
     | 
    
         
            +
                assert_equal 'a', f[2]
         
     | 
| 
      
 234 
     | 
    
         
            +
                assert_equal 'a', f[-1]
         
     | 
| 
      
 235 
     | 
    
         
            +
                assert_equal ['a', 'b', 'c'], f.sort
         
     | 
| 
      
 236 
     | 
    
         
            +
                f.sort!
         
     | 
| 
      
 237 
     | 
    
         
            +
                assert_equal ['a', 'b', 'c'], f
         
     | 
| 
      
 238 
     | 
    
         
            +
              end
         
     | 
| 
      
 239 
     | 
    
         
            +
             
     | 
| 
      
 240 
     | 
    
         
            +
              def create_test_data
         
     | 
| 
      
 241 
     | 
    
         
            +
                verbose(false) do
         
     | 
| 
      
 242 
     | 
    
         
            +
                  mkdir "testdata" unless File.exist? "testdata"
         
     | 
| 
      
 243 
     | 
    
         
            +
                  mkdir "testdata/CVS" rescue nil
         
     | 
| 
      
 244 
     | 
    
         
            +
                  touch "testdata/.dummy"
         
     | 
| 
      
 245 
     | 
    
         
            +
                  touch "testdata/x.bak"
         
     | 
| 
      
 246 
     | 
    
         
            +
                  touch "testdata/x~"
         
     | 
| 
      
 247 
     | 
    
         
            +
                  touch "testdata/core"
         
     | 
| 
      
 248 
     | 
    
         
            +
                  touch "testdata/x.c"
         
     | 
| 
      
 249 
     | 
    
         
            +
                  touch "testdata/xyz.c"
         
     | 
| 
      
 250 
     | 
    
         
            +
                  touch "testdata/abc.c"
         
     | 
| 
      
 251 
     | 
    
         
            +
                  touch "testdata/existing"
         
     | 
| 
      
 252 
     | 
    
         
            +
                end
         
     | 
| 
      
 253 
     | 
    
         
            +
              end
         
     | 
| 
      
 254 
     | 
    
         
            +
              
         
     | 
| 
      
 255 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,55 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rake'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'test/filecreation'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'fileutils'
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            class TestFileUtils < Test::Unit::TestCase
         
     | 
| 
      
 9 
     | 
    
         
            +
              include FileCreation
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              def test_rm_one_file
         
     | 
| 
      
 12 
     | 
    
         
            +
                create_file("testdata/a")
         
     | 
| 
      
 13 
     | 
    
         
            +
                FileUtils.rm_r "testdata/a"
         
     | 
| 
      
 14 
     | 
    
         
            +
                assert ! File.exist?("testdata/a")
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              def test_rm_two_files
         
     | 
| 
      
 18 
     | 
    
         
            +
                create_file("testdata/a")
         
     | 
| 
      
 19 
     | 
    
         
            +
                create_file("testdata/b")
         
     | 
| 
      
 20 
     | 
    
         
            +
                FileUtils.rm_r ["testdata/a", "testdata/b"]
         
     | 
| 
      
 21 
     | 
    
         
            +
                assert ! File.exist?("testdata/a")
         
     | 
| 
      
 22 
     | 
    
         
            +
                assert ! File.exist?("testdata/b")
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              def test_rm_filelist
         
     | 
| 
      
 26 
     | 
    
         
            +
                list = Rake::FileList.new << "testdata/a" << "testdata/b"
         
     | 
| 
      
 27 
     | 
    
         
            +
                list.each { |fn| create_file(fn) }
         
     | 
| 
      
 28 
     | 
    
         
            +
                FileUtils.rm_r list
         
     | 
| 
      
 29 
     | 
    
         
            +
                assert ! File.exist?("testdata/a")
         
     | 
| 
      
 30 
     | 
    
         
            +
                assert ! File.exist?("testdata/b")
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
              def test_verbose
         
     | 
| 
      
 34 
     | 
    
         
            +
                verbose true
         
     | 
| 
      
 35 
     | 
    
         
            +
                assert_equal true, verbose
         
     | 
| 
      
 36 
     | 
    
         
            +
                verbose false
         
     | 
| 
      
 37 
     | 
    
         
            +
                assert_equal false, verbose
         
     | 
| 
      
 38 
     | 
    
         
            +
                verbose(true){
         
     | 
| 
      
 39 
     | 
    
         
            +
                  assert_equal true, verbose
         
     | 
| 
      
 40 
     | 
    
         
            +
                }
         
     | 
| 
      
 41 
     | 
    
         
            +
                assert_equal false, verbose
         
     | 
| 
      
 42 
     | 
    
         
            +
              end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
              def test_nowrite
         
     | 
| 
      
 45 
     | 
    
         
            +
                nowrite true
         
     | 
| 
      
 46 
     | 
    
         
            +
                assert_equal true, nowrite
         
     | 
| 
      
 47 
     | 
    
         
            +
                nowrite false
         
     | 
| 
      
 48 
     | 
    
         
            +
                assert_equal false, nowrite
         
     | 
| 
      
 49 
     | 
    
         
            +
                nowrite(true){
         
     | 
| 
      
 50 
     | 
    
         
            +
                  assert_equal true, nowrite
         
     | 
| 
      
 51 
     | 
    
         
            +
                }
         
     | 
| 
      
 52 
     | 
    
         
            +
                assert_equal false, nowrite
         
     | 
| 
      
 53 
     | 
    
         
            +
              end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            end
         
     |