2011-06-23 18:11:55 -04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
2009-10-02 15:07:55 -04:00
|
|
|
require 'fileutils'
|
|
|
|
|
2011-06-23 18:11:55 -04:00
|
|
|
class TestRakeDefinitions < Rake::TestCase
|
2009-10-02 15:07:55 -04:00
|
|
|
include Rake
|
2011-05-15 07:55:52 -04:00
|
|
|
|
2011-06-23 18:11:55 -04:00
|
|
|
EXISTINGFILE = "existing"
|
2009-10-02 15:07:55 -04:00
|
|
|
|
|
|
|
def setup
|
2011-06-23 18:11:55 -04:00
|
|
|
super
|
|
|
|
|
2009-10-02 15:07:55 -04:00
|
|
|
Task.clear
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_task
|
|
|
|
done = false
|
|
|
|
task :one => [:two] do done = true end
|
|
|
|
task :two
|
|
|
|
task :three => [:one, :two]
|
|
|
|
check_tasks(:one, :two, :three)
|
|
|
|
assert done, "Should be done"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_file_task
|
|
|
|
done = false
|
2011-06-23 18:11:55 -04:00
|
|
|
file "one" => "two" do done = true end
|
|
|
|
file "two"
|
|
|
|
file "three" => ["one", "two"]
|
|
|
|
check_tasks("one", "two", "three")
|
2009-10-02 15:07:55 -04:00
|
|
|
assert done, "Should be done"
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_tasks(n1, n2, n3)
|
|
|
|
t = Task[n1]
|
|
|
|
assert Task === t, "Should be a Task"
|
|
|
|
assert_equal n1.to_s, t.name
|
2013-10-11 17:35:01 -04:00
|
|
|
assert_equal [n2.to_s], t.prerequisites.map { |n| n.to_s }
|
2009-10-02 15:07:55 -04:00
|
|
|
t.invoke
|
|
|
|
t2 = Task[n2]
|
|
|
|
assert_equal FileList[], t2.prerequisites
|
|
|
|
t3 = Task[n3]
|
2013-10-11 17:35:01 -04:00
|
|
|
assert_equal [n1.to_s, n2.to_s], t3.prerequisites.map { |n| n.to_s }
|
2009-10-02 15:07:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_incremental_definitions
|
|
|
|
runs = []
|
|
|
|
task :t1 => [:t2] do runs << "A"; 4321 end
|
|
|
|
task :t1 => [:t3] do runs << "B"; 1234 end
|
|
|
|
task :t1 => [:t3]
|
|
|
|
task :t2
|
|
|
|
task :t3
|
|
|
|
Task[:t1].invoke
|
|
|
|
assert_equal ["A", "B"], runs
|
|
|
|
assert_equal ["t2", "t3"], Task[:t1].prerequisites
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_missing_dependencies
|
2011-06-23 18:11:55 -04:00
|
|
|
task :x => ["missing"]
|
|
|
|
assert_raises(RuntimeError) { Task[:x].invoke }
|
2009-10-02 15:07:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_implicit_file_dependencies
|
|
|
|
runs = []
|
|
|
|
create_existing_file
|
|
|
|
task :y => [EXISTINGFILE] do |t| runs << t.name end
|
|
|
|
Task[:y].invoke
|
|
|
|
assert_equal runs, ['y']
|
|
|
|
end
|
|
|
|
|
|
|
|
private # ----------------------------------------------------------
|
|
|
|
|
|
|
|
def create_existing_file
|
|
|
|
Dir.mkdir File.dirname(EXISTINGFILE) unless
|
|
|
|
File.exist?(File.dirname(EXISTINGFILE))
|
|
|
|
open(EXISTINGFILE, "w") do |f| f.puts "HI" end unless
|
|
|
|
File.exist?(EXISTINGFILE)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|