rant 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +504 -0
 - data/README +203 -0
 - data/Rantfile +104 -0
 - data/TODO +19 -0
 - data/bin/rant +12 -0
 - data/bin/rant-import +12 -0
 - data/devel-notes +50 -0
 - data/doc/configure.rdoc +40 -0
 - data/doc/csharp.rdoc +74 -0
 - data/doc/rant-import.rdoc +32 -0
 - data/doc/rant.rdoc +24 -0
 - data/doc/rantfile.rdoc +227 -0
 - data/doc/rubyproject.rdoc +210 -0
 - data/lib/rant.rb +9 -0
 - data/lib/rant/cs_compiler.rb +334 -0
 - data/lib/rant/import.rb +291 -0
 - data/lib/rant/import/rubydoc.rb +125 -0
 - data/lib/rant/import/rubypackage.rb +417 -0
 - data/lib/rant/import/rubytest.rb +97 -0
 - data/lib/rant/plugin/README +50 -0
 - data/lib/rant/plugin/configure.rb +345 -0
 - data/lib/rant/plugin/csharp.rb +275 -0
 - data/lib/rant/plugin_methods.rb +41 -0
 - data/lib/rant/rantenv.rb +217 -0
 - data/lib/rant/rantfile.rb +664 -0
 - data/lib/rant/rantlib.rb +1118 -0
 - data/lib/rant/rantsys.rb +258 -0
 - data/lib/rant/rantvar.rb +82 -0
 - data/rantmethods.rb +79 -0
 - data/run_import +7 -0
 - data/run_rant +7 -0
 - data/setup.rb +1360 -0
 - data/test/Rantfile +2 -0
 - data/test/plugin/configure/Rantfile +47 -0
 - data/test/plugin/configure/test_configure.rb +58 -0
 - data/test/plugin/csharp/Hello.cs +10 -0
 - data/test/plugin/csharp/Rantfile +30 -0
 - data/test/plugin/csharp/src/A.cs +8 -0
 - data/test/plugin/csharp/src/B.cs +8 -0
 - data/test/plugin/csharp/test_csharp.rb +99 -0
 - data/test/project1/Rantfile +127 -0
 - data/test/project1/test_project.rb +203 -0
 - data/test/project2/buildfile +14 -0
 - data/test/project2/rantfile.rb +20 -0
 - data/test/project2/sub1/Rantfile +12 -0
 - data/test/project2/test_project.rb +87 -0
 - data/test/project_rb1/README +14 -0
 - data/test/project_rb1/bin/wgrep +5 -0
 - data/test/project_rb1/lib/wgrep.rb +56 -0
 - data/test/project_rb1/rantfile.rb +30 -0
 - data/test/project_rb1/test/tc_wgrep.rb +21 -0
 - data/test/project_rb1/test/text +3 -0
 - data/test/project_rb1/test_project_rb1.rb +153 -0
 - data/test/test_env.rb +47 -0
 - data/test/test_filetask.rb +57 -0
 - data/test/test_lighttask.rb +49 -0
 - data/test/test_metatask.rb +29 -0
 - data/test/test_rant_interface.rb +65 -0
 - data/test/test_sys.rb +61 -0
 - data/test/test_task.rb +115 -0
 - data/test/toplevel.rf +11 -0
 - data/test/ts_all.rb +4 -0
 - data/test/tutil.rb +95 -0
 - metadata +133 -0
 
| 
         @@ -0,0 +1,57 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
      
 2 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rant/rantlib'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            $test_filetask_file = File.expand_path(__FILE__)
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            class TestFileTask < Test::Unit::TestCase
         
     | 
| 
      
 8 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
                def teardown
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                def test_needed_non_existent
         
     | 
| 
      
 14 
     | 
    
         
            +
            	run = false
         
     | 
| 
      
 15 
     | 
    
         
            +
            	t = Rant::FileTask.new(nil, "non_existent") { run = true }
         
     | 
| 
      
 16 
     | 
    
         
            +
            	assert(t.needed?,
         
     | 
| 
      
 17 
     | 
    
         
            +
            	    "`non_existent' doesn't exist, so filetask is needed")
         
     | 
| 
      
 18 
     | 
    
         
            +
            	assert(!run,
         
     | 
| 
      
 19 
     | 
    
         
            +
            	    "only FileTask#needed? was called, which shouldn't run task block")
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
                def test_needed_no_dep
         
     | 
| 
      
 22 
     | 
    
         
            +
            	run = false
         
     | 
| 
      
 23 
     | 
    
         
            +
            	t = Rant.file $test_filetask_file do
         
     | 
| 
      
 24 
     | 
    
         
            +
            	    run = true
         
     | 
| 
      
 25 
     | 
    
         
            +
            	end
         
     | 
| 
      
 26 
     | 
    
         
            +
            	assert(!t.needed?,
         
     | 
| 
      
 27 
     | 
    
         
            +
            	    "file exists and has no prerequisite, so needed? should return false")
         
     | 
