rake 0.8.7 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. data/.gemtest +0 -0
  2. data/CHANGES +78 -9
  3. data/{README → README.rdoc} +14 -10
  4. data/RRR +9 -0
  5. data/Rakefile +100 -125
  6. data/TODO +1 -1
  7. data/bin/rake +4 -3
  8. data/doc/command_line_usage.rdoc +18 -6
  9. data/doc/glossary.rdoc +2 -2
  10. data/doc/jamis.rb +2 -2
  11. data/doc/proto_rake.rdoc +22 -22
  12. data/doc/rake.1.gz +0 -0
  13. data/doc/rakefile.rdoc +56 -33
  14. data/doc/rational.rdoc +6 -6
  15. data/doc/release_notes/rake-0.4.15.rdoc +1 -1
  16. data/doc/release_notes/rake-0.5.0.rdoc +1 -1
  17. data/doc/release_notes/rake-0.7.0.rdoc +1 -1
  18. data/doc/release_notes/rake-0.7.2.rdoc +3 -3
  19. data/doc/release_notes/rake-0.7.3.rdoc +2 -2
  20. data/doc/release_notes/rake-0.8.0.rdoc +1 -1
  21. data/doc/release_notes/rake-0.8.2.rdoc +3 -3
  22. data/doc/release_notes/rake-0.8.3.rdoc +2 -2
  23. data/doc/release_notes/rake-0.8.4.rdoc +1 -1
  24. data/doc/release_notes/rake-0.8.5.rdoc +1 -1
  25. data/doc/release_notes/rake-0.8.6.rdoc +1 -1
  26. data/doc/release_notes/rake-0.8.7.rdoc +1 -1
  27. data/doc/release_notes/rake-0.9.0.rdoc +112 -0
  28. data/doc/release_notes/rake-0.9.1.rdoc +52 -0
  29. data/doc/release_notes/rake-0.9.2.rdoc +49 -0
  30. data/install.rb +14 -12
  31. data/lib/rake/alt_system.rb +7 -6
  32. data/lib/rake/application.rb +589 -0
  33. data/lib/rake/classic_namespace.rb +1 -0
  34. data/lib/rake/clean.rb +2 -4
  35. data/lib/rake/cloneable.rb +25 -0
  36. data/lib/rake/contrib/compositepublisher.rb +2 -5
  37. data/lib/rake/contrib/ftptools.rb +5 -8
  38. data/lib/rake/contrib/publisher.rb +2 -8
  39. data/lib/rake/contrib/rubyforgepublisher.rb +2 -4
  40. data/lib/rake/contrib/sshpublisher.rb +4 -6
  41. data/lib/rake/contrib/sys.rb +7 -25
  42. data/lib/rake/default_loader.rb +10 -0
  43. data/lib/rake/dsl_definition.rb +167 -0
  44. data/lib/rake/early_time.rb +18 -0
  45. data/lib/rake/ext/core.rb +27 -0
  46. data/lib/rake/ext/module.rb +39 -0
  47. data/lib/rake/ext/string.rb +167 -0
  48. data/lib/rake/ext/time.rb +14 -0
  49. data/lib/rake/file_creation_task.rb +24 -0
  50. data/lib/rake/file_list.rb +403 -0
  51. data/lib/rake/file_task.rb +47 -0
  52. data/lib/rake/file_utils.rb +112 -0
  53. data/lib/rake/file_utils_ext.rb +142 -0
  54. data/lib/rake/gempackagetask.rb +6 -90
  55. data/lib/rake/invocation_chain.rb +51 -0
  56. data/lib/rake/invocation_exception_mixin.rb +16 -0
  57. data/lib/rake/loaders/makefile.rb +13 -15
  58. data/lib/rake/multi_task.rb +16 -0
  59. data/lib/rake/name_space.rb +25 -0
  60. data/lib/rake/packagetask.rb +13 -12
  61. data/lib/rake/pathmap.rb +1 -0
  62. data/lib/rake/pseudo_status.rb +24 -0
  63. data/lib/rake/rake_module.rb +29 -0
  64. data/lib/rake/rake_test_loader.rb +10 -2
  65. data/lib/rake/rdoctask.rb +211 -190
  66. data/lib/rake/ruby182_test_unit_fix.rb +9 -7
  67. data/lib/rake/rule_recursion_overflow_error.rb +20 -0
  68. data/lib/rake/runtest.rb +4 -6
  69. data/lib/rake/task.rb +327 -0
  70. data/lib/rake/task_argument_error.rb +7 -0
  71. data/lib/rake/task_arguments.rb +74 -0
  72. data/lib/rake/task_manager.rb +307 -0
  73. data/lib/rake/tasklib.rb +1 -2
  74. data/lib/rake/testtask.rb +57 -27
  75. data/lib/rake/version.rb +10 -0
  76. data/lib/rake/win32.rb +4 -4
  77. data/lib/rake.rb +29 -2470
  78. data/test/data/access/Rakefile +35 -0
  79. data/test/data/comments/Rakefile +18 -0
  80. data/test/data/default/Rakefile +1 -3
  81. data/test/data/deprecated_import/Rakefile +1 -0
  82. data/test/data/dryrun/Rakefile +1 -1
  83. data/test/data/extra/Rakefile +1 -0
  84. data/test/data/file_creation_task/Rakefile +1 -3
  85. data/test/data/multidesc/Rakefile +0 -2
  86. data/test/data/namespace/Rakefile +9 -2
  87. data/test/data/rakelib/test1.rb +1 -0
  88. data/test/data/statusreturn/Rakefile +0 -2
  89. data/test/data/verbose/Rakefile +34 -0
  90. data/test/{filecreation.rb → file_creation.rb} +11 -9
  91. data/test/helper.rb +44 -0
  92. data/test/in_environment.rb +11 -6
  93. data/test/test_rake.rb +3 -6
  94. data/test/test_rake_application.rb +364 -0
  95. data/test/test_rake_application_options.rb +382 -0
  96. data/test/{test_clean.rb → test_rake_clean.rb} +2 -4
  97. data/test/{test_definitions.rb → test_rake_definitions.rb} +7 -12
  98. data/test/test_rake_directory_task.rb +55 -0
  99. data/test/test_rake_dsl.rb +73 -0
  100. data/test/{test_earlytime.rb → test_rake_early_time.rb} +3 -7
  101. data/test/{test_extension.rb → test_rake_extension.rb} +4 -8
  102. data/test/{test_file_creation_task.rb → test_rake_file_creation_task.rb} +7 -7
  103. data/test/{test_filelist.rb → test_rake_file_list.rb} +45 -35
  104. data/test/test_rake_file_list_path_map.rb +8 -0
  105. data/test/{test_file_task.rb → test_rake_file_task.rb} +23 -62
  106. data/test/{test_fileutils.rb → test_rake_file_utils.rb} +34 -33
  107. data/test/{test_ftp.rb → test_rake_ftp_file.rb} +5 -5
  108. data/test/{session_functional.rb → test_rake_functional.rb} +173 -44
  109. data/test/test_rake_invocation_chain.rb +52 -0
  110. data/test/{test_makefile_loader.rb → test_rake_makefile_loader.rb} +2 -5
  111. data/test/{test_multitask.rb → test_rake_multi_task.rb} +18 -12
  112. data/test/{test_namespace.rb → test_rake_name_space.rb} +4 -16
  113. data/test/test_rake_package_task.rb +78 -0
  114. data/test/{test_pathmap.rb → test_rake_path_map.rb} +5 -58
  115. data/test/test_rake_path_map_explode.rb +31 -0
  116. data/test/test_rake_path_map_partial.rb +18 -0
  117. data/test/{test_pseudo_status.rb → test_rake_pseudo_status.rb} +2 -8
  118. data/test/{test_rdoc_task.rb → test_rake_rdoc_task.rb} +22 -29
  119. data/test/{test_require.rb → test_rake_require.rb} +11 -11
  120. data/test/{test_rules.rb → test_rake_rules.rb} +12 -15
  121. data/test/{test_tasks.rb → test_rake_task.rb} +75 -178
  122. data/test/test_rake_task_argument_parsing.rb +116 -0
  123. data/test/{test_task_arguments.rb → test_rake_task_arguments.rb} +7 -10
  124. data/test/{test_tasklib.rb → test_rake_task_lib.rb} +2 -5
  125. data/test/{test_task_manager.rb → test_rake_task_manager.rb} +12 -40
  126. data/test/test_rake_task_manager_argument_resolution.rb +36 -0
  127. data/test/test_rake_task_with_arguments.rb +162 -0
  128. data/test/test_rake_test_task.rb +122 -0
  129. data/test/{test_top_level_functions.rb → test_rake_top_level_functions.rb} +12 -22
  130. data/test/{test_win32.rb → test_rake_win32.rb} +21 -10
  131. data/test/test_sys.rb +20 -0
  132. metadata +129 -51
  133. data/test/capture_stdout.rb +0 -26
  134. data/test/contrib/test_sys.rb +0 -47
  135. data/test/functional.rb +0 -15
  136. data/test/rake_test_setup.rb +0 -24
  137. data/test/test_application.rb +0 -675
  138. data/test/test_invocation_chain.rb +0 -81
  139. data/test/test_package_task.rb +0 -118
  140. data/test/test_test_task.rb +0 -77
