rake 0.9.2 → 0.9.2.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rake might be problematic. Click here for more details.

Files changed (75) hide show
  1. data/CHANGES +13 -0
  2. data/README.rdoc +12 -15
  3. data/Rakefile +8 -44
  4. data/bin/rake +1 -0
  5. data/lib/rake.rb +4 -0
  6. data/lib/rake/application.rb +9 -3
  7. data/lib/rake/classic_namespace.rb +2 -0
  8. data/lib/rake/clean.rb +1 -0
  9. data/lib/rake/contrib/publisher.rb +10 -6
  10. data/lib/rake/contrib/sshpublisher.rb +5 -0
  11. data/lib/rake/dsl_definition.rb +13 -4
  12. data/lib/rake/ext/time.rb +3 -3
  13. data/lib/rake/file_utils.rb +9 -7
  14. data/lib/rake/file_utils_ext.rb +4 -1
  15. data/lib/rake/gempackagetask.rb +2 -0
  16. data/lib/rake/rake_test_loader.rb +15 -6
  17. data/lib/rake/rdoctask.rb +5 -1
  18. data/lib/rake/task_arguments.rb +4 -0
  19. data/lib/rake/version.rb +5 -7
  20. data/test/file_creation.rb +2 -2
  21. data/test/helper.rb +460 -12
  22. data/test/test_rake.rb +3 -1
  23. data/test/test_rake_application.rb +250 -125
  24. data/test/test_rake_application_options.rb +146 -193
  25. data/test/test_rake_clean.rb +2 -0
  26. data/test/test_rake_definitions.rb +6 -6
  27. data/test/test_rake_directory_task.rb +26 -35
  28. data/test/test_rake_dsl.rb +4 -0
  29. data/test/test_rake_file_creation_task.rb +1 -7
  30. data/test/test_rake_file_list.rb +128 -133
  31. data/test/test_rake_file_task.rb +1 -3
  32. data/test/test_rake_file_utils.rb +123 -70
  33. data/test/test_rake_functional.rb +234 -252
  34. data/test/test_rake_makefile_loader.rb +22 -1
  35. data/test/test_rake_package_task.rb +10 -9
  36. data/test/test_rake_path_map_explode.rb +3 -0
  37. data/test/test_rake_pseudo_status.rb +3 -2
  38. data/test/test_rake_rake_test_loader.rb +21 -0
  39. data/test/test_rake_rdoc_task.rb +5 -3
  40. data/test/test_rake_require.rb +8 -3
  41. data/test/test_rake_rules.rb +56 -75
  42. data/test/test_rake_task.rb +5 -9
  43. data/test/test_rake_task_argument_parsing.rb +33 -46
  44. data/test/test_rake_task_arguments.rb +2 -0
  45. data/test/test_rake_task_manager.rb +12 -0
  46. data/test/test_rake_task_with_arguments.rb +11 -0
  47. data/test/test_rake_test_task.rb +55 -57
  48. data/test/test_rake_top_level_functions.rb +52 -17
  49. data/test/test_rake_win32.rb +31 -42
  50. metadata +6 -52
  51. data/RRR +0 -9
  52. data/test/check_expansion.rb +0 -5
  53. data/test/check_no_expansion.rb +0 -5
  54. data/test/data/access/Rakefile +0 -35
  55. data/test/data/chains/Rakefile +0 -15
  56. data/test/data/comments/Rakefile +0 -18
  57. data/test/data/default/Rakefile +0 -17
  58. data/test/data/deprecated_import/Rakefile +0 -1
  59. data/test/data/dryrun/Rakefile +0 -22
  60. data/test/data/extra/Rakefile +0 -1
  61. data/test/data/file_creation_task/Rakefile +0 -31
  62. data/test/data/imports/Rakefile +0 -19
  63. data/test/data/imports/deps.mf +0 -1
  64. data/test/data/multidesc/Rakefile +0 -15
  65. data/test/data/namespace/Rakefile +0 -64
  66. data/test/data/rakelib/test1.rb +0 -4
  67. data/test/data/rbext/rakefile.rb +0 -3
  68. data/test/data/sample.mf +0 -14
  69. data/test/data/statusreturn/Rakefile +0 -6
  70. data/test/data/unittest/Rakefile +0 -1
  71. data/test/data/verbose/Rakefile +0 -34
  72. data/test/in_environment.rb +0 -35
  73. data/test/reqfile.rb +0 -3
  74. data/test/reqfile2.rb +0 -3
  75. data/test/shellcommand.rb +0 -3