| 
      
 28 
     | 
    
         
            +
            	assert(!run)
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
                def test_single_dep
         
     | 
| 
      
 31 
     | 
    
         
            +
            	tr = false
         
     | 
| 
      
 32 
     | 
    
         
            +
            	t = Rant.task :t do
         
     | 
| 
      
 33 
     | 
    
         
            +
            	    tr = true
         
     | 
| 
      
 34 
     | 
    
         
            +
            	end
         
     | 
| 
      
 35 
     | 
    
         
            +
            	run = false
         
     | 
| 
      
 36 
     | 
    
         
            +
            	f = Rant.file "testfile" => :t do
         
     | 
| 
      
 37 
     | 
    
         
            +
            	    run = true
         
     | 
| 
      
 38 
     | 
    
         
            +
            	end
         
     | 
| 
      
 39 
     | 
    
         
            +
            	f.invoke
         
     | 
| 
      
 40 
     | 
    
         
            +
            	assert(tr)
         
     | 
| 
      
 41 
     | 
    
         
            +
            	assert(run)
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
                def test_prerequisites
         
     | 
| 
      
 44 
     | 
    
         
            +
            	Rant.file "a" do
         
     | 
| 
      
 45 
     | 
    
         
            +
            	    true
         
     | 
| 
      
 46 
     | 
    
         
            +
            	end
         
     | 
| 
      
 47 
     | 
    
         
            +
            	Rant.file "b" do
         
     | 
| 
      
 48 
     | 
    
         
            +
            	    true
         
     | 
| 
      
 49 
     | 
    
         
            +
            	end
         
     | 
| 
      
 50 
     | 
    
         
            +
            	f = Rant.file "c" => %w(a b) do |t|
         
     | 
| 
      
 51 
     | 
    
         
            +
            	    assert_equal(t.prerequisites, %w(a b),
         
     | 
| 
      
 52 
     | 
    
         
            +
            		"prerequisites should always be an array of _strings_")
         
     | 
| 
      
 53 
     | 
    
         
            +
            	    true
         
     | 
| 
      
 54 
     | 
    
         
            +
            	end
         
     | 
| 
      
 55 
     | 
    
         
            +
            	f.invoke
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,49 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
      
 2 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rant/rantlib'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            class TestLightTask < Test::Unit::TestCase
         
     | 
| 
      
 7 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 8 
     | 
    
         
            +
            	@app = Rant::RantApp.new %w()
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
                def teardown
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
                # shortcut for Rant::LightTask.new
         
     | 
| 
      
 13 
     | 
    
         
            +
                def lt(*args, &block)
         
     | 
| 
      
 14 
     | 
    
         
            +
            	Rant::LightTask.new(*[@app, args].flatten, &block)
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
                def test_init
         
     | 
| 
      
 17 
     | 
    
         
            +
            	t = lt :tinit
         
     | 
| 
      
 18 
     | 
    
         
            +
            	assert(t.needed?,
         
     | 
| 
      
 19 
     | 
    
         
            +
            	    "needed? should be true after creation without " +
         
     | 
| 
      
 20 
     | 
    
         
            +
            	    "`needed' block")
         
     | 
| 
      
 21 
     | 
    
         
            +
            	assert(!t.done?)
         
     | 
| 
      
 22 
     | 
    
         
            +
            	assert_equal(t.name, "tinit",
         
     | 
| 
      
 23 
     | 
    
         
            +
            	    "task name should always be a string, despite creation with symbol")
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
                def test_with_blocks
         
     | 
| 
      
 26 
     | 
    
         
            +
            	run = false
         
     | 
| 
      
 27 
     | 
    
         
            +
            	nr = false
         
     | 
| 
      
 28 
     | 
    
         
            +
            	t = lt :with_blocks do |a|
         
     | 
| 
      
 29 
     | 
    
         
            +
            	    a.needed {
         
     | 
| 
      
 30 
     | 
    
         
            +
            		nr = true
         
     | 
| 
      
 31 
     | 
    
         
            +
            	    }
         
     | 
| 
      
 32 
     | 
    
         
            +
            	    a.act do |l|
         
     | 
| 
      
 33 
     | 
    
         
            +
            		assert_equal(l, t,
         
     | 
| 
      
 34 
     | 
    
         
            +
            		    "act block should get the LightTask as argument")
         
     | 
| 
      
 35 
     | 
    
         
            +
            		run = true
         
     | 
| 
      
 36 
     | 
    
         
            +
            	    end
         
     | 
| 
      
 37 
     | 
    
         
            +
            	end
         
     | 
| 
      
 38 
     | 
    
         
            +
            	assert(t.needed?,
         
     | 
| 
      
 39 
     | 
    
         
            +
            	    "needed block returns true")
         
     | 