@@ -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,24 +1,28 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'rake/rdoctask'
5
- require 'test/rake_test_setup'
1
+ require File.expand_path('../helper', __FILE__)
2
+ begin
3
+ old_verbose = $VERBOSE
4
+ $VERBOSE = nil
5
+ require 'rake/rdoctask'
6
+ ensure
7
+ $VERBOSE = old_verbose
8
+ end
6
9
 
7
- class TestRDocTask < Test::Unit::TestCase
10
+ class TestRakeRDocTask < Rake::TestCase
8
11
  include Rake
9
- include TestMethods
10
-
12
+
11
13
  def setup
14
+ super
15
+
12
16
  Task.clear
13
17
  end
14
-
18
+
15
19
  def test_tasks_creation
16
20
  Rake::RDocTask.new
17
21
  assert Task[:rdoc]
18
22
  assert Task[:clobber_rdoc]
19
23
  assert Task[:rerdoc]
20
24
  end
21
-
25
+
22
26
  def test_tasks_creation_with_custom_name_symbol
23
27
  rd = Rake::RDocTask.new(:rdoc_dev)
24
28
  assert Task[:rdoc_dev]
@@ -26,7 +30,7 @@ class TestRDocTask < Test::Unit::TestCase
26
30
  assert Task[:rerdoc_dev]