@@ -26,13 +26,15 @@ class TestRake < Rake::TestCase
26
26
  old_app = Rake.application
27
27
  fake_app = Object.new
28
28
  Rake.application = fake_app
29
+
29
30
  assert_equal fake_app, Rake.application
31
+
30
32
  ensure
31
33
  Rake.application = old_app
32
34
  end
33
35
 
34
36
  def test_original_dir_reports_current_dir
35
- assert_equal Dir.pwd, Rake.original_dir
37
+ assert_equal @tempdir, Rake.original_dir
36
38
  end
37
39
 
38
40
  end
@@ -1,20 +1,12 @@
1
1
  require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  class TestRakeApplication < Rake::TestCase
4
- include InEnvironment
5
4
 
6
5
  def setup
7
6
  super
8
7
 
9
- @app = Rake::Application.new
8
+ @app = Rake.application
10
9
  @app.options.rakelib = []
11
- Rake::TaskManager.record_task_metadata = true
12
- end
13
-
14
- def teardown
15
- Rake::TaskManager.record_task_metadata = false
16
-
17
- super
18
10
  end
19
11
 
20
12
  def test_constant_warning
@@ -35,28 +27,30 @@ class TestRakeApplication < Rake::TestCase
35
27
  end
36
28
 
37
29
  def test_display_tasks_with_long_comments
38
- in_environment('RAKE_COLUMNS' => '80') do
39
- @app.options.show_tasks = :tasks
40
- @app.options.show_task_pattern = //
41
- @app.last_description = "1234567890" * 8
42
- @app.define_task(Rake::Task, "t")
43
- out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
44
- assert_match(/^rake t/, out)
45
- assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
46
- end
30
+ @app.terminal_columns = 80
31
+ @app.options.show_tasks = :tasks
32
+ @app.options.show_task_pattern = //
33
+ @app.last_description = "1234567890" * 8
34
+ @app.define_task(Rake::Task, "t")
35
+
36
+ out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
37
+
38
+ assert_match(/^rake t/, out)
39
+ assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
47
40
  end
48
41
 
49
42
  def test_display_tasks_with_task_name_wider_than_tty_display