| 
      
 40 
     | 
    
         
            +
            	assert(nr,
         
     | 
| 
      
 41 
     | 
    
         
            +
            	    "`needed' block should have been run")
         
     | 
| 
      
 42 
     | 
    
         
            +
            	assert(t.invoke,
         
     | 
| 
      
 43 
     | 
    
         
            +
            	    "invoke should return true because task was needed")
         
     | 
| 
      
 44 
     | 
    
         
            +
            	assert(run,
         
     | 
| 
      
 45 
     | 
    
         
            +
            	    "task should have been run")
         
     | 
| 
      
 46 
     | 
    
         
            +
            	assert(!t.needed?,
         
     | 
| 
      
 47 
     | 
    
         
            +
            	    "task shouldn't be needed? after first run")
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,29 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
      
 2 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rant/rantlib'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'tutil'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            class TestMetaTask < Test::Unit::TestCase
         
     | 
| 
      
 7 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 8 
     | 
    
         
            +
            	@app = Rant::RantApp.new %w()
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
                def teardown
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
                def test_with_single_task
         
     | 
| 
      
 13 
     | 
    
         
            +
            	run = false
         
     | 
| 
      
 14 
     | 
    
         
            +
            	t = @app.task :t do run = true end
         
     | 
| 
      
 15 
     | 
    
         
            +
            	mt = MetaTask.for_task t
         
     | 
| 
      
 16 
     | 
    
         
            +
            	assert_equal(t.name, mt.name,
         
     | 
| 
      
 17 
     | 
    
         
            +
            	    "MetaTask should have name of contained task(s).")
         
     | 
| 
      
 18 
     | 
    
         
            +
            	if t.needed?
         
     | 
| 
      
 19 
     | 
    
         
            +
            	    assert(mt.needed?,
         
     | 
| 
      
 20 
     | 
    
         
            +
            		"MetaTask should be needed? if only contained task is needed?")
         
     | 
| 
      
 21 
     | 
    
         
            +
            	    mt.invoke
         
     | 
| 
      
 22 
     | 
    
         
            +
            	    assert(run,
         
     | 
| 
      
 23 
     | 
    
         
            +
            		"only contained task was needed?, so it should get invoked")
         
     | 
| 
      
 24 
     | 
    
         
            +
            	else
         
     | 
| 
      
 25 
     | 
    
         
            +
            	    assert(!mt.needed?,
         
     | 
| 
      
 26 
     | 
    
         
            +
            		"MetaTask should return false from needed? because the only contained task does also.")
         
     | 
| 
      
 27 
     | 
    
         
            +
            	end
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,65 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
      
 2 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rant'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'tutil'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            $testDir ||= File.expand_path(File.dirname(__FILE__))
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            class TestRantInterface < Test::Unit::TestCase
         
     | 
| 
      
 9 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 10 
     | 
    
         
            +
            	# Ensure we run in test directory.
         
     | 
| 
      
 11 
     | 
    
         
            +
            	Dir.chdir($testDir) unless Dir.pwd == $testDir
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
                def teardown
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
                def test_cmd_targets
         
     | 
| 
      
 16 
     | 
    
         
            +
            	@app = RantApp.new("-f non_existent", "target", "-aforced_target")
         
     | 
| 
      
 17 
     | 
    
         
            +
            	op = capture_stderr {
         
     | 
| 
      
 18 
     | 
    
         
            +
            	    assert_equal(@app.run, 1,
         
     | 
| 
      
 19 
     | 
    
         
            +
            		"Rant should fail because there is no such Rantfile.")
         
     | 
| 
      
 20 
     | 
    
         
            +
            	}
         
     | 
| 
      
 21 
     | 
    
         
            +
            	assert(op =~ /\[ERROR\]/,
         
     | 
| 
      
 22 
     | 
    
         
            +
            	    "rant should print error message if -f RANTFILE not found")
         
     | 
| 
      
 23 
     | 
    
         
            +
            	assert_equal(@app.cmd_targets.size, 2,
         
     | 
| 
      
 24 
     | 
    
         
            +
            	    "there were to targets given on commandline")
         
     | 
| 
      
 25 
     | 
    
         
            +
            	assert(@app.cmd_targets.include?("target"))
         
     | 
| 
      
 26 
     | 
    
         
            +
            	assert(@app.cmd_targets.include?("forced_target"))
         
     | 
| 
      
 27 
     | 
    
         
            +
            	assert(@app.cmd_targets.first == "forced_target",
         
     | 
| 
      
 28 
     | 
    
         
            +
            	    "forced_target should run first")
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
                def test_envvar_on_cmdline
         
     | 
| 
      
 31 
     | 
    
         
            +
            	@app = RantApp.new("VAR=VAL")
         
     | 
| 
      
 32 
     | 
    
         
            +
            	assert_equal(@app.run, 0)
         
     | 