27
31
  assert_equal :rdoc_dev, rd.name
28
32
  end
29
-
33
+
30
34
  def test_tasks_creation_with_custom_name_string
31
35
  rd = Rake::RDocTask.new("rdoc_dev")
32
36
  assert Task[:rdoc_dev]
@@ -34,7 +38,7 @@ class TestRDocTask < Test::Unit::TestCase
34
38
  assert Task[:rerdoc_dev]
35
39
  assert_equal "rdoc_dev", rd.name
36
40
  end
37
-
41
+
38
42
  def test_tasks_creation_with_custom_name_hash
39
43
  options = { :rdoc => "rdoc", :clobber_rdoc => "rdoc:clean", :rerdoc => "rdoc:force" }
40
44
  rd = Rake::RDocTask.new(options)
@@ -44,45 +48,34 @@ class TestRDocTask < Test::Unit::TestCase
44
48
  assert_raises(RuntimeError) { Task[:clobber_rdoc] }
45
49
  assert_equal options, rd.name
46
50
  end
47
-
51
+
48
52
  def test_tasks_creation_with_custom_name_hash_will_use_default_if_an_option_isnt_given
49
- rd = Rake::RDocTask.new(:clobber_rdoc => "rdoc:clean")
53
+ Rake::RDocTask.new(:clobber_rdoc => "rdoc:clean")
50
54
  assert Task[:rdoc]
