Permalink
Browse files

reevaluate prerequisites if they change. This allows a prerequisite t…

…o add additional prereqs to it's parent task
  • Loading branch information...
damphyr committed Jan 13, 2012
1 parent 47c6d8a commit 609ca3b434a7ff6689ca476a9ee5d7d22437042a
Showing with 23 additions and 1 deletion.
  1. +2 −0 lib/rake/task.rb
  2. +21 −1 test/test_rake_task.rb
@@ -171,10 +171,12 @@ def add_chain_to(exception, new_chain)

# Invoke all the prerequisites of a task.
def invoke_prerequisites(task_args, invocation_chain) # :nodoc:
original_size=prerequisite_tasks.size
prerequisite_tasks.each { |prereq|
prereq_args = task_args.new_scope(prereq.arg_names)
prereq.invoke_with_call_chain(prereq_args, invocation_chain)
}
invoke_prerequisites(task_args, invocation_chain) if prerequisite_tasks.size != original_size
end

# Format the trace flags for display.
@@ -202,7 +202,27 @@ def test_prerequiste_tasks_honors_namespaces

assert_equal [b, c], a.prerequisite_tasks
end


#Test the handling of prerequisite invocation when the list
#of prerequisites for a task is changed by a prerequisite
def test_dynamic_prerequisites
runlist = []
t1 = task(:t1 => [:t2]) { |t| runlist << t.name; 3321 }
t2 = task(:t2) { |t| task :t1=>:t3; runlist << t.name }
#although it adds a prerequisite to t2 it will do so after t2 is executed
t3 = task(:t3) { |t| task :t2=>:t4; runlist << t.name }
t4 = task(:t4) { |t| runlist << t.name }
assert_equal ["t2"], t1.prerequisites
assert_equal [], t2.prerequisites
t1.invoke
assert_equal ["t2","t3"], t1.prerequisites
#so, these have changed but not in time
#so you can't change prereqs on the same level
assert_equal ["t4"], t2.prerequisites
#but changing the prereqs of the "parent" works
assert_equal ["t2", "t3", "t1"], runlist
end

def test_timestamp_returns_now_if_all_prereqs_have_no_times
a = task :a => ["b", "c"]
b = task :b

0 comments on commit 609ca3b

Please sign in to comment.