| 
      
 33 
     | 
    
         
            +
            	assert_equal(ENV["VAR"], "VAL",
         
     | 
| 
      
 34 
     | 
    
         
            +
            	    "rant should set arguments of form VAR=VAL in ENV")
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
                def test_envvar_on_cmdline_lc
         
     | 
| 
      
 37 
     | 
    
         
            +
            	@app = RantApp.new("var2=val2")
         
     | 
| 
      
 38 
     | 
    
         
            +
            	assert_equal(@app.run, 0)
         
     | 
| 
      
 39 
     | 
    
         
            +
            	assert_equal(ENV["var2"], "val2",
         
     | 
| 
      
 40 
     | 
    
         
            +
            	    "rant should set arguments of form var2=val2 in ENV")
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
                def test_opt_targets
         
     | 
| 
      
 43 
     | 
    
         
            +
            	@app = RantApp.new("--tasks")
         
     | 
| 
      
 44 
     | 
    
         
            +
            	@app.desc 'This is a "public" target.'
         
     | 
| 
      
 45 
     | 
    
         
            +
            	@app.task :public_task
         
     | 
| 
      
 46 
     | 
    
         
            +
            	@app.task :private_task
         
     | 
| 
      
 47 
     | 
    
         
            +
            	op = capture_stdout { 
         
     | 
| 
      
 48 
     | 
    
         
            +
            	    assert_equal(@app.run, 0)
         
     | 
| 
      
 49 
     | 
    
         
            +
            	}
         
     | 
| 
      
 50 
     | 
    
         
            +
            	assert(op =~ /\bpublic_task\b/,
         
     | 
| 
      
 51 
     | 
    
         
            +
            	    "rant -T output should contain name of described task")
         
     | 
| 
      
 52 
     | 
    
         
            +
            	assert(op !~ /private_task/,
         
     | 
| 
      
 53 
     | 
    
         
            +
            	    "rant -T output shouldn't contain name of not-described task")
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
                def test_opt_help
         
     | 
| 
      
 56 
     | 
    
         
            +
            	op = capture_stdout {
         
     | 
| 
      
 57 
     | 
    
         
            +
            	    assert_equal(Rant.run("--help"), 0,
         
     | 
| 
      
 58 
     | 
    
         
            +
            		"rant --help should return 0")
         
     | 
| 
      
 59 
     | 
    
         
            +
            	}
         
     | 
| 
      
 60 
     | 
    
         
            +
            	assert(!op.empty?,
         
     | 
| 
      
 61 
     | 
    
         
            +
            	    "rant --help should write to STDOUT")
         
     | 
| 
      
 62 
     | 
    
         
            +
            	assert(op.split("\n").size > 15,
         
     | 
| 
      
 63 
     | 
    
         
            +
            	    "rant --help should print at least 16 lines to STDOUT")
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
            end
         
     | 
    
        data/test/test_sys.rb
    ADDED
    
    | 
         @@ -0,0 +1,61 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
      
 2 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rant/rantlib'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'tutil'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            $testDir ||= File.expand_path(File.dirname(__FILE__))
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            class TestFileUtils < Test::Unit::TestCase
         
     | 
| 
      
 9 
     | 
    
         
            +
                include Rant::Sys
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 12 
     | 
    
         
            +
            	# Ensure we run in test directory.
         
     | 
| 
      
 13 
     | 
    
         
            +
            	Dir.chdir($testDir) unless Dir.pwd == $testDir
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
                def teardown
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                def test_ruby
         
     | 
| 
      
 19 
     | 
    
         
            +
            	op = capture_stdout do
         
     | 
| 
      
 20 
     | 
    
         
            +
            	    ruby('-e ""') { |succ, stat|
         
     | 
| 
      
 21 
     | 
    
         
            +
            		assert(succ)
         
     | 
| 
      
 22 
     | 
    
         
            +
            		assert_equal(stat, 0)
         
     | 
| 
      
 23 
     | 
    
         
            +
            	    }
         
     | 
| 
      
 24 
     | 
    
         
            +
            	end
         
     | 
| 
      
 25 
     | 
    
         
            +
            	assert(op =~ /\-e/i,
         
     | 
| 
      
 26 
     | 
    
         
            +
            	    "Sys should print command with arguments to $stdout")
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
                def test_split_path
         
     | 
| 
      
 29 
     | 
    
         
            +
            	pl = split_path("/home/stefan")
         
     | 
| 
      
 30 
     | 
    
         
            +
            	assert_equal(pl.size, 3,
         
     | 
| 
      
 31 
     | 
    
         
            +
            	    "/home/stefan should get split into 3 parts")
         
     | 
| 
      
 32 
     | 
    
         
            +
            	assert_equal(pl[0], "/")
         
     | 
| 
      
 33 
     | 
    
         
            +
            	assert_equal(pl[1], "home")
         
     | 
| 
      
 34 
     | 
    
         
            +
            	assert_equal(pl[2], "stefan")
         
     | 