50
- in_environment('RAKE_COLUMNS' => '80') do
51
- @app.options.show_tasks = :tasks
52
- @app.options.show_task_pattern = //
53
- task_name = "task name" * 80
54
- @app.last_description = "something short"
55
- @app.define_task(Rake::Task, task_name )
56
- out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
57
- # Ensure the entire task name is output and we end up showing no description
58
- assert_match(/rake #{task_name} # .../, out)
59
- end
43
+ @app.terminal_columns = 80
44
+ @app.options.show_tasks = :tasks
45
+ @app.options.show_task_pattern = //
46
+ task_name = "task name" * 80
47
+ @app.last_description = "something short"
48
+ @app.define_task(Rake::Task, task_name )
49
+
50
+ out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
51
+
52
+ # Ensure the entire task name is output and we end up showing no description
53
+ assert_match(/rake #{task_name} # .../, out)
60
54
  end
61
55
 
62
56
  def test_display_tasks_with_very_long_task_name_to_a_non_tty_shows_name_and_comment
@@ -67,7 +61,9 @@ class TestRakeApplication < Rake::TestCase
67
61
  task_name = "task name" * 80
68
62
  @app.last_description = "something short"
69
63
  @app.define_task(Rake::Task, task_name )
64
+
70
65
  out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
66
+
71
67
  # Ensure the entire task name is output and we end up showing no description
72
68
  assert_match(/rake #{task_name} # #{description}/, out)
73
69
  end
@@ -84,16 +80,17 @@ class TestRakeApplication < Rake::TestCase
84
80
  end
85
81
 
86
82
  def test_display_tasks_with_long_comments_to_a_non_tty_with_columns_set_truncates_comments
87
- in_environment("RAKE_COLUMNS" => '80') do
88
- @app.options.show_tasks = :tasks
89
- @app.options.show_task_pattern = //
90
- @app.tty_output = false
91
- @app.last_description = "1234567890" * 8
92
- @app.define_task(Rake::Task, "t")
93
- out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
94
- assert_match(/^rake t/, out)
95
- assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
96
- end
83
+ @app.terminal_columns = 80
84
+ @app.options.show_tasks = :tasks
85
+ @app.options.show_task_pattern = //
86
+ @app.tty_output = false
87
+ @app.last_description = "1234567890" * 8
88
+ @app.define_task(Rake::Task, "t")
89
+
90
+ out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
91
+
92
+ assert_match(/^rake t/, out)
93
+ assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
97
94
  end
98
95
 
99
96
  def test_describe_tasks
@@ -117,6 +114,8 @@ class TestRakeApplication < Rake::TestCase
117
114
  end
118
115
 
119
116
  def test_finding_rakefile
117
+ rakefile_default
118
+
120
119
  assert_match(/Rakefile/i, @app.instance_eval { have_rakefile })
121
120
  end
122
121
 
@@ -127,108 +126,144 @@ class TestRakeApplication < Rake::TestCase
127
126
  end
128
127
 
129
128
  def test_load_rakefile
130
- in_environment("PWD" => "test/data/unittest") do
131
- @app.instance_eval do
132
- handle_options
133
- options.silent = true
134
- load_rakefile
135
- end
136
- assert_equal "rakefile", @app.rakefile.downcase
137
- assert_match(%r(unittest$), Dir.pwd)
129
+ rakefile_unittest
130
+
131
+ @app.instance_eval do
132
+ handle_options
133
+ options.silent = true
134
+ load_rakefile
138
135
  end
136
+
137
+ assert_equal "rakefile", @app.rakefile.downcase
138
+ assert_equal @tempdir, Dir.pwd
139
139
  end
140
140
 
141
141
  def test_load_rakefile_doesnt_print_rakefile_directory_from_same_dir
142
- in_environment("PWD" => "test/data/unittest") do
143
- _, err = capture_io do
144
- @app.instance_eval do
145
- @original_dir = File.expand_path(".") # pretend we started from the unittest dir
146
- raw_load_rakefile
147
- end
142
+ rakefile_unittest
143
+
144
+ _, err = capture_io do
145
+ @app.instance_eval do
146
+ # pretend we started from the unittest dir
147
+ @original_dir = File.expand_path(".")
148
+ raw_load_rakefile
148
149
  end
149
- _, location = @app.find_rakefile_location
150
- refute_match(/\(in #{location}\)/, err)
151
150
  end
151
+
152
+ assert_empty err
152
153
  end
153
154
 
154
155
  def test_load_rakefile_from_subdir
155
- in_environment("PWD" => "test/data/unittest/subdir") do
156
- @app.instance_eval do
157
- handle_options
158
- options.silent = true
159
- load_rakefile
160
- end
161
- assert_equal "rakefile", @app.rakefile.downcase
162
- assert_match(%r(unittest$), Dir.pwd)
156
+ rakefile_unittest
157
+ Dir.chdir 'subdir'
158
+
159
+ @app.instance_eval do
160
+ handle_options
161
+ options.silent = true
162
+ load_rakefile
163
163
  end
164
+
165
+ assert_equal "rakefile", @app.rakefile.downcase
166
+ assert_equal @tempdir, Dir.pwd
164
167
  end
165
168
 
166
169
  def test_load_rakefile_prints_rakefile_directory_from_subdir
167
- in_environment("PWD" => "test/data/unittest/subdir") do
168
- _, err = capture_io do
169
- @app.instance_eval do
170
- raw_load_rakefile
171
- end
170
+ rakefile_unittest
171
+ Dir.chdir 'subdir'
172
+
173
+ app = Rake::Application.new
174
+ app.options.rakelib = []
175
+
176
+ _, err = capture_io do
177
+ app.instance_eval do
178
+ raw_load_rakefile
172
179
  end
173
- _, location = @app.find_rakefile_location
174
- assert_match(/\(in #{location}\)/, err)
175
180
  end
181
+
182
+ assert_equal "(in #{@tempdir}\)\n", err
176
183
  end
177
184
 
178
185
  def test_load_rakefile_doesnt_print_rakefile_directory_from_subdir_if_silent
179
- in_environment("PWD" => "test/data/unittest/subdir") do
180
- _, err = capture_io do
181
- @app.instance_eval do
182
- handle_options
183
- options.silent = true
184
- raw_load_rakefile
185
- end
186
- end
187
- _, location = @app.find_rakefile_location
188
- refute_match(/\(in #{location}\)/, err)
189
- end
190
- end
186
+ rakefile_unittest
187
+ Dir.chdir 'subdir'
191
188
 
192
- def test_load_rakefile_not_found
193
- in_environment("PWD" => "/", "RAKE_SYSTEM" => 'not_exist') do
189
+ _, err = capture_io do
194
190
  @app.instance_eval do
195
191
  handle_options
196
192
  options.silent = true
193
+ raw_load_rakefile
197
194
  end
198
- ex = assert_raises(RuntimeError) do
199
- @app.instance_eval do raw_load_rakefile end
200
- end
201
- assert_match(/no rakefile found/i, ex.message)
202
195
  end
196
+
197
+ assert_empty err
198
+ end
199
+
200
+ def test_load_rakefile_not_found
201
+ Dir.chdir @tempdir
202
+ ENV['RAKE_SYSTEM'] = 'not_exist'
203
+
204
+ @app.instance_eval do
205
+ handle_options
206
+ options.silent = true
207
+ end
208
+
209
+ ex = assert_raises(RuntimeError) do
210
+ @app.instance_eval do raw_load_rakefile end
211
+ end
212
+
213
+ assert_match(/no rakefile found/i, ex.message)
203
214
  end
204
215
 
205
216
  def test_load_from_system_rakefile
206
- in_environment('RAKE_SYSTEM' => 'test/data/sys') do
207
- @app.options.rakelib = []
208
- @app.instance_eval do
209
- handle_options
210
- options.silent = true
211
- options.load_system = true
212
- options.rakelib = []
213
- load_rakefile
214
- end
215
- assert_equal "test/data/sys", @app.system_dir
216
- assert_nil @app.rakefile
217
+ rake_system_dir
218
+
219
+ @app.instance_eval do
220
+ handle_options
221
+ options.silent = true
222
+ options.load_system = true
223
+ options.rakelib = []
224
+ load_rakefile
217
225
  end
226
+
227
+ assert_equal @system_dir, @app.system_dir
228
+ assert_nil @app.rakefile
229
+ rescue SystemExit
230
+ flunk 'failed to load rakefile'
218
231
  end
219
232
 
220
233
  def test_load_from_calculated_system_rakefile
221
- flexmock(@app, :standard_system_dir => "__STD_SYS_DIR__")
222
- in_environment('RAKE_SYSTEM' => nil) do
223
- @app.options.rakelib = []
224
- @app.instance_eval do
225
- handle_options
226
- options.silent = true
227
- options.load_system = true
228
- options.rakelib = []
229
- load_rakefile
230
- end
231
- assert_equal "__STD_SYS_DIR__", @app.system_dir
234
+ rakefile_default
235
+ def @app.standard_system_dir
236
+ "__STD_SYS_DIR__"
237
+ end
238
+
239
+ ENV['RAKE_SYSTEM'] = nil
240
+
241
+ @app.instance_eval do
242
+ handle_options
243
+ options.silent = true
244
+ options.load_system = true
245
+ options.rakelib = []
246
+ load_rakefile
247
+ end
248
+
249
+ assert_equal "__STD_SYS_DIR__", @app.system_dir
250
+ rescue SystemExit
251
+ flunk 'failed to find system rakefile'
252
+ end
253
+
254
+ def test_terminal_columns
255
+ old_RAKE_COLUMNS = ENV['RAKE_COLUMNS']
256
+
257
+ ENV['RAKE_COLUMNS'] = '42'
258
+
259
+ app = Rake::Application.new
260
+
261
+ assert_equal 42, app.terminal_columns
262
+ ensure
263
+ if old_RAKE_COLUMNS then
264
+ ENV['RAKE_COLUMNS'].delete
265
+ else
266
+ ENV['RAKE_COLUMNS'] = old_RAKE_COLUMNS
232
267
  end
233
268
  end
234
269
 
@@ -237,25 +272,28 @@ class TestRakeApplication < Rake::TestCase
237
272
  end
238
273
 
239
274
  def test_loading_imports
240
- mock = flexmock("loader")
241
- mock.should_receive(:load).with("x.dummy").once
275
+ loader = util_loader
276
+
242
277
  @app.instance_eval do
243
- add_loader("dummy", mock)
278
+ add_loader("dummy", loader)
244
279
  add_import("x.dummy")
245
280
  load_imports
246
281
  end
282
+
283
+ # HACK no assertions
247
284
  end
248
285
 
249
286
  def test_building_imported_files_on_demand
250
- mock = flexmock("loader")
251
- mock.should_receive(:load).with("x.dummy").once
252
- mock.should_receive(:make_dummy).with_no_args.once
287
+ loader = util_loader
288
+
253
289
  @app.instance_eval do
254
- intern(Rake::Task, "x.dummy").enhance do mock.make_dummy end
255
- add_loader("dummy", mock)
290
+ intern(Rake::Task, "x.dummy").enhance do loader.make_dummy end
291
+ add_loader("dummy", loader)
256
292
  add_import("x.dummy")
257
293
  load_imports
258
294
  end
295
+
296
+ # HACK no assertions
259
297
  end
260
298
 
261
299
  def test_handle_options_should_strip_options_from_ARGV
@@ -273,16 +311,24 @@ class TestRakeApplication < Rake::TestCase
273
311
 
274
312
  def test_good_run
275
313
  ran = false
276
- ARGV.clear
314
+
277
315
  ARGV << '--rakelib=""'
316
+
278
317
  @app.options.silent = true
318
+
279
319
  @app.instance_eval do
280
320
  intern(Rake::Task, "default").enhance { ran = true }
281
321
  end
282
- in_environment("PWD" => "test/data/default") do
322
+
323
+ rakefile_default
324
+
325
+ out, err = capture_io do
283
326
  @app.run
284
327
  end
328
+
285
329
  assert ran
330
+ assert_empty err
331
+ assert_equal "DEFAULT\n", out
286
332
  end
287
333
 
288
334
  def test_display_task_run
@@ -351,14 +397,93 @@ class TestRakeApplication < Rake::TestCase
351
397
  end
352
398
 
353
399
  def test_deprecation_message
354
- in_environment do
355
- _, err = capture_io do
356
- @app.deprecate("a", "b", "c")
400
+ _, err = capture_io do
401
+ @app.deprecate("a", "b", "c")
402
+ end
403
+ assert_match(/'a' is deprecated/i, err)
404
+ assert_match(/use 'b' instead/i, err)
405
+ assert_match(/at c$/i, err)
406
+ end
407
+
408
+ def test_standard_exception_handling_invalid_option
409
+ out, err = capture_io do
410
+ e = assert_raises SystemExit do
411
+ @app.standard_exception_handling do
412
+ raise OptionParser::InvalidOption, 'blah'
413
+ end
414
+ end
415
+
416
+ assert_equal 1, e.status
417
+ end
418
+
419
+ assert_empty out
420
+ assert_equal "invalid option: blah\n", err
421
+ end
422
+
423
+ def test_standard_exception_handling_other
424
+ out, err = capture_io do
425
+ e = assert_raises SystemExit do
426
+ @app.standard_exception_handling do
427
+ raise 'blah'
428
+ end
429
+ end
430
+
431
+ assert_equal 1, e.status
432
+ end
433
+
434
+ assert_empty out
435
+ assert_match "rake aborted!\n", err
436
+ assert_match "blah\n", err
437
+ end
438
+
439
+ def test_standard_exception_handling_system_exit
440
+ out, err = capture_io do
441
+ e = assert_raises SystemExit do
442
+ @app.standard_exception_handling do
443
+ exit 0
444
+ end
357
445
  end
358
- assert_match(/'a' is deprecated/i, err)
359
- assert_match(/use 'b' instead/i, err)
360
- assert_match(/at c$/i, err)
446
+
447
+ assert_equal 0, e.status
448
+ end
449
+
450
+ assert_empty out
451
+ assert_empty err
452
+ end
453
+
454
+ def test_standard_exception_handling_system_exit_nonzero
455
+ out, err = capture_io do
456
+ e = assert_raises SystemExit do
457
+ @app.standard_exception_handling do
458
+ exit 5
459
+ end
460
+ end
461
+
462
+ assert_equal 5, e.status
361
463
  end
464
+
465
+ assert_empty out
466
+ assert_empty err
362
467
  end
468
+
469
+ def util_loader
470
+ loader = Object.new
471
+
472
+ loader.instance_variable_set :@load_called, false
473
+ def loader.load arg
474
+ raise 'called more than once' if @load_called
475
+ raise ArgumentError, arg unless arg == 'x.dummy'
476
+ @load_called = true
477
+ end
478
+
479
+ loader.instance_variable_set :@make_dummy_called, false
480
+ def loader.make_dummy
481
+ raise 'called more than once' if @make_dummy_called
482
+ @make_dummy_called = true
483
+ end
484
+
485
+ loader
486
+ end
487
+
363
488
  end
364
489