51
55
  assert Task[:"rdoc:clean"]
52
56
  assert Task[:rerdoc]
53
57
  end
54
-
58
+
55
59
  def test_tasks_creation_with_custom_name_hash_raises_exception_if_invalid_option_given
56
60
  assert_raises(ArgumentError) do
57
61
  Rake::RDocTask.new(:foo => "bar")
58
62
  end
59
-
63
+
60
64
  begin
61
65
  Rake::RDocTask.new(:foo => "bar")
62
66
  rescue ArgumentError => e
63
67
  assert_match(/foo/, e.message)
64
68
  end
65
69
  end
66
-
67
- def test_inline_source_is_enabled_by_default
68
- rd = Rake::RDocTask.new
69
- assert rd.option_list.include?('--inline-source')
70
- end
71
-
70
+
72
71
  def test_inline_source_option_is_only_appended_if_option_not_already_given
73
72
  rd = Rake::RDocTask.new
74
73
  rd.options << '--inline-source'
75
74
  assert_equal 1, rd.option_list.grep('--inline-source').size
76
-
75
+
77
76
  rd = Rake::RDocTask.new
78
77
  rd.options << '-S'
79
78
  assert_equal 1, rd.option_list.grep('-S').size
80
79
  assert_equal 0, rd.option_list.grep('--inline-source').size
81
80
  end
82
-
83
- def test_inline_source_option_can_be_disabled
84
- rd = Rake::RDocTask.new
85
- rd.inline_source = false
86
- assert !rd.option_list.include?('--inline-source')
87
- end
88
81
  end
@@ -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
@@ -17,19 +11,25 @@ class TestRequire < Test::Unit::TestCase
17
11
 
18
12
  def test_wont_reload_rake_library
19
13
  app = Rake::Application.new
14
+
15
+ paths = ['test/data/rakelib']
16
+ loaded_files = []
17
+ app.rake_require("test2", paths, loaded_files)
18
+
20
19
  assert ! app.instance_eval {
21
- rake_require("test2", ['test/data/rakelib'], ['test2'])
20
+ rake_require("test2", paths, loaded_files)
22
21
  }
23
22
  end
24
23
 
25
24
  def test_throws_error_if_library_not_found
26
25
  app = Rake::Application.new