| 
      
 35 
     | 
    
         
            +
            	pl = split_path("../")
         
     | 
| 
      
 36 
     | 
    
         
            +
            	assert_equal(pl.size, 1,
         
     | 
| 
      
 37 
     | 
    
         
            +
            	    '../ should be "split" into one element')
         
     | 
| 
      
 38 
     | 
    
         
            +
            	assert_equal(pl[0], "..")
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
                # perhaps this test should go into a seperate file
         
     | 
| 
      
 41 
     | 
    
         
            +
                def test_toplevel
         
     | 
| 
      
 42 
     | 
    
         
            +
            	assert_match(/\btd\b/, run_rant("-ftoplevel.rf"),
         
     | 
| 
      
 43 
     | 
    
         
            +
            	    "Sys module should print commands to stdout")
         
     | 
| 
      
 44 
     | 
    
         
            +
            	assert_equal(0, $?,
         
     | 
| 
      
 45 
     | 
    
         
            +
            	    "rant -ftoplevel.rf in test/ should be successfull")
         
     | 
| 
      
 46 
     | 
    
         
            +
                ensure
         
     | 
| 
      
 47 
     | 
    
         
            +
            	File.delete "td" if File.exist? "td"
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
                # ...ditto
         
     | 
| 
      
 50 
     | 
    
         
            +
                def test_name_error
         
     | 
| 
      
 51 
     | 
    
         
            +
            	File.open("name_error.rf", "w") { |f|
         
     | 
| 
      
 52 
     | 
    
         
            +
            	    f << "no_var_no_method\n"
         
     | 
| 
      
 53 
     | 
    
         
            +
            	}
         
     | 
| 
      
 54 
     | 
    
         
            +
            	out, err = capture_std do
         
     | 
| 
      
 55 
     | 
    
         
            +
            	    assert_equal(1, Rant.run("-fname_error.rf"))
         
     | 
| 
      
 56 
     | 
    
         
            +
            	end
         
     | 
| 
      
 57 
     | 
    
         
            +
            	assert_match(/Name\s*Error/i, err.split("\n").first)
         
     | 
| 
      
 58 
     | 
    
         
            +
                ensure
         
     | 
| 
      
 59 
     | 
    
         
            +
            	File.delete "name_error.rf" if File.exist? "name_error.rf"
         
     | 
| 
      
 60 
     | 
    
         
            +
                end
         
     | 
| 
      
 61 
     | 
    
         
            +
            end
         
     | 
    
        data/test/test_task.rb
    ADDED
    
    | 
         @@ -0,0 +1,115 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
      
 2 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rant/rantlib'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            $-w = true
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            class TestTask < Test::Unit::TestCase
         
     | 
| 
      
 8 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
                def teardown
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                def test_version
         
     | 
| 
      
 14 
     | 
    
         
            +
            	assert(Rant::VERSION.length >= 5)
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                def test_needed
         
     | 
| 
      
 18 
     | 
    
         
            +
            	run = false
         
     | 
| 
      
 19 
     | 
    
         
            +
            	t = Rant::Task.new(nil, :non_existent) { run = true }
         
     | 
| 
      
 20 
     | 
    
         
            +
            	assert(t.needed?,
         
     | 
| 
      
 21 
     | 
    
         
            +
            	    "Rant::Task should always be 'needed?' before first invocation")
         
     | 
| 
      
 22 
     | 
    
         
            +
            	assert(!run,
         
     | 
| 
      
 23 
     | 
    
         
            +
            	    "Rant::Task shouldn't get run when 'needed?' is called")
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                def test_invoke
         
     | 
| 
      
 27 
     | 
    
         
            +
            	run = false
         
     | 
| 
      
 28 
     | 
    
         
            +
            	block = lambda { run = true }
         
     | 
| 
      
 29 
     | 
    
         
            +
            	task = Rant::Task.new(nil, :test_run, &block)
         
     | 
| 
      
 30 
     | 
    
         
            +
            	task.invoke
         
     | 
| 
      
 31 
     | 
    
         
            +
            	assert(run, "block should have been executed")
         
     | 
| 
      
 32 
     | 
    
         
            +
            	assert(task.done?, "task is done")
         
     | 
| 
      
 33 
     | 
    
         
            +
            	assert(!task.needed?,
         
     | 
| 
      
 34 
     | 
    
         
            +
            	    "task is done, so 'needed?' should return false")
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                def test_fail
         
     | 
| 
      
 38 
     | 
    
         
            +
            	block = lambda { |t| t.fail "this task abortet itself" }
         
     | 
| 
      
 39 
     | 
    
         
            +
            	task = Rant::Task.new(nil, :test_fail, &block)
         
     | 
| 
      
 40 
     | 
    
         
            +
            	assert_raise(Rant::TaskFail,
         
     | 
| 
      
 41 
     | 
    
         
            +
            	    "run should throw Rant::TaskFail if block raises Exception") {
         
     | 
| 
      
 42 
     | 
    
         
            +
            	    task.invoke
         
     | 
| 
      
 43 
     | 
    
         
            +
            	}
         
     | 
