drake 0.9.0.0.3.0 → 0.9.1.0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/CHANGES +9 -8
  2. data/CHANGES-drake +4 -0
  3. data/Rakefile +14 -49
  4. data/Rakefile-drake +2 -1
  5. data/bin/drake +4 -3
  6. data/doc/release_notes/rake-0.9.1.rdoc +52 -0
  7. data/lib/rake/dsl_definition.rb +19 -0
  8. data/lib/rake/version.rb +1 -1
  9. data/test/data/access/Rakefile +3 -1
  10. data/test/data/default/Rakefile +0 -2
  11. data/test/data/file_creation_task/Rakefile +0 -2
  12. data/test/data/multidesc/Rakefile +0 -2
  13. data/test/data/namespace/Rakefile +0 -2
  14. data/test/data/statusreturn/Rakefile +0 -2
  15. data/test/file_creation.rb +0 -2
  16. data/test/helper.rb +63 -0
  17. data/test/in_environment.rb +4 -1
  18. data/test/{parallel_setup.rb → setup_parallel.rb} +0 -0
  19. data/test/{serial_setup.rb → setup_serial.rb} +0 -0
  20. data/test/{lib/parallel_test.rb → test_parallel.rb} +3 -1
  21. data/test/{lib/rake_test.rb → test_rake.rb} +2 -5
  22. data/test/test_rake_application.rb +365 -0
  23. data/test/test_rake_application_options.rb +383 -0
  24. data/test/test_rake_clean.rb +14 -0
  25. data/test/{lib/definitions_test.rb → test_rake_definitions.rb} +5 -10
  26. data/test/test_rake_directory_task.rb +55 -0
  27. data/test/test_rake_dsl.rb +53 -0
  28. data/test/{lib/earlytime_test.rb → test_rake_early_time.rb} +2 -5
  29. data/test/{lib/extension_test.rb → test_rake_extension.rb} +2 -6
  30. data/test/{lib/file_creation_task_test.rb → test_rake_file_creation_task.rb} +7 -7
  31. data/test/{lib/filelist_test.rb → test_rake_file_list.rb} +18 -22
  32. data/test/test_rake_file_list_path_map.rb +8 -0
  33. data/test/{lib/file_task_test.rb → test_rake_file_task.rb} +22 -61
  34. data/test/{lib/fileutils_test.rb → test_rake_file_utils.rb} +11 -15
  35. data/test/{lib/ftp_test.rb → test_rake_ftp_file.rb} +5 -5
  36. data/test/{functional/session_based_tests.rb → test_rake_functional.rb} +35 -24
  37. data/test/test_rake_invocation_chain.rb +52 -0
  38. data/test/{lib/makefile_loader_test.rb → test_rake_makefile_loader.rb} +2 -5
  39. data/test/{lib/multitask_test.rb → test_rake_multi_task.rb} +5 -7
  40. data/test/{lib/namespace_test.rb → test_rake_name_space.rb} +4 -16
  41. data/test/{lib/package_task_test.rb → test_rake_package_task.rb} +2 -6
  42. data/test/{lib/pathmap_test.rb → test_rake_path_map.rb} +4 -58
  43. data/test/test_rake_path_map_explode.rb +31 -0
  44. data/test/test_rake_path_map_partial.rb +18 -0
  45. data/test/{lib/pseudo_status_test.rb → test_rake_pseudo_status.rb} +2 -8
  46. data/test/{lib/rdoc_task_test.rb → test_rake_rdoc_task.rb} +4 -7
  47. data/test/{lib/require_test.rb → test_rake_require.rb} +3 -9
  48. data/test/{lib/rules_test.rb → test_rake_rules.rb} +11 -13
  49. data/test/{lib/task_test.rb → test_rake_task.rb} +16 -183
  50. data/test/test_rake_task_argument_parsing.rb +126 -0
  51. data/test/{lib/task_arguments_test.rb → test_rake_task_arguments.rb} +2 -5
  52. data/test/{lib/tasklib_test.rb → test_rake_task_lib.rb} +2 -5
  53. data/test/{lib/task_manager_test.rb → test_rake_task_manager.rb} +7 -45
  54. data/test/test_rake_task_manager_argument_resolution.rb +36 -0
  55. data/test/test_rake_task_with_arguments.rb +162 -0
  56. data/test/{lib/test_task_test.rb → test_rake_test_task.rb} +52 -7
  57. data/test/{lib/top_level_functions_test.rb → test_rake_top_level_functions.rb} +8 -20
  58. data/test/{lib/win32_test.rb → test_rake_win32.rb} +5 -12
  59. data/test/{contrib/test_sys.rb → test_sys.rb} +2 -6
  60. metadata +62 -47
  61. data/lib/rake/dsl.rb +0 -2
  62. data/test/capture_stdout.rb +0 -26
  63. data/test/functional/functional_test.rb +0 -25
  64. data/test/lib/application_test.rb +0 -871
  65. data/test/lib/clean_test.rb +0 -15
  66. data/test/lib/dsl_test.rb +0 -52
  67. data/test/lib/invocation_chain_test.rb +0 -81
  68. data/test/lib/testtask_test.rb +0 -49
  69. data/test/rake_test_setup.rb +0 -41
  70. data/test/ruby_version_test.rb +0 -3
  71. data/test/test_helper.rb +0 -19
