Skip to content

Commit

Permalink
Merge pull request #96 from ruby/unscoped-prerequisite-lookup
Browse files Browse the repository at this point in the history
Lookup prerequisites with same name outside of scope instead of matching self
  • Loading branch information
hsbt committed Jan 29, 2016
2 parents 845d0f6 + e9dd241 commit 290af47
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rake/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ def prerequisite_tasks
end

def lookup_prerequisite(prerequisite_name) # :nodoc:
application[prerequisite_name, @scope]
scoped_prerequisite_task = application[prerequisite_name, @scope]
if scoped_prerequisite_task == self
unscoped_prerequisite_task = application[prerequisite_name]
end
unscoped_prerequisite_task || scoped_prerequisite_task
end
private :lookup_prerequisite

Expand Down
30 changes: 30 additions & 0 deletions test/test_rake_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def test_prerequisite_tasks_fails_if_prerequisites_are_undefined
end

def test_prerequisite_tasks_honors_namespaces
task :b
a = b = nil
namespace "X" do
a = task :a => ["b", "c"]
Expand All @@ -221,6 +222,35 @@ def test_prerequisite_tasks_honors_namespaces
assert_equal [b, c], a.prerequisite_tasks
end

def test_prerequisite_tasks_finds_tasks_with_same_name_outside_namespace
b1 = nil
namespace "a" do
b1 = task :b => "b"
end
b2 = task :b

assert_equal [b2], b1.prerequisite_tasks
end

def test_prerequisite_tasks_in_nested_namespaces
m = task :m
a_c_m = a_b_m = a_m = nil
namespace "a" do
a_m = task :m

namespace "b" do
a_b_m = task :m => "m"
end

namespace "c" do
a_c_m = task :m => "a:m"
end
end

assert_equal [m], a_b_m.prerequisite_tasks
assert_equal [a_m], a_c_m.prerequisite_tasks
end

def test_all_prerequisite_tasks_includes_all_prerequisites
a = task :a => "b"
b = task :b => ["c", "d"]
Expand Down

0 comments on commit 290af47

Please sign in to comment.