| 
      
 44 
     | 
    
         
            +
            	assert(task.fail?)
         
     | 
| 
      
 45 
     | 
    
         
            +
            	assert(task.run?, "although task failed, it was ran")
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                def test_dependant
         
     | 
| 
      
 49 
     | 
    
         
            +
            	r1 = r2 = false
         
     | 
| 
      
 50 
     | 
    
         
            +
            	t1 = Rant::Task.new(nil, :t1) { r1 = true }
         
     | 
| 
      
 51 
     | 
    
         
            +
            	t2 = Rant::Task.new(nil, :t2) { r2 = true }
         
     | 
| 
      
 52 
     | 
    
         
            +
            	t1 << t2
         
     | 
| 
      
 53 
     | 
    
         
            +
            	t1.invoke
         
     | 
| 
      
 54 
     | 
    
         
            +
            	assert(r1)
         
     | 
| 
      
 55 
     | 
    
         
            +
            	assert(r2, "t1 depends on t2, so t2 should have been run")
         
     | 
| 
      
 56 
     | 
    
         
            +
            	assert(t1.done?)
         
     | 
| 
      
 57 
     | 
    
         
            +
            	assert(t2.done?)
         
     | 
| 
      
 58 
     | 
    
         
            +
            	assert(!t1.needed?)
         
     | 
| 
      
 59 
     | 
    
         
            +
            	assert(!t2.needed?)
         
     | 
| 
      
 60 
     | 
    
         
            +
                end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                def test_dependance_fails
         
     | 
| 
      
 63 
     | 
    
         
            +
            	t1 = Rant::Task.new(nil, :t1) { true }
         
     | 
| 
      
 64 
     | 
    
         
            +
            	t2 = Rant::Task.new(nil, :t2) { |t| t.fail }
         
     | 
| 
      
 65 
     | 
    
         
            +
            	t1 << t2
         
     | 
| 
      
 66 
     | 
    
         
            +
            	assert_raise(Rant::TaskFail,
         
     | 
| 
      
 67 
     | 
    
         
            +
            	    "dependency t2 failed, so t1 should fail too") {
         
     | 
| 
      
 68 
     | 
    
         
            +
            	    t1.invoke
         
     | 
| 
      
 69 
     | 
    
         
            +
            	}
         
     | 
| 
      
 70 
     | 
    
         
            +
            	assert(t1.fail?,
         
     | 
| 
      
 71 
     | 
    
         
            +
            	    "fail flag should be set for task if dependency fails")
         
     | 
| 
      
 72 
     | 
    
         
            +
            	assert(t2.fail?,
         
     | 
| 
      
 73 
     | 
    
         
            +
            	    "fail flag should be set for task if it fails")
         
     | 
| 
      
 74 
     | 
    
         
            +
                end
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                def test_task
         
     | 
| 
      
 77 
     | 
    
         
            +
            	run = false
         
     | 
| 
      
 78 
     | 
    
         
            +
            	t = Rant.task :t do |t|
         
     | 
| 
      
 79 
     | 
    
         
            +
            	    run = true
         
     | 
| 
      
 80 
     | 
    
         
            +
            	end
         
     | 
| 
      
 81 
     | 
    
         
            +
            	t.invoke
         
     | 
| 
      
 82 
     | 
    
         
            +
            	assert(run)
         
     | 
| 
      
 83 
     | 
    
         
            +
                end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                def test_dep_on_self
         
     | 
| 
      
 86 
     | 
    
         
            +
            	run = false
         
     | 
| 
      
 87 
     | 
    
         
            +
            	t = Rant.task :t => "t" do |t|
         
     | 
| 
      
 88 
     | 
    
         
            +
            	    run = true
         
     | 
| 
      
 89 
     | 
    
         
            +
            	end
         
     | 
| 
      
 90 
     | 
    
         
            +
            	th = Thread.new { t.invoke }
         
     | 
| 
      
 91 
     | 
    
         
            +
            	# shouldn't take half a second...
         
     | 
| 
      
 92 
     | 
    
         
            +
            	assert_equal(th.join(0.5), th,
         
     | 
| 
      
 93 
     | 
    
         
            +
            	    "task should remove dependency on itself")
         
     | 
| 
      
 94 
     | 
    
         
            +
            	assert(run,
         
     | 
| 
      
 95 
     | 
    
         
            +
            	    "task should get run despite dependency on itself")
         
     | 
| 
      
 96 
     | 
    
         
            +
                end
         
     | 
| 
      
 97 
     | 
    
         
            +
                def test_dep_on_self_in_deplist
         
     | 
| 
      
 98 
     | 
    
         
            +
            	rl = []
         
     | 
| 
      
 99 
     | 
    
         
            +
            	t1 = Rant.task :t1 do |t|
         
     | 