27
- ex = assert_exception(LoadError) {
26
+ ex = assert_raises(LoadError) {
28
27
  assert app.instance_eval {
29
28
  rake_require("testx", ['test/data/rakelib'], [])
30
29
  }
31
30
  }
32
- assert_match(/x/, ex.message)
31
+ assert_match(/(can *not|can't)\s+find/i, ex.message)
32
+ assert_match(/testx/, ex.message)
33
33
  end
34
34
  end
35
35
 
@@ -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/filecreation'
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 = []
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
@@ -97,7 +95,7 @@ class TestRules < Test::Unit::TestCase
97
95
  assert_equal [OBJFILE], @runs
98
96
  end
99
97
 
100
- def test_file_names_beginning_with_dot_can_be_tricked_into_refering_to_file
98
+ def test_file_names_beginning_with_dot_can_be_tricked_into_referring_to_file
101
99
  verbose(false) do
102
100
  chdir("testdata") do
103
101
  create_file('.foo')
@@ -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
@@ -278,7 +276,6 @@ class TestRules < Test::Unit::TestCase
278
276
  end
279
277
 
280
278
  def test_rule_with_proc_dependent_will_trigger
281
- ran = false
282
279
  mkdir_p("testdata/src/jw")
283
280
  create_file("testdata/src/jw/X.java")
284
281
  rule %r(classes/.*\.class) => [
@@ -334,7 +331,7 @@ class TestRules < Test::Unit::TestCase
334
331
  rule ".#{letter}" => ".#{prev}" do |t| puts "#{t.name}" end
335
332
  prev = letter
336
333
  end
337
- ex = assert_exception(Rake::RuleRecursionOverflowError) {
334
+ ex = assert_raises(Rake::RuleRecursionOverflowError) {
338
335
  Task["testdata/a.z"].invoke
339
336
  }
340
337
  assert_match(/a\.z => testdata\/a.y/, ex.message)
@@ -342,7 +339,7 @@ class TestRules < Test::Unit::TestCase
342
339
 
343
340
  def test_rules_with_bad_dependents_will_fail
344
341
  rule "a" => [ 1 ] do |t| puts t.name end
345
- assert_exception(RuntimeError) do Task['a'].invoke end
342
+ assert_raises(RuntimeError) do Task['a'].invoke end
346
343
  end
347
344
 
348
345
  end
@@ -1,20 +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/filecreation'
7
- require 'test/capture_stdout'
8
- require 'test/rake_test_setup'
9
-
10
- ######################################################################
11
- class TestTask < Test::Unit::TestCase
12
- include CaptureStdout
3
+
4
+ class TestRakeTask < Rake::TestCase
13
5
  include Rake
14
- include TestMethods
15
6
 
16
7
  def setup
8
+ super
9
+
17
10
  Task.clear
11
+ Rake::TaskManager.record_task_metadata = true
12
+ end
13
+
14
+ def teardown
15
+ Rake::TaskManager.record_task_metadata = false
16
+
17
+ super
18
18
  end
19
19
 
20
20
  def test_create
@@ -27,10 +27,13 @@ class TestTask < Test::Unit::TestCase
27
27
  assert_equal t, arg
28
28
  assert_nil t.source
29
29
  assert_equal [], t.sources
30
+ assert_equal 1, t.locations.size
31
+ assert_match(/#{Regexp.quote(__FILE__)}/, t.locations.first)
30
32
  end
31
33
 
32
34
  def test_inspect
33
- t = task(:foo, :needs => [:bar, :baz])
35
+ # t = task(:foo, :needs => [:bar, :baz])
36
+ t = task(:foo => [:bar, :baz])
34
37
  assert_equal "<Rake::Task foo => [bar, baz]>", t.inspect
35
38
  end
36
39
 
@@ -50,7 +53,7 @@ class TestTask < Test::Unit::TestCase
50
53
  t2 = task(:t2 => [:t1]) { |t| runlist << t.name }
51
54
  assert_equal ["t2"], t1.prerequisites
52
55
  assert_equal ["t1"], t2.prerequisites
53
- ex = assert_exception RuntimeError do
56
+ ex = assert_raises RuntimeError do
54
57
  t1.invoke
55
58
  end
56
59
  assert_match(/circular dependency/i, ex.message)
@@ -61,10 +64,10 @@ class TestTask < Test::Unit::TestCase
61
64
  Rake.application.options.dryrun = true
62
65
  runlist = []
63
66
  t1 = task(:t1) { |t| runlist << t.name; 3321 }
64
- out = capture_stdout { t1.invoke }
65
- assert_match(/execute .*t1/i, out)
66
- assert_match(/dry run/i, out)
67
- assert_no_match(/invoke/i, out)
67
+ _, err = capture_io { t1.invoke }
68
+ assert_match(/execute .*t1/i, err)
69
+ assert_match(/dry run/i, err)
70
+ refute_match(/invoke/i, err)
68
71
  assert_equal [], runlist
69
72
  ensure
70
73
  Rake.application.options.dryrun = false
@@ -73,11 +76,11 @@ class TestTask < Test::Unit::TestCase
73
76
  def test_tasks_can_be_traced
74
77
  Rake.application.options.trace = true
75
78
  t1 = task(:t1)
76
- out = capture_stdout {
79
+ _, err = capture_io {
77
80
  t1.invoke
78
81
  }
79
- assert_match(/invoke t1/i, out)
80
- assert_match(/execute t1/i, out)
82
+ assert_match(/invoke t1/i, err)
83
+ assert_match(/execute t1/i, err)
81
84
  ensure
82
85
  Rake.application.options.trace = false
83
86
  end
@@ -123,7 +126,7 @@ class TestTask < Test::Unit::TestCase
123
126
  def test_find
124
127
  task :tfind
125
128
  assert_equal "tfind", Task[:tfind].name
126
- ex = assert_exception(RuntimeError) { Task[:leaves] }
129
+ ex = assert_raises(RuntimeError) { Task[:leaves] }
127
130
  assert_equal "Don't know how to build task 'leaves'", ex.message
128
131
  end
129
132
 
@@ -174,6 +177,56 @@ class TestTask < Test::Unit::TestCase
174
177
  assert_equal ["b", "c"], Task[:a].prerequisites
175
178
  end
176
179
 
180
+ def test_prerequiste_tasks_returns_tasks_not_strings
181
+ a = task :a => ["b", "c"]
182
+ b = task :b
183
+ c = task :c
184
+ assert_equal [b, c], a.prerequisite_tasks
185
+ end
186
+
187
+ def test_prerequiste_tasks_fails_if_prerequisites_are_undefined
188
+ a = task :a => ["b", "c"]
189
+ b = task :b
190
+ assert_raises(RuntimeError) do
191
+ a.prerequisite_tasks
192
+ end
193
+ end
194
+
195
+ def test_prerequiste_tasks_honors_namespaces
196
+ a = b = nil
197
+ namespace "X" do
198
+ a = task :a => ["b", "c"]
199
+ b = task :b
200
+ end
201
+ c = task :c
202
+
203
+ assert_equal [b, c], a.prerequisite_tasks
204
+ end
205
+
206
+ def test_timestamp_returns_now_if_all_prereqs_have_no_times
207
+ a = task :a => ["b", "c"]
208
+ b = task :b
209
+ c = task :c
210
+
211
+ faux_stamp = 100
212
+ flexmock(Time, :now => faux_stamp)
213
+
214
+ assert_equal faux_stamp, a.timestamp
215
+ end
216
+
217
+ def test_timestamp_returns_latest_prereq_timestamp
218
+ a = task :a => ["b", "c"]
219
+ b = task :b
220
+ c = task :c
221
+
222
+ faux_stamp = 100
223
+ flexmock(Time, :now => faux_stamp-10)
224
+ flexmock(b, :timestamp => faux_stamp - 1)
225
+ flexmock(c, :timestamp => faux_stamp)
226
+
227
+ assert_equal faux_stamp, a.timestamp
228
+ end
229
+
177
230
  def test_investigation_output
178
231
  t1 = task(:t1 => [:t2, :t3]) { |t| runlist << t.name; 3321 }
179
232
  task(:t2)
@@ -216,159 +269,3 @@ class TestTask < Test::Unit::TestCase
216
269
  end
217
270
  end
218
271
 
219
- ######################################################################
220
- class TestTaskWithArguments < Test::Unit::TestCase
221
- include CaptureStdout
222
- include Rake
223
- include TestMethods
224
-
225
- def setup
226
- Task.clear
227
- end
228
-
229
- def test_no_args_given
230
- t = task :t
231
- assert_equal [], t.arg_names
232
- end
233
-
234
- def test_args_given
235
- t = task :t, :a, :b
236
- assert_equal [:a, :b], t.arg_names
237
- end
238
-
239
- def test_name_and_needs
240
- t = task(:t => [:pre])
241
- assert_equal "t", t.name
242
- assert_equal [], t.arg_names
243
- assert_equal ["pre"], t.prerequisites
244
- end
245
-
246
- def test_name_and_explicit_needs
247
- t = task(:t, :needs => [:pre])
248
- assert_equal "t", t.name
249
- assert_equal [], t.arg_names
250
- assert_equal ["pre"], t.prerequisites
251
- end
252
-
253
- def test_name_args_and_explicit_needs
254
- t = task(:t, :x, :y, :needs => [:pre])
255
- assert_equal "t", t.name
256
- assert_equal [:x, :y], t.arg_names
257
- assert_equal ["pre"], t.prerequisites
258
- end
259
-
260
- def test_illegal_keys_in_task_name_hash
261
- assert_exception RuntimeError do
262
- t = task(:t, :x, :y => 1, :needs => [:pre])
263
- end
264
- end
265
-
266
- def test_arg_list_is_empty_if_no_args_given
267
- t = task(:t) { |tt, args| assert_equal({}, args.to_hash) }
268
- t.invoke(1, 2, 3)
269
- end
270
-
271
- def test_tasks_can_access_arguments_as_hash
272
- t = task :t, :a, :b, :c do |tt, args|
273
- assert_equal({:a => 1, :b => 2, :c => 3}, args.to_hash)
274
- assert_equal 1, args[:a]
275
- assert_equal 2, args[:b]
276
- assert_equal 3, args[:c]
277
- assert_equal 1, args.a
278
- assert_equal 2, args.b
279
- assert_equal 3, args.c
280
- end
281
- t.invoke(1, 2, 3)
282
- end
283
-
284
- def test_actions_of_various_arity_are_ok_with_args
285
- notes = []
286
- t = task(:t, :x) do
287
- notes << :a
288
- end
289
- t.enhance do | |
290
- notes << :b
291
- end
292
- t.enhance do |task|
293
- notes << :c
294
- assert_kind_of Task, task
295
- end
296
- t.enhance do |t2, args|
297
- notes << :d
298
- assert_equal t, t2
299
- assert_equal({:x => 1}, args.to_hash)
300
- end
301
- assert_nothing_raised do t.invoke(1) end
302
- assert_equal [:a, :b, :c, :d], notes
303
- end
304
-
305
- def test_arguments_are_passed_to_block
306
- t = task(:t, :a, :b) { |tt, args|
307
- assert_equal( { :a => 1, :b => 2 }, args.to_hash )
308
- }
309
- t.invoke(1, 2)
310
- end
311
-
312
- def test_extra_parameters_are_ignored
313
- t = task(:t, :a) { |tt, args|
314
- assert_equal 1, args.a
315
- assert_nil args.b
316
- }
317
- t.invoke(1, 2)
318
- end
319
-
320
- def test_arguments_are_passed_to_all_blocks
321
- counter = 0
322
- t = task :t, :a
323
- task :t do |tt, args|
324
- assert_equal 1, args.a
325
- counter += 1
326
- end
327
- task :t do |tt, args|
328
- assert_equal 1, args.a
329
- counter += 1
330
- end
331
- t.invoke(1)
332
- assert_equal 2, counter
333
- end
334
-
335
- def test_block_with_no_parameters_is_ok
336
- t = task(:t) { }
337
- t.invoke(1, 2)
338
- end
339
-
340
- def test_name_with_args
341
- desc "T"
342
- t = task(:tt, :a, :b)
343
- assert_equal "tt", t.name
344
- assert_equal "T", t.comment
345
- assert_equal "[a,b]", t.arg_description
346
- assert_equal "tt[a,b]", t.name_with_args
347
- assert_equal [:a, :b],t.arg_names
348
- end
349
-
350
- def test_named_args_are_passed_to_prereqs
351
- value = nil
352
- pre = task(:pre, :rev) { |t, args| value = args.rev }
353
- t = task(:t, :name, :rev, :needs => [:pre])
354
- t.invoke("bill", "1.2")
355
- assert_equal "1.2", value
356
- end
357
-
358
- def test_args_not_passed_if_no_prereq_names
359
- pre = task(:pre) { |t, args|
360
- assert_equal({}, args.to_hash)
361
- assert_equal "bill", args.name
362
- }
363
- t = task(:t, :name, :rev, :needs => [:pre])
364
- t.invoke("bill", "1.2")
365
- end
366
-
367
- def test_args_not_passed_if_no_arg_names
368
- pre = task(:pre, :rev) { |t, args|
369
- assert_equal({}, args.to_hash)
370
- }
371
- t = task(:t, :needs => [:pre])
372
- t.invoke("bill", "1.2")
373
- end
374
- end
@@ -0,0 +1,116 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestRakeTaskArgumentParsing < Rake::TestCase
4
+ def setup
5
+ super
6
+
7
+ @app = Rake::Application.new
8
+ end
9
+
10
+ def test_name_only
11
+ name, args = @app.parse_task_string("name")
12
+ assert_equal "name", name
13
+ assert_equal [], args
14
+ end
15
+
16
+ def test_empty_args
17
+ name, args = @app.parse_task_string("name[]")
18
+ assert_equal "name", name
19
+ assert_equal [], args
20
+ end
21
+
22
+ def test_one_argument
23
+ name, args = @app.parse_task_string("name[one]")
24
+ assert_equal "name", name
25
+ assert_equal ["one"], args
26
+ end
27
+
28
+ def test_two_arguments
29
+ name, args = @app.parse_task_string("name[one,two]")
30
+ assert_equal "name", name
31
+ assert_equal ["one", "two"], args
32
+ end
33
+
34
+ def test_can_handle_spaces_between_args
35
+ name, args = @app.parse_task_string("name[one, two,\tthree , \tfour]")
36
+ assert_equal "name", name
37
+ assert_equal ["one", "two", "three", "four"], args
38
+ end
39
+
40
+ def test_keeps_embedded_spaces
41
+ name, args = @app.parse_task_string("name[a one ana, two]")
42
+ assert_equal "name", name
43
+ assert_equal ["a one ana", "two"], args
44
+ end
45
+
46
+ def test_terminal_width_using_env
47
+ app = Rake::Application.new
48
+ in_environment('RAKE_COLUMNS' => '1234') do
49
+ assert_equal 1234, app.terminal_width
50
+ end
51
+ end
52
+
53
+ def test_terminal_width_using_stty
54
+ app = Rake::Application.new
55
+ flexmock(app,
56
+ :unix? => true,
57
+ :dynamic_width_stty => 1235,
58
+ :dynamic_width_tput => 0)
59
+ in_environment('RAKE_COLUMNS' => nil) do
60
+ assert_equal 1235, app.terminal_width
61
+ end
62
+ end
63
+
64
+ def test_terminal_width_using_tput
65
+ app = Rake::Application.new
66
+ flexmock(app,
67
+ :unix? => true,
68
+ :dynamic_width_stty => 0,
69
+ :dynamic_width_tput => 1236)
70
+ in_environment('RAKE_COLUMNS' => nil) do
71
+ assert_equal 1236, app.terminal_width
72
+ end
73
+ end
74
+
75
+ def test_terminal_width_using_hardcoded_80
76
+ app = Rake::Application.new
77
+ flexmock(app, :unix? => false)
78
+ in_environment('RAKE_COLUMNS' => nil) do
79
+ assert_equal 80, app.terminal_width
80
+ end
81
+ end
82
+
83
+ def test_terminal_width_with_failure
84
+ app = Rake::Application.new
85
+ flexmock(app).should_receive(:unix?).and_throw(RuntimeError)
86
+ in_environment('RAKE_COLUMNS' => nil) do
87
+ assert_equal 80, app.terminal_width
88
+ end
89
+ end
90
+
91
+ def test_no_rakeopt
92
+ in_environment do
93
+ ARGV << '--trace'
94
+ app = Rake::Application.new
95
+ app.init
96
+ assert !app.options.silent
97
+ end
98
+ end
99
+
100
+ def test_rakeopt_with_blank_options
101
+ in_environment("RAKEOPT" => "") do
102
+ ARGV << '--trace'
103
+ app = Rake::Application.new
104
+ app.init
105
+ assert !app.options.silent
106
+ end
107
+ end
108
+
109
+ def test_rakeopt_with_silent_options
110
+ in_environment("RAKEOPT" => "-s") do
111
+ app = Rake::Application.new
112
+ app.init
113
+ assert app.options.silent
114
+ end
115
+ end
116
+ end