Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed namespace task list bug.

  • Loading branch information...
commit 995b742dccaf0bfcbeb112054d9836b26794f84e 1 parent 298b939
@jimweirich authored
Showing with 39 additions and 13 deletions.
  1. +11 −2 lib/rake.rb
  2. +28 −11 test/test_namespace.rb
View
13 lib/rake.rb
@@ -1650,9 +1650,9 @@ def [](name)
@task_manager.lookup(name, @scope)
end
- # Return the list of tasks defined in this namespace.
+ # Return the list of tasks defined in this and nested namespaces.
def tasks
- @task_manager.tasks
+ @task_manager.tasks_in_scope(@scope)
end
end # NameSpace
@@ -1797,6 +1797,15 @@ def tasks
@tasks.values.sort_by { |t| t.name }
end
+ # List of all the tasks defined in the given scope (and its
+ # sub-scopes).
+ def tasks_in_scope(scope)
+ prefix = scope.join(":")
+ tasks.select { |t|
+ /^#{prefix}:/ =~ t.name
+ }
+ end
+
# Clear all tasks in this application.
def clear
@tasks.clear
View
39 test/test_namespace.rb
@@ -14,25 +14,42 @@
class TestNameSpace < Test::Unit::TestCase
include TestMethods
+ class TM
+ include Rake::TaskManager
+ end
+
def test_namespace_creation
- mgr = flexmock("TaskManager")
+ mgr = TM.new
ns = Rake::NameSpace.new(mgr, [])
assert_not_nil ns
end
def test_namespace_lookup
- mgr = flexmock("TaskManager")
- mgr.should_receive(:lookup).with(:t, ["a"]).
- and_return(:dummy).once
- ns = Rake::NameSpace.new(mgr, ["a"])
- assert_equal :dummy, ns[:t]
+ mgr = TM.new
+ ns = mgr.in_namespace("n") do
+ mgr.define_task(Rake::Task, "t")
+ end
+
+ assert_not_nil ns["t"]
+ assert_equal mgr["n:t"], ns["t"]
end
def test_namespace_reports_tasks_it_owns
- mgr = flexmock("TaskManager")
- mgr.should_receive(:tasks).with().
- and_return([:x, :y, :z]).once
- ns = Rake::NameSpace.new(mgr, ["a"])
- assert_equal [:x, :y, :z], ns.tasks
+ mgr = TM.new
+ nns = nil
+ ns = mgr.in_namespace("n") do
+ mgr.define_task(Rake::Task, :x)
+ mgr.define_task(Rake::Task, :y)
+ nns = mgr.in_namespace("nn") do
+ mgr.define_task(Rake::Task, :z)
+ end
+ end
+ mgr.in_namespace("m") do
+ mgr.define_task(Rake::Task, :x)
+ end
+
+ assert_equal ["n:nn:z", "n:x", "n:y"],
+ ns.tasks.map { |tsk| tsk.name }
+ assert_equal ["n:nn:z"], nns.tasks.map {|t| t.name}
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.