| 
      
 100 
     | 
    
         
            +
            	    rl << t.name
         
     | 
| 
      
 101 
     | 
    
         
            +
            	end
         
     | 
| 
      
 102 
     | 
    
         
            +
            	t2 = Rant.task :t2 do |t|
         
     | 
| 
      
 103 
     | 
    
         
            +
            	    rl << t.name
         
     | 
| 
      
 104 
     | 
    
         
            +
            	end
         
     | 
| 
      
 105 
     | 
    
         
            +
            	t3 = Rant.task :t3 => [:t1, :t3, :t2] do |t|
         
     | 
| 
      
 106 
     | 
    
         
            +
            	    rl << t.name
         
     | 
| 
      
 107 
     | 
    
         
            +
            	end
         
     | 
| 
      
 108 
     | 
    
         
            +
            	th = Thread.new { t3.invoke }
         
     | 
| 
      
 109 
     | 
    
         
            +
            	# shouldn't take half a second...
         
     | 
| 
      
 110 
     | 
    
         
            +
            	assert_equal(th.join(0.5), th,
         
     | 
| 
      
 111 
     | 
    
         
            +
            	    "task should remove dependency on itself from dependency list")
         
     | 
| 
      
 112 
     | 
    
         
            +
            	assert_equal(rl, %w(t1 t2 t3),
         
     | 
| 
      
 113 
     | 
    
         
            +
            	    "t3 was run and depends on [t1, t2] => run order: t1 t2 t3")
         
     | 
| 
      
 114 
     | 
    
         
            +
                end
         
     | 
| 
      
 115 
     | 
    
         
            +
            end
         
     | 
    
        data/test/toplevel.rf
    ADDED
    
    
    
        data/test/ts_all.rb
    ADDED
    
    
    
        data/test/tutil.rb
    ADDED
    
    | 
         @@ -0,0 +1,95 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
      
 2 
     | 
    
         
            +
            # This file contains methods that aid in testing Rant.
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            RANT_BIN = File.expand_path(
         
     | 
| 
      
 5 
     | 
    
         
            +
                File.join(File.dirname(__FILE__), "..", "run_rant"))
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            # Everything written to $stdout during +yield+ will be returned. No
         
     | 
| 
      
 8 
     | 
    
         
            +
            # output to $stdout.
         
     | 
| 
      
 9 
     | 
    
         
            +
            def capture_stdout
         
     | 
| 
      
 10 
     | 
    
         
            +
                tfn = "._ranttestcstdout.tmp"
         
     | 
| 
      
 11 
     | 
    
         
            +
                if File.exist? tfn
         
     | 
| 
      
 12 
     | 
    
         
            +
            	raise <<-EOD
         
     | 
| 
      
 13 
     | 
    
         
            +
            When testing Rant: `#{Dir.pwd + "/" + tfn}' exists.
         
     | 
| 
      
 14 
     | 
    
         
            +
              The testing process temporarily needs this file. Ensure that the
         
     | 
| 
      
 15 
     | 
    
         
            +
              file doesn't contain data useful for you and try to remove it.
         
     | 
| 
      
 16 
     | 
    
         
            +
              (Perhaps this file was left by an earlier testrun.)
         
     | 
| 
      
 17 
     | 
    
         
            +
            	EOD
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
                begin
         
     | 
| 
      
 20 
     | 
    
         
            +
            	stdout = $stdout
         
     | 
| 
      
 21 
     | 
    
         
            +
            	File.open(tfn, "w") { |tf|
         
     | 
| 
      
 22 
     | 
    
         
            +
            	    $stdout = tf
         
     | 
| 
      
 23 
     | 
    
         
            +
            	    yield
         
     | 
| 
      
 24 
     | 
    
         
            +
            	}
         
     | 
| 
      
 25 
     | 
    
         
            +
            	o = File.read tfn
         
     | 
| 
      
 26 
     | 
    
         
            +
                ensure
         
     | 
| 
      
 27 
     | 
    
         
            +
            	$stdout = stdout
         
     | 
| 
      
 28 
     | 
    
         
            +
            	File.delete tfn if File.exist? tfn
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
            end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
            def capture_stderr
         
     | 
| 
      
 33 
     | 
    
         
            +
                tfn = "._ranttestcstderr.tmp"
         
     | 
| 
      
 34 
     | 
    
         
            +
                if File.exist? tfn
         
     | 
| 
      
 35 
     | 
    
         
            +
            	raise <<-EOD
         
     | 
| 
      
 36 
     | 
    
         
            +
            When testing Rant: `#{Dir.pwd + "/" + tfn}' exists.
         
     | 
| 
      
 37 
     | 
    
         
            +
              The testing process temporarily needs this file. Ensure that the
         
     | 
| 
      
 38 
     | 
    
         
            +
              file doesn't contain data useful for you and try to remove it.
         
     | 