@@ -0,0 +1,52 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestRakeInvocationChain < Rake::TestCase
4
+
5
+ def setup
6
+ super
7
+
8
+ @empty = Rake::InvocationChain::EMPTY
9
+
10
+ @first_member = "A"
11
+ @second_member = "B"
12
+ @one = @empty.append(@first_member)
13
+ @two = @one.append(@second_member)
14
+ end
15
+
16
+ def test_append
17
+ chain = @empty.append("A")
18
+
19
+ assert_equal 'TOP => A', chain.to_s # HACK
20
+ end
21
+
22
+ def test_append_one_circular
23
+ ex = assert_raises RuntimeError do
24
+ @one.append(@first_member)
25
+ end
26
+ assert_match(/circular +dependency/i, ex.message)
27
+ assert_match(/A.*=>.*A/, ex.message)
28
+ end
29
+
30
+ def test_append_two_circular
31
+ ex = assert_raises RuntimeError do
32
+ @two.append(@first_member)
33
+ end
34
+ assert_match(/A.*=>.*B.*=>.*A/, ex.message)
35
+ end
36
+
37
+ def test_member_eh_one
38
+ assert @one.member?(@first_member)
39
+ end
40
+
41
+ def test_member_eh_two
42
+ assert @two.member?(@first_member)
43
+ assert @two.member?(@second_member)
44
+ end
45
+
46
+ def test_to_s_empty
47
+ assert_equal "TOP", @empty.to_s
48
+ assert_equal "TOP => A", @one.to_s
49
+ end
50
+
51
+ end
52
+
@@ -1,10 +1,7 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'rake'
1
+ require File.expand_path('../helper', __FILE__)
5
2
  require 'rake/loaders/makefile'
6
3
 
7
- class TestMakefileLoader < Test::Unit::TestCase
4
+ class TestRakeMakefileLoader < Rake::TestCase
8
5
  include Rake
9
6
 
10
7
  def test_parse
@@ -1,14 +1,13 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
1
+ require File.expand_path('../helper', __FILE__)
4
2
  require 'thread'
5
- require 'rake'
6
3
 
7
- ######################################################################
8
- class TestMultiTask < Test::Unit::TestCase
4
+ class TestRakeMultiTask < Rake::TestCase
9
5
  include Rake
6
+ include Rake::DSL
10
7
 
11
8
  def setup
9
+ super
10
+
12
11
  Task.clear
13
12
  @runs = ThreadSafeArray.new
14
13
  end
@@ -43,4 +42,3 @@ class TestMultiTask < Test::Unit::TestCase
43
42
  end
44
43
  end
45
44
 
46
-
@@ -1,18 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
- begin
4
- require 'rubygems'
5
- rescue LoadError
6
- # got no gems
7
- end
8
-
9
- require 'test/unit'
10
- require 'flexmock/test_unit'
11
- require 'rake'
12
- require 'test/rake_test_setup'
13
-
14
- class TestNameSpace < Test::Unit::TestCase
15
- include TestMethods
3
+ class TestRakeNameSpace < Rake::TestCase
16
4
 
17
5
  class TM
18
6
  include Rake::TaskManager
