PageRenderTime 123ms CodeModel.GetById 61ms app.highlight 32ms RepoModel.GetById 28ms app.codeStats 0ms

/tools/Ruby/lib/ruby/gems/1.8/gems/rake-0.9.2/test/test_rake_task_manager.rb

http://github.com/agross/netopenspace
Ruby | 145 lines | 121 code | 24 blank | 0 comment | 0 complexity | e655acd9fbc6b7d76b76cf4edc13709d MD5 | raw file
  1require File.expand_path('../helper', __FILE__)
  2
  3class TestRakeTaskManager < Rake::TestCase
  4
  5  def setup
  6    super
  7
  8    @tm = Rake::TestCase::TaskManager.new
  9  end
 10
 11  def test_create_task_manager
 12    refute_nil @tm
 13    assert_equal [], @tm.tasks
 14  end
 15
 16  def test_define_task
 17    t = @tm.define_task(Rake::Task, :t)
 18    assert_equal "t", t.name
 19    assert_equal @tm, t.application
 20  end
 21
 22  def test_name_lookup
 23    t = @tm.define_task(Rake::Task, :t)
 24    assert_equal t, @tm[:t]
 25  end
 26
 27  def test_namespace_task_create
 28    @tm.in_namespace("x") do
 29      t = @tm.define_task(Rake::Task, :t)
 30      assert_equal "x:t", t.name
 31    end
 32    assert_equal ["x:t"], @tm.tasks.collect { |t| t.name }
 33  end
 34
 35  def test_anonymous_namespace
 36    anon_ns = @tm.in_namespace(nil) do
 37      t = @tm.define_task(Rake::Task, :t)
 38      assert_equal "_anon_1:t", t.name
 39    end
 40    task = anon_ns[:t]
 41    assert_equal "_anon_1:t", task.name
 42  end
 43
 44  def test_create_filetask_in_namespace
 45    @tm.in_namespace("x") do
 46      t = @tm.define_task(Rake::FileTask, "fn")
 47      assert_equal "fn", t.name
 48    end
 49    assert_equal ["fn"], @tm.tasks.collect { |t| t.name }
 50  end
 51
 52  def test_namespace_yields_same_namespace_as_returned
 53    yielded_namespace = nil
 54    returned_namespace = @tm.in_namespace("x") do |ns|
 55      yielded_namespace = ns
 56    end
 57    assert_equal returned_namespace, yielded_namespace
 58  end
 59
 60  def test_name_lookup_with_implicit_file_tasks
 61    t = @tm["README.rdoc"]
 62    assert_equal "README.rdoc", t.name
 63    assert Rake::FileTask === t
 64  end
 65
 66  def test_name_lookup_with_nonexistent_task
 67    assert_raises(RuntimeError) {
 68      @tm["DOES NOT EXIST"]
 69    }
 70  end
 71
 72  def test_name_lookup_in_multiple_scopes
 73    aa = nil
 74    bb = nil
 75    xx = @tm.define_task(Rake::Task, :xx)
 76    top_z = @tm.define_task(Rake::Task, :z)
 77    @tm.in_namespace("a") do
 78      aa = @tm.define_task(Rake::Task, :aa)
 79      mid_z = @tm.define_task(Rake::Task, :z)
 80      @tm.in_namespace("b") do
 81        bb = @tm.define_task(Rake::Task, :bb)
 82        bot_z = @tm.define_task(Rake::Task, :z)
 83
 84        assert_equal ["a", "b"], @tm.current_scope
 85
 86        assert_equal bb, @tm["a:b:bb"]
 87        assert_equal aa, @tm["a:aa"]
 88        assert_equal xx, @tm["xx"]
 89        assert_equal bot_z, @tm["z"]
 90        assert_equal mid_z, @tm["^z"]
 91        assert_equal top_z, @tm["^^z"]
 92        assert_equal top_z, @tm["rake:z"]
 93      end
 94
 95      assert_equal ["a"], @tm.current_scope
 96
 97      assert_equal bb, @tm["a:b:bb"]
 98      assert_equal aa, @tm["a:aa"]
 99      assert_equal xx, @tm["xx"]
100      assert_equal bb, @tm["b:bb"]
101      assert_equal aa, @tm["aa"]
102      assert_equal mid_z, @tm["z"]
103      assert_equal top_z, @tm["^z"]
104      assert_equal top_z, @tm["rake:z"]
105    end
106
107    assert_equal [], @tm.current_scope
108
109    assert_equal [], xx.scope
110    assert_equal ['a'], aa.scope
111    assert_equal ['a', 'b'], bb.scope
112  end
113
114  def test_lookup_with_explicit_scopes
115    t1, t2, t3, s = (0...4).collect { nil }
116    t1 = @tm.define_task(Rake::Task, :t)
117    @tm.in_namespace("a") do
118      t2 = @tm.define_task(Rake::Task, :t)
119      s =  @tm.define_task(Rake::Task, :s)
120      @tm.in_namespace("b") do
121        t3 = @tm.define_task(Rake::Task, :t)
122      end
123    end
124    assert_equal t1, @tm[:t, []]
125    assert_equal t2, @tm[:t, ["a"]]
126    assert_equal t3, @tm[:t, ["a", "b"]]
127    assert_equal s,  @tm[:s, ["a", "b"]]
128    assert_equal s,  @tm[:s, ["a"]]
129  end
130
131  def test_correctly_scoped_prerequisites_are_invoked
132    values = []
133    @tm = Rake::Application.new
134    @tm.define_task(Rake::Task, :z) do values << "top z" end
135    @tm.in_namespace("a") do
136      @tm.define_task(Rake::Task, :z) do values << "next z" end
137      @tm.define_task(Rake::Task, :x => :z)
138    end
139
140    @tm["a:x"].invoke
141    assert_equal ["next z"], values
142  end
143
144end
145