| 
      
 39 
     | 
    
         
            +
              (Perhaps this file was left by an earlier testrun.)
         
     | 
| 
      
 40 
     | 
    
         
            +
            	EOD
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
                begin
         
     | 
| 
      
 43 
     | 
    
         
            +
            	stderr = $stderr
         
     | 
| 
      
 44 
     | 
    
         
            +
            	File.open(tfn, "w") { |tf|
         
     | 
| 
      
 45 
     | 
    
         
            +
            	    $stderr = tf
         
     | 
| 
      
 46 
     | 
    
         
            +
            	    yield
         
     | 
| 
      
 47 
     | 
    
         
            +
            	}
         
     | 
| 
      
 48 
     | 
    
         
            +
            	o = File.read tfn
         
     | 
| 
      
 49 
     | 
    
         
            +
                ensure
         
     | 
| 
      
 50 
     | 
    
         
            +
            	$stderr = stderr
         
     | 
| 
      
 51 
     | 
    
         
            +
            	File.delete tfn if File.exist? tfn
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
            end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            def capture_std
         
     | 
| 
      
 56 
     | 
    
         
            +
                outfn = "._ranttestcstdout.tmp"
         
     | 
| 
      
 57 
     | 
    
         
            +
                errfn = "._ranttestcstderr.tmp"
         
     | 
| 
      
 58 
     | 
    
         
            +
                if File.exist? outfn
         
     | 
| 
      
 59 
     | 
    
         
            +
            	raise <<-EOD
         
     | 
| 
      
 60 
     | 
    
         
            +
            When testing Rant: `#{Dir.pwd + "/" + outfn}' exists.
         
     | 
| 
      
 61 
     | 
    
         
            +
              The testing process temporarily needs this file. Ensure that the
         
     | 
| 
      
 62 
     | 
    
         
            +
              file doesn't contain data useful for you and try to remove it.
         
     | 
| 
      
 63 
     | 
    
         
            +
              (Perhaps this file was left by an earlier testrun.)
         
     | 
| 
      
 64 
     | 
    
         
            +
            	EOD
         
     | 
| 
      
 65 
     | 
    
         
            +
                end
         
     | 
| 
      
 66 
     | 
    
         
            +
                if File.exist? errfn
         
     | 
| 
      
 67 
     | 
    
         
            +
            	raise <<-EOD
         
     | 
| 
      
 68 
     | 
    
         
            +
            When testing Rant: `#{Dir.pwd + "/" + errfn}' exists.
         
     | 
| 
      
 69 
     | 
    
         
            +
              The testing process temporarily needs this file. Ensure that the
         
     | 
| 
      
 70 
     | 
    
         
            +
              file doesn't contain data useful for you and try to remove it.
         
     | 
| 
      
 71 
     | 
    
         
            +
              (Perhaps this file was left by an earlier testrun.)
         
     | 
| 
      
 72 
     | 
    
         
            +
            	EOD
         
     | 
| 
      
 73 
     | 
    
         
            +
                end
         
     | 
| 
      
 74 
     | 
    
         
            +
                begin
         
     | 
| 
      
 75 
     | 
    
         
            +
            	stdout = $stdout
         
     | 
| 
      
 76 
     | 
    
         
            +
            	stderr = $stderr
         
     | 
| 
      
 77 
     | 
    
         
            +
            	File.open(outfn, "w") { |of|
         
     | 
| 
      
 78 
     | 
    
         
            +
            	    $stdout = of
         
     | 
| 
      
 79 
     | 
    
         
            +
            	    File.open(errfn, "w") { |ef|
         
     | 
| 
      
 80 
     | 
    
         
            +
            		$stderr = ef
         
     | 
| 
      
 81 
     | 
    
         
            +
            		yield
         
     | 
| 
      
 82 
     | 
    
         
            +
            	    }
         
     | 
| 
      
 83 
     | 
    
         
            +
            	}
         
     | 
| 
      
 84 
     | 
    
         
            +
            	[File.read(outfn), File.read(errfn)]
         
     | 
| 
      
 85 
     | 
    
         
            +
                ensure
         
     | 
| 
      
 86 
     | 
    
         
            +
            	$stderr = stderr
         
     | 
| 
      
 87 
     | 
    
         
            +
            	$stdout = stdout
         
     | 
| 
      
 88 
     | 
    
         
            +
            	File.delete outfn if File.exist? outfn
         
     | 
| 
      
 89 
     | 
    
         
            +
            	File.delete errfn if File.exist? errfn
         
     | 
| 
      
 90 
     | 
    
         
            +
                end
         
     | 
| 
      
 91 
     | 
    
         
            +
            end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
            def run_rant(*args)
         
     | 
| 
      
 94 
     | 
    
         
            +
                `#{Rant::Env::RUBY} #{RANT_BIN} #{args.join(' ')}`
         
     | 
| 
      
 95 
     | 
    
         
            +
            end
         
     |