@@ -21,7 +9,7 @@ class TestNameSpace < Test::Unit::TestCase
21
9
  def test_namespace_creation
22
10
  mgr = TM.new
23
11
  ns = Rake::NameSpace.new(mgr, [])
24
- assert_not_nil ns
12
+ refute_nil ns
25
13
  end
26
14
 
27
15
  def test_namespace_lookup
@@ -30,7 +18,7 @@ class TestNameSpace < Test::Unit::TestCase
30
18
  mgr.define_task(Rake::Task, "t")
31
19
  end
32
20
 
33
- assert_not_nil ns["t"]
21
+ refute_nil ns["t"]
34
22
  assert_equal mgr["n:t"], ns["t"]
35
23
  end
36
24
 
@@ -1,11 +1,7 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
1
+ require File.expand_path('../helper', __FILE__)
4
2
  require 'rake/packagetask'
5
- require 'test/rake_test_setup'
6
3
 
7
- class TestPackageTask < Test::Unit::TestCase
8
- include TestMethods
4
+ class TestRakePackageTask < Rake::TestCase
9
5
 
10
6
  def test_initialize
11
7
  pkg = Rake::PackageTask.new("pkgr", "1.2.3") { |p|
@@ -1,12 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
- require 'test/unit'
4
- require 'test/rake_test_setup'
5
- require 'rake'
6
-
7
- # ====================================================================
8
- class TestPathMap < Test::Unit::TestCase
9
- include TestMethods
3
+ class TestRakePathMap < Rake::TestCase
10
4
 
11
5
  def test_returns_self_with_no_args
12
6
  assert_equal "abc.rb", "abc.rb".pathmap
@@ -88,7 +82,7 @@ class TestPathMap < Test::Unit::TestCase
88
82
  end
89
83
 
90
84
  def test_undefined_percent_causes_error
91
- assert_exception(ArgumentError) {
85
+ assert_raises(ArgumentError) {
92
86
  "dir/abc.rb".pathmap("%z")
93
87
  }
94
88
  end
@@ -132,7 +126,7 @@ class TestPathMap < Test::Unit::TestCase
132
126
  end
133
127
 
134
128
  def test_pattern_with_invalid_operator
135
- ex = assert_exception(ArgumentError) do
129
+ ex = assert_raises(ArgumentError) do
136
130
  "abc.xyz".pathmap("%{src,bin}z")
137
131
  end
138
132
  assert_match(/unknown.*pathmap.*spec.*z/i, ex.message)
@@ -161,51 +155,3 @@ class TestPathMap < Test::Unit::TestCase
161
155
  end
162
156
  end
163
157
 
164
- class TestPathMapExplode < Test::Unit::TestCase
165
- def setup
166
- String.class_eval { public :pathmap_explode }
167
- end
168
-
169
- def teardown
170
- String.class_eval { protected :pathmap_explode }
171
- end
172
-
173
- def test_explode
174
- assert_equal ['a'], 'a'.pathmap_explode
175
- assert_equal ['a', 'b'], 'a/b'.pathmap_explode
176
- assert_equal ['a', 'b', 'c'], 'a/b/c'.pathmap_explode
177
- assert_equal ['/', 'a'], '/a'.pathmap_explode
178
- assert_equal ['/', 'a', 'b'], '/a/b'.pathmap_explode
179
- assert_equal ['/', 'a', 'b', 'c'], '/a/b/c'.pathmap_explode
180
- if File::ALT_SEPARATOR
181
- assert_equal ['c:.', 'a'], 'c:a'.pathmap_explode
182
- assert_equal ['c:.', 'a', 'b'], 'c:a/b'.pathmap_explode
183
- assert_equal ['c:.', 'a', 'b', 'c'], 'c:a/b/c'.pathmap_explode
184
- assert_equal ['c:/', 'a'], 'c:/a'.pathmap_explode
185
- assert_equal ['c:/', 'a', 'b'], 'c:/a/b'.pathmap_explode
186
- assert_equal ['c:/', 'a', 'b', 'c'], 'c:/a/b/c'.pathmap_explode
187
- end
188
- end
189
- end
190
-
191
- class TestPathMapPartial < Test::Unit::TestCase
192
- def test_pathmap_partial
193
- @path = "1/2/file"
194
- def @path.call(n)
195
- pathmap_partial(n)
196
- end
197
- assert_equal("1", @path.call(1))
198
- assert_equal("1/2", @path.call(2))
199
- assert_equal("1/2", @path.call(3))
200
- assert_equal(".", @path.call(0))
201
- assert_equal("2", @path.call(-1))
202
- assert_equal("1/2", @path.call(-2))
203
- assert_equal("1/2", @path.call(-3))
204
- end
205
- end
206
-
207
- class TestFileListPathMap < Test::Unit::TestCase
208
- def test_file_list_supports_pathmap
209
- assert_equal ['a', 'b'], FileList['dir/a.rb', 'dir/b.rb'].pathmap("%n")
210
- end
211
- end
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestRakePathMapExplode < Rake::TestCase
4
+ def setup
5
+ super
6
+
7
+ String.class_eval { public :pathmap_explode }
8
+ end
9
+
10
+ def teardown
11
+ String.class_eval { protected :pathmap_explode }
12
+ end
13
+
14
+ def test_explode
15
+ assert_equal ['a'], 'a'.pathmap_explode
16
+ assert_equal ['a', 'b'], 'a/b'.pathmap_explode
17
+ assert_equal ['a', 'b', 'c'], 'a/b/c'.pathmap_explode
18
+ assert_equal ['/', 'a'], '/a'.pathmap_explode
19
+ assert_equal ['/', 'a', 'b'], '/a/b'.pathmap_explode
20
+ assert_equal ['/', 'a', 'b', 'c'], '/a/b/c'.pathmap_explode
21
+ if File::ALT_SEPARATOR
22
+ assert_equal ['c:.', 'a'], 'c:a'.pathmap_explode
23
+ assert_equal ['c:.', 'a', 'b'], 'c:a/b'.pathmap_explode
24
+ assert_equal ['c:.', 'a', 'b', 'c'], 'c:a/b/c'.pathmap_explode
25
+ assert_equal ['c:/', 'a'], 'c:/a'.pathmap_explode
26
+ assert_equal ['c:/', 'a', 'b'], 'c:/a/b'.pathmap_explode
27
+ assert_equal ['c:/', 'a', 'b', 'c'], 'c:/a/b/c'.pathmap_explode
28
+ end
29
+ end
30
+ end
31
+
@@ -0,0 +1,18 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestRakePathMapPartial < Rake::TestCase
4
+ def test_pathmap_partial
5
+ @path = "1/2/file"
6
+ def @path.call(n)
7
+ pathmap_partial(n)
8
+ end
9
+ assert_equal("1", @path.call(1))
10
+ assert_equal("1/2", @path.call(2))
11
+ assert_equal("1/2", @path.call(3))
12
+ assert_equal(".", @path.call(0))
13
+ assert_equal("2", @path.call(-1))
14
+ assert_equal("1/2", @path.call(-2))
15
+ assert_equal("1/2", @path.call(-3))
16
+ end
17
+ end
18
+
@@ -1,12 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
- require 'test/unit'
4
- require 'rake'
5
-
6
- require 'test/capture_stdout'
7
- require 'test/rake_test_setup'
8
-
9
- class PseudoStatusTest < Test::Unit::TestCase
3
+ class TestRakePseudoStatus < Rake::TestCase
10
4
  def test_with_zero_exit_status
11
5
  s = Rake::PseudoStatus.new
12
6
  assert_equal 0, s.exitstatus
@@ -1,7 +1,4 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'test/capture_stdout'
1
+ require File.expand_path('../helper', __FILE__)
5
2
  begin
6
3
  old_verbose = $VERBOSE
7
4
  $VERBOSE = nil
@@ -9,13 +6,13 @@ begin
9
6
  ensure
10
7
  $VERBOSE = old_verbose
11
8
  end
12
- require 'test/rake_test_setup'
13
9
 
14
- class TestRDocTask < Test::Unit::TestCase
10
+ class TestRakeRDocTask < Rake::TestCase
15
11
  include Rake
16
- include TestMethods
17
12
 
18
13
  def setup
14
+ super
15
+
19
16
  Task.clear
20
17
  end
21
18
 
@@ -1,12 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
- require 'test/unit'
4
- require 'rake'
5
- require 'test/rake_test_setup'
6
-
7
- # ====================================================================
8
- class TestRequire < Test::Unit::TestCase
9
- include TestMethods
3
+ class TestRakeRequire < Rake::TestCase
10
4
 
11
5
  def test_can_load_rake_library
12
6
  app = Rake::Application.new
@@ -32,7 +26,7 @@ class TestRequire < Test::Unit::TestCase
32
26
  def test_throws_error_if_library_not_found
33
27
  app = Rake::Application.new
34
28
  app.options.threads = Rake.application.options.threads
35
- ex = assert_exception(LoadError) {
29
+ ex = assert_raises(LoadError) {
36
30
  assert app.instance_eval {
37
31
  rake_require("testx", ['test/data/rakelib'], [])
38
32
  }
@@ -1,16 +1,9 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
1
+ require File.expand_path('../helper', __FILE__)
4
2
  require 'fileutils'
5
- require 'rake'
6
- require 'test/file_creation'
7
- require 'test/rake_test_setup'
8
3
 
9
4
  ######################################################################
10
- class TestRules < Test::Unit::TestCase
5
+ class TestRakeRules < Rake::TestCase
11
6
  include Rake
12
- include FileCreation
13
- include TestMethods
14
7
 
15
8
  SRCFILE = "testdata/abc.c"
16
9
  SRCFILE2 = "testdata/xyz.c"
@@ -20,12 +13,17 @@ class TestRules < Test::Unit::TestCase
20
13
  DOTFOOFILE = "testdata/.foo"
21
14
 
22
15
  def setup
16
+ super
17
+
23
18
  Task.clear
24
19
  @runs = ThreadSafeArray.new
20
+ FileUtils.mkdir_p 'testdata' # HACK use tmpdir
25
21
  end
26
22
 
27
23
  def teardown
28
24
  FileList['testdata/*'].uniq.each do |f| rm_r(f, :verbose=>false) end
25
+
26
+ super
29
27
  end
30
28
 
31
29
  def test_multiple_rules1
@@ -192,8 +190,8 @@ class TestRules < Test::Unit::TestCase
192
190
  rule '.o' => ['.c'] do |t|
193
191
  @runs << t.name
194
192
  end
195
- assert_exception(RuntimeError) { Task['testdata/x.obj'].invoke }
196
- assert_exception(RuntimeError) { Task['testdata/x.xyo'].invoke }
193
+ assert_raises(RuntimeError) { Task['testdata/x.obj'].invoke }
194
+ assert_raises(RuntimeError) { Task['testdata/x.xyo'].invoke }
197
195
  end
198
196
 
199
197
  def test_rule_rebuilds_obj_when_source_is_newer
@@ -333,7 +331,7 @@ class TestRules < Test::Unit::TestCase
333
331
  rule ".#{letter}" => ".#{prev}" do |t| puts "#{t.name}" end
334
332
  prev = letter
335
333
  end
336
- ex = assert_exception(Rake::RuleRecursionOverflowError) {
334
+ ex = assert_raises(Rake::RuleRecursionOverflowError) {
337
335
  Task["testdata/a.z"].invoke
338
336
  }
339
337
  assert_match(/a\.z => testdata\/a.y/, ex.message)
@@ -341,7 +339,7 @@ class TestRules < Test::Unit::TestCase
341
339
 
342
340
  def test_rules_with_bad_dependents_will_fail
343
341
  rule "a" => [ 1 ] do |t| puts t.name end
344
- assert_exception(RuntimeError) do Task['a'].invoke end
342
+ assert_raises(RuntimeError) do Task['a'].invoke end
345
343
  end
346
344
 
347
345
  end
@@ -1,25 +1,20 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
1
+ require File.expand_path('../helper', __FILE__)
4
2
  require 'fileutils'
5
- require 'rake'
6
- require 'test/rake_test_setup'
7
3
 
8
- ######################################################################
9
- class TestTask < Test::Unit::TestCase
10
- include CaptureStdout
4
+ class TestRakeTask < Rake::TestCase
11
5
  include Rake
12
- include TestMethods
13
- include Rake::DSL
14
6
 
15
7
  def setup
8
+ super
9
+
16
10
  Task.clear
17
11
  Rake::TaskManager.record_task_metadata = true
18
12
  end
19
13
 
20
14
  def teardown
21
- super
22
15
  Rake::TaskManager.record_task_metadata = false
16
+
17
+ super
23
18
  end
24
19
 
25
20
  def test_create
@@ -65,7 +60,7 @@ class TestTask < Test::Unit::TestCase
65
60
  t2 = task(:t2 => [:t1]) { |t| runlist << t.name }
66
61
  assert_equal ["t2"], t1.prerequisites
67
62
  assert_equal ["t1"], t2.prerequisites
68
- ex = assert_exception RuntimeError do
63
+ ex = assert_raises RuntimeError do
69
64
  t1.invoke
70
65
  end
71
66
  assert_match(/circular dependency/i, ex.message)
@@ -76,10 +71,10 @@ class TestTask < Test::Unit::TestCase
76
71
  Rake.application.options.dryrun = true
77
72
  runlist = ThreadSafeArray.new
78
73
  t1 = task(:t1) { |t| runlist << t.name; 3321 }
79
- out = capture_stderr { t1.invoke }
80
- assert_match(/execute .*t1/i, out)
81
- assert_match(/dry run/i, out)
82
- assert_no_match(/invoke/i, out)
74
+ _, err = capture_io { t1.invoke }
75
+ assert_match(/execute .*t1/i, err)
76
+ assert_match(/dry run/i, err)
77
+ refute_match(/invoke/i, err)
83
78
  assert_equal [], runlist
84
79
  ensure
85
80
  Rake.application.options.dryrun = false
@@ -88,11 +83,11 @@ class TestTask < Test::Unit::TestCase
88
83
  def test_tasks_can_be_traced
89
84
  Rake.application.options.trace = true
90
85
  t1 = task(:t1)
91
- out = capture_stderr {
86
+ _, err = capture_io {
92
87
  t1.invoke
93
88
  }
94
- assert_match(/invoke t1/i, out)
95
- assert_match(/execute t1/i, out)
89
+ assert_match(/invoke t1/i, err)
90
+ assert_match(/execute t1/i, err)
96
91
  ensure
97
92
  Rake.application.options.trace = false
98
93
  end
@@ -145,7 +140,7 @@ class TestTask < Test::Unit::TestCase
145
140
  def test_find
146
141
  task :tfind
147
142
  assert_equal "tfind", Task[:tfind].name
148
- ex = assert_exception(RuntimeError) { Task[:leaves] }
143
+ ex = assert_raises(RuntimeError) { Task[:leaves] }
149
144
  assert_equal "Don't know how to build task 'leaves'", ex.message
150
145
  end
151
146
 
@@ -206,7 +201,7 @@ class TestTask < Test::Unit::TestCase
206
201
  def test_prerequiste_tasks_fails_if_prerequisites_are_undefined
207
202
  a = task :a => ["b", "c"]
208
203
  b = task :b
209
- assert_exception(RuntimeError) do
204
+ assert_raises(RuntimeError) do
210
205
  a.prerequisite_tasks
211
206
  end
212
207
  end
@@ -287,165 +282,3 @@ class TestTask < Test::Unit::TestCase
287
282
  assert_equal "HI", t.comment
288
283
  end
289
284
  end
290
-
291
- ######################################################################
292
- class TestTaskWithArguments < Test::Unit::TestCase
293
- include CaptureStdout
294
- include Rake
295
- include TestMethods
296
- include Rake::DSL
297
-
298
- def setup
299
- super
300
- Task.clear
301
- Rake::TaskManager.record_task_metadata = true
302
- end
303
-
304
- def teardown
305
- Rake::TaskManager.record_task_metadata = false
306
- super
307
- end
308
-
309
- def test_no_args_given
310
- t = task :t
311
- assert_equal [], t.arg_names
312
- end
313
-
314
- def test_args_given
315
- t = task :t, :a, :b
316
- assert_equal [:a, :b], t.arg_names
317
- end
318
-
319
- def test_name_and_needs
320
- t = task(:t => [:pre])
321
- assert_equal "t", t.name
322
- assert_equal [], t.arg_names
323
- assert_equal ["pre"], t.prerequisites
324
- end
325
-
326
- def test_name_args_and_explicit_needs
327
- ignore_deprecations do
328
- t = task(:t, :x, :y, :needs => [:pre])
329
- assert_equal "t", t.name
330
- assert_equal [:x, :y], t.arg_names
331
- assert_equal ["pre"], t.prerequisites
332
- end
333
- end
334
-
335
- def test_illegal_keys_in_task_name_hash
336
- ignore_deprecations do
337
- assert_exception RuntimeError do
338
- t = task(:t, :x, :y => 1, :needs => [:pre])
339
- end
340
- end
341
- end
342
-
343
- def test_arg_list_is_empty_if_no_args_given
344
- t = task(:t) { |tt, args| assert_equal({}, args.to_hash) }
345
- t.invoke(1, 2, 3)
346
- end
347
-
348
- def test_tasks_can_access_arguments_as_hash
349
- t = task :t, :a, :b, :c do |tt, args|
350
- assert_equal({:a => 1, :b => 2, :c => 3}, args.to_hash)
351
- assert_equal 1, args[:a]
352
- assert_equal 2, args[:b]
353
- assert_equal 3, args[:c]
354
- assert_equal 1, args.a
355
- assert_equal 2, args.b
356
- assert_equal 3, args.c
357
- end
358
- t.invoke(1, 2, 3)
359
- end
360
-
361
- def test_actions_of_various_arity_are_ok_with_args
362
- notes = ThreadSafeArray.new
363
- t = task(:t, :x) do
364
- notes << :a
365
- end
366
- t.enhance do | |
367
- notes << :b
368
- end
369
- t.enhance do |task|
370
- notes << :c
371
- assert_kind_of Task, task
372
- end
373
- t.enhance do |t2, args|
374
- notes << :d
375
- assert_equal t, t2
376
- assert_equal({:x => 1}, args.to_hash)
377
- end
378
- assert_nothing_raised do t.invoke(1) end
379
- assert_equal [:a, :b, :c, :d], notes
380
- end
381
-
382
- def test_arguments_are_passed_to_block
383
- t = task(:t, :a, :b) { |tt, args|
384
- assert_equal( { :a => 1, :b => 2 }, args.to_hash )
385
- }
386
- t.invoke(1, 2)
387
- end
388
-
389
- def test_extra_parameters_are_ignored
390
- t = task(:t, :a) { |tt, args|
391
- assert_equal 1, args.a
392
- assert_nil args.b
393
- }
394
- t.invoke(1, 2)
395
- end
396
-
397
- def test_arguments_are_passed_to_all_blocks
398
- counter = 0
399
- t = task :t, :a
400
- task :t do |tt, args|
401
- assert_equal 1, args.a
402
- counter += 1
403
- end
404
- task :t do |tt, args|
405
- assert_equal 1, args.a
406
- counter += 1
407
- end
408
- t.invoke(1)
409
- assert_equal 2, counter
410
- end
411
-
412
- def test_block_with_no_parameters_is_ok
413
- t = task(:t) { }
414
- t.invoke(1, 2)
415
- end
416
-
417
- def test_name_with_args
418
- desc "T"
419
- t = task(:tt, :a, :b)
420
- assert_equal "tt", t.name
421
- assert_equal "T", t.comment
422
- assert_equal "[a,b]", t.arg_description
423
- assert_equal "tt[a,b]", t.name_with_args
424
- assert_equal [:a, :b],t.arg_names
425
- end
426
-
427
- def test_named_args_are_passed_to_prereqs
428
- value = nil
429
- pre = task(:pre, :rev) { |t, args| value = args.rev }
430
- t = task(:t, [:name, :rev] => [:pre])
431
- t.invoke("bill", "1.2")
432
- assert_equal "1.2", value
433
- end
434
-
435
- def test_args_not_passed_if_no_prereq_names
436
- pre = task(:pre) { |t, args|
437
- assert_equal({}, args.to_hash)
438
- assert_equal "bill", args.name
439
- }
440
- t = task(:t, [:name, :rev] => [:pre])
441
- t.invoke("bill", "1.2")
442
- end
443
-
444
- def test_args_not_passed_if_no_arg_names
445
- pre = task(:pre, :rev) { |t, args|
446
- assert_equal({}, args.to_hash)
447
- }
448
- t = task(:t => [:pre])
449
- t.invoke("bill", "1.2")
450
- end
451
- end