rake 0.8.7 → 0.9.0

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 (124) hide show
  1. data/.gemtest +0 -0
  2. data/CHANGES +77 -9
  3. data/{README → README.rdoc} +14 -10
  4. data/Rakefile +129 -118
  5. data/TODO +1 -1
  6. data/doc/command_line_usage.rdoc +18 -6
  7. data/doc/glossary.rdoc +2 -2
  8. data/doc/jamis.rb +2 -2
  9. data/doc/proto_rake.rdoc +22 -22
  10. data/doc/rake.1.gz +0 -0
  11. data/doc/rakefile.rdoc +55 -32
  12. data/doc/rational.rdoc +6 -6
  13. data/doc/release_notes/rake-0.4.15.rdoc +1 -1
  14. data/doc/release_notes/rake-0.5.0.rdoc +1 -1
  15. data/doc/release_notes/rake-0.7.0.rdoc +1 -1
  16. data/doc/release_notes/rake-0.7.2.rdoc +3 -3
  17. data/doc/release_notes/rake-0.7.3.rdoc +2 -2
  18. data/doc/release_notes/rake-0.8.0.rdoc +1 -1
  19. data/doc/release_notes/rake-0.8.2.rdoc +3 -3
  20. data/doc/release_notes/rake-0.8.3.rdoc +2 -2
  21. data/doc/release_notes/rake-0.8.4.rdoc +1 -1
  22. data/doc/release_notes/rake-0.8.5.rdoc +1 -1
  23. data/doc/release_notes/rake-0.8.6.rdoc +1 -1
  24. data/doc/release_notes/rake-0.8.7.rdoc +1 -1
  25. data/doc/release_notes/rake-0.9.0.rdoc +112 -0
  26. data/install.rb +14 -12
  27. data/lib/rake/alt_system.rb +7 -6
  28. data/lib/rake/application.rb +589 -0
  29. data/lib/rake/classic_namespace.rb +1 -0
  30. data/lib/rake/clean.rb +2 -4
  31. data/lib/rake/cloneable.rb +25 -0
  32. data/lib/rake/contrib/compositepublisher.rb +2 -5
  33. data/lib/rake/contrib/ftptools.rb +5 -8
  34. data/lib/rake/contrib/publisher.rb +2 -8
  35. data/lib/rake/contrib/rubyforgepublisher.rb +2 -4
  36. data/lib/rake/contrib/sshpublisher.rb +4 -6
  37. data/lib/rake/contrib/sys.rb +7 -25
  38. data/lib/rake/default_loader.rb +10 -0
  39. data/lib/rake/dsl.rb +2 -0
  40. data/lib/rake/dsl_definition.rb +143 -0
  41. data/lib/rake/early_time.rb +18 -0
  42. data/lib/rake/ext/core.rb +27 -0
  43. data/lib/rake/ext/module.rb +39 -0
  44. data/lib/rake/ext/string.rb +167 -0
  45. data/lib/rake/ext/time.rb +14 -0
  46. data/lib/rake/file_creation_task.rb +24 -0
  47. data/lib/rake/file_list.rb +403 -0
  48. data/lib/rake/file_task.rb +47 -0
  49. data/lib/rake/file_utils.rb +112 -0
  50. data/lib/rake/file_utils_ext.rb +142 -0
  51. data/lib/rake/gempackagetask.rb +6 -90
  52. data/lib/rake/invocation_chain.rb +51 -0
  53. data/lib/rake/invocation_exception_mixin.rb +16 -0
  54. data/lib/rake/loaders/makefile.rb +13 -15
  55. data/lib/rake/multi_task.rb +16 -0
  56. data/lib/rake/name_space.rb +25 -0
  57. data/lib/rake/packagetask.rb +13 -12
  58. data/lib/rake/pathmap.rb +1 -0
  59. data/lib/rake/pseudo_status.rb +24 -0
  60. data/lib/rake/rake_module.rb +29 -0
  61. data/lib/rake/rake_test_loader.rb +10 -2
  62. data/lib/rake/rdoctask.rb +211 -190
  63. data/lib/rake/ruby182_test_unit_fix.rb +9 -7
  64. data/lib/rake/rule_recursion_overflow_error.rb +20 -0
  65. data/lib/rake/runtest.rb +4 -6
  66. data/lib/rake/task.rb +327 -0
  67. data/lib/rake/task_argument_error.rb +7 -0
  68. data/lib/rake/task_arguments.rb +74 -0
  69. data/lib/rake/task_manager.rb +307 -0
  70. data/lib/rake/tasklib.rb +1 -2
  71. data/lib/rake/testtask.rb +57 -27
  72. data/lib/rake/version.rb +10 -0
  73. data/lib/rake/win32.rb +4 -4
  74. data/lib/rake.rb +29 -2470
  75. data/test/contrib/test_sys.rb +8 -31
  76. data/test/data/access/Rakefile +33 -0
  77. data/test/data/comments/Rakefile +18 -0
  78. data/test/data/default/Rakefile +1 -1
  79. data/test/data/deprecated_import/Rakefile +1 -0
  80. data/test/data/dryrun/Rakefile +1 -1
  81. data/test/data/file_creation_task/Rakefile +1 -1
  82. data/test/data/namespace/Rakefile +9 -0
  83. data/test/data/rakelib/test1.rb +1 -0
  84. data/test/data/verbose/Rakefile +34 -0
  85. data/test/{filecreation.rb → file_creation.rb} +11 -7
  86. data/test/functional/functional_test.rb +25 -0
  87. data/test/{session_functional.rb → functional/session_based_tests.rb} +141 -23
  88. data/test/in_environment.rb +7 -5
  89. data/test/{test_application.rb → lib/application_test.rb} +331 -143
  90. data/test/{test_clean.rb → lib/clean_test.rb} +1 -0
  91. data/test/{test_definitions.rb → lib/definitions_test.rb} +3 -3
  92. data/test/lib/dsl_test.rb +52 -0
  93. data/test/{test_earlytime.rb → lib/earlytime_test.rb} +1 -2
  94. data/test/{test_extension.rb → lib/extension_test.rb} +2 -2
  95. data/test/{test_file_creation_task.rb → lib/file_creation_task_test.rb} +1 -1
  96. data/test/{test_file_task.rb → lib/file_task_test.rb} +4 -4
  97. data/test/{test_filelist.rb → lib/filelist_test.rb} +38 -24
  98. data/test/{test_fileutils.rb → lib/fileutils_test.rb} +27 -22
  99. data/test/{test_multitask.rb → lib/multitask_test.rb} +14 -6
  100. data/test/lib/package_task_test.rb +82 -0
  101. data/test/{test_pathmap.rb → lib/pathmap_test.rb} +3 -2
  102. data/test/{test_rake.rb → lib/rake_test.rb} +1 -1
  103. data/test/{test_rdoc_task.rb → lib/rdoc_task_test.rb} +19 -23
  104. data/test/{test_require.rb → lib/require_test.rb} +8 -2
  105. data/test/{test_rules.rb → lib/rules_test.rb} +2 -3
  106. data/test/{test_task_arguments.rb → lib/task_arguments_test.rb} +5 -5
  107. data/test/{test_task_manager.rb → lib/task_manager_test.rb} +15 -5
  108. data/test/{test_tasks.rb → lib/task_test.rb} +84 -21
  109. data/test/{test_test_task.rb → lib/test_task_test.rb} +3 -3
  110. data/test/lib/testtask_test.rb +49 -0
  111. data/test/{test_top_level_functions.rb → lib/top_level_functions_test.rb} +5 -3
  112. data/test/{test_win32.rb → lib/win32_test.rb} +19 -0
  113. data/test/rake_test_setup.rb +5 -9
  114. data/test/ruby_version_test.rb +3 -0
  115. data/test/test_helper.rb +19 -0
  116. metadata +108 -49
  117. data/test/functional.rb +0 -15
  118. data/test/test_package_task.rb +0 -118
  119. /data/test/{test_ftp.rb → lib/ftp_test.rb} +0 -0
  120. /data/test/{test_invocation_chain.rb → lib/invocation_chain_test.rb} +0 -0
  121. /data/test/{test_makefile_loader.rb → lib/makefile_loader_test.rb} +0 -0
  122. /data/test/{test_namespace.rb → lib/namespace_test.rb} +0 -0
  123. /data/test/{test_pseudo_status.rb → lib/pseudo_status_test.rb} +0 -0
  124. /data/test/{test_tasklib.rb → lib/tasklib_test.rb} +0 -0
@@ -21,18 +21,26 @@ class TestApplication < Test::Unit::TestCase
21
21
  include TestMethods
22
22
 
23
23
  def setup
24
+ super
24
25
  @app = Rake::Application.new
25
26
  @app.options.rakelib = []
27
+ Rake::TaskManager.record_task_metadata = true
28
+ end
29
+
30
+ def teardown
31
+ Rake::TaskManager.record_task_metadata = false
32
+ super
26
33
  end
27
34
 
28
35
  def test_constant_warning
29
- err = capture_stderr do @app.instance_eval { const_warning("Task") } end
30
- assert_match(/warning/i, err)
31
- assert_match(/deprecated/i, err)
32
- assert_match(/Task/i, err)
36
+ error_messages = capture_stderr do @app.instance_eval { const_warning("Task") } end
37
+ assert_match(/warning/i, error_messages)
38
+ assert_match(/deprecated/i, error_messages)
39
+ assert_match(/Task/i, error_messages)
33
40
  end
34
41
 
35
42
  def test_display_tasks
43
+ @app.options.show_tasks = :tasks
36
44
  @app.options.show_task_pattern = //
37
45
  @app.last_description = "COMMENT"
38
46
  @app.define_task(Rake::Task, "t")
@@ -43,6 +51,7 @@ class TestApplication < Test::Unit::TestCase
43
51
 
44
52
  def test_display_tasks_with_long_comments
45
53
  in_environment('RAKE_COLUMNS' => '80') do
54
+ @app.options.show_tasks = :tasks
46
55
  @app.options.show_task_pattern = //
47
56
  @app.last_description = "1234567890" * 8
48
57
  @app.define_task(Rake::Task, "t")
@@ -54,8 +63,8 @@ class TestApplication < Test::Unit::TestCase
54
63
 
55
64
  def test_display_tasks_with_task_name_wider_than_tty_display
56
65
  in_environment('RAKE_COLUMNS' => '80') do
66
+ @app.options.show_tasks = :tasks
57
67
  @app.options.show_task_pattern = //
58
- description = "something short"
59
68
  task_name = "task name" * 80
60
69
  @app.last_description = "something short"
61
70
  @app.define_task(Rake::Task, task_name )
@@ -66,6 +75,7 @@ class TestApplication < Test::Unit::TestCase
66
75
  end
67
76
 
68
77
  def test_display_tasks_with_very_long_task_name_to_a_non_tty_shows_name_and_comment
78
+ @app.options.show_tasks = :tasks
69
79
  @app.options.show_task_pattern = //
70
80
  @app.tty_output = false
71
81
  description = "something short"
@@ -78,6 +88,7 @@ class TestApplication < Test::Unit::TestCase
78
88
  end
79
89
 
80
90
  def test_display_tasks_with_long_comments_to_a_non_tty_shows_entire_comment
91
+ @app.options.show_tasks = :tasks
81
92
  @app.options.show_task_pattern = //
82
93
  @app.tty_output = false
83
94
  @app.last_description = "1234567890" * 8
@@ -89,6 +100,7 @@ class TestApplication < Test::Unit::TestCase
89
100
 
90
101
  def test_display_tasks_with_long_comments_to_a_non_tty_with_columns_set_truncates_comments
91
102
  in_environment("RAKE_COLUMNS" => '80') do
103
+ @app.options.show_tasks = :tasks
92
104
  @app.options.show_task_pattern = //
93
105
  @app.tty_output = false
94
106
  @app.last_description = "1234567890" * 8
@@ -99,9 +111,9 @@ class TestApplication < Test::Unit::TestCase
99
111
  end
100
112
  end
101
113
 
102
- def test_display_tasks_with_full_descriptions
114
+ def test_describe_tasks
115
+ @app.options.show_tasks = :describe
103
116
  @app.options.show_task_pattern = //
104
- @app.options.full_description = true
105
117
  @app.last_description = "COMMENT"
106
118
  @app.define_task(Rake::Task, "t")
107
119
  out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
@@ -109,6 +121,16 @@ class TestApplication < Test::Unit::TestCase
109
121
  assert_match(/^ {4}COMMENT$/, out)
110
122
  end
111
123
 
124
+ def test_show_lines
125
+ @app.options.show_tasks = :lines
126
+ @app.options.show_task_pattern = //
127
+ @app.last_description = "COMMENT"
128
+ @app.define_task(Rake::Task, "t")
129
+ @app['t'].locations << "HERE:1"
130
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
131
+ assert_match(/^rake t +[^:]+:\d+ *$/, out)
132
+ end
133
+
112
134
  def test_finding_rakefile
113
135
  assert_match(/Rakefile/i, @app.instance_eval { have_rakefile })
114
136
  end
@@ -121,7 +143,7 @@ class TestApplication < Test::Unit::TestCase
121
143
 
122
144
  def test_load_rakefile
123
145
  in_environment("PWD" => "test/data/unittest") do
124
- @app.instance_eval do
146
+ @app.instance_eval do
125
147
  handle_options
126
148
  options.silent = true
127
149
  load_rakefile
@@ -131,6 +153,19 @@ class TestApplication < Test::Unit::TestCase
131
153
  end
132
154
  end
133
155
 
156
+ def test_load_rakefile_doesnt_print_rakefile_directory_from_same_dir
157
+ in_environment("PWD" => "test/data/unittest") do
158
+ error_messages = capture_stderr do
159
+ @app.instance_eval do
160
+ @original_dir = File.expand_path(".") # pretend we started from the unittest dir
161
+ raw_load_rakefile
162
+ end
163
+ end
164
+ _, location = @app.find_rakefile_location
165
+ assert_no_match(/\(in #{location}\)/, error_messages)
166
+ end
167
+ end
168
+
134
169
  def test_load_rakefile_from_subdir
135
170
  in_environment("PWD" => "test/data/unittest/subdir") do
136
171
  @app.instance_eval do
@@ -143,14 +178,40 @@ class TestApplication < Test::Unit::TestCase
143
178
  end
144
179
  end
145
180
 
181
+ def test_load_rakefile_prints_rakefile_directory_from_subdir
182
+ in_environment("PWD" => "test/data/unittest/subdir") do
183
+ error_messages = capture_stderr do
184
+ @app.instance_eval do
185
+ raw_load_rakefile
186
+ end
187
+ end
188
+ _, location = @app.find_rakefile_location
189
+ assert_match(/\(in #{location}\)/, error_messages)
190
+ end
191
+ end
192
+
193
+ def test_load_rakefile_doesnt_print_rakefile_directory_from_subdir_if_silent
194
+ in_environment("PWD" => "test/data/unittest/subdir") do
195
+ error_messages = capture_stderr do
196
+ @app.instance_eval do
197
+ handle_options
198
+ options.silent = true
199
+ raw_load_rakefile
200
+ end
201
+ end
202
+ _, location = @app.find_rakefile_location
203
+ assert_no_match(/\(in #{location}\)/, error_messages)
204
+ end
205
+ end
206
+
146
207
  def test_load_rakefile_not_found
147
208
  in_environment("PWD" => "/", "RAKE_SYSTEM" => 'not_exist') do
148
209
  @app.instance_eval do
149
210
  handle_options
150
211
  options.silent = true
151
212
  end
152
- ex = assert_exception(RuntimeError) do
153
- @app.instance_eval do raw_load_rakefile end
213
+ ex = assert_exception(RuntimeError) do
214
+ @app.instance_eval do raw_load_rakefile end
154
215
  end
155
216
  assert_match(/no rakefile found/i, ex.message)
156
217
  end
@@ -171,6 +232,21 @@ class TestApplication < Test::Unit::TestCase
171
232
  end
172
233
  end
173
234
 
235
+ def test_load_from_calculated_system_rakefile
236
+ flexmock(@app, :standard_system_dir => "__STD_SYS_DIR__")
237
+ in_environment('RAKE_SYSTEM' => nil) do
238
+ @app.options.rakelib = []
239
+ @app.instance_eval do
240
+ handle_options
241
+ options.silent = true
242
+ options.load_system = true
243
+ options.rakelib = []
244
+ load_rakefile
245
+ end
246
+ assert_equal "__STD_SYS_DIR__", @app.system_dir
247
+ end
248
+ end
249
+
174
250
  def test_windows
175
251
  assert ! (@app.windows? && @app.unix?)
176
252
  end
@@ -259,8 +335,8 @@ class TestApplication < Test::Unit::TestCase
259
335
  ARGV.clear
260
336
  ARGV << '-f' << '-s' << '--rakelib=""'
261
337
  assert_exception(SystemExit) {
262
- err = capture_stderr { @app.run }
263
- assert_match(/see full trace/, err)
338
+ error_messages = capture_stderr { @app.run }
339
+ assert_match(/see full trace/, error_messages)
264
340
  }
265
341
  ensure
266
342
  ARGV.clear
@@ -271,8 +347,8 @@ class TestApplication < Test::Unit::TestCase
271
347
  ARGV.clear
272
348
  ARGV << '-f' << '-s' << '-t'
273
349
  assert_exception(SystemExit) {
274
- err = capture_stderr { capture_stdout { @app.run } }
275
- assert_no_match(/see full trace/, err)
350
+ error_messages = capture_stderr { capture_stdout { @app.run } }
351
+ assert_no_match(/see full trace/, error_messages)
276
352
  }
277
353
  ensure
278
354
  ARGV.clear
@@ -283,11 +359,22 @@ class TestApplication < Test::Unit::TestCase
283
359
  ARGV.clear
284
360
  ARGV << '-f' << '-s' << '--xyzzy'
285
361
  assert_exception(SystemExit) {
286
- err = capture_stderr { capture_stdout { @app.run } }
362
+ capture_stderr { capture_stdout { @app.run } }
287
363
  }
288
364
  ensure
289
365
  ARGV.clear
290
366
  end
367
+
368
+ def test_deprecation_message
369
+ in_environment do
370
+ error_messages = capture_stderr do
371
+ @app.deprecate("a", "b", "c")
372
+ end
373
+ assert_match(/'a' is deprecated/i, error_messages)
374
+ assert_match(/use 'b' instead/i, error_messages)
375
+ assert_match(/at c$/i, error_messages)
376
+ end
377
+ end
291
378
  end
292
379
 
293
380
 
@@ -295,20 +382,21 @@ end
295
382
  class TestApplicationOptions < Test::Unit::TestCase
296
383
  include CaptureStdout
297
384
  include TestMethods
385
+ include InEnvironment
298
386
 
299
387
  def setup
300
388
  clear_argv
301
- RakeFileUtils.verbose_flag = false
302
- RakeFileUtils.nowrite_flag = false
389
+ Rake::FileUtilsExt.verbose_flag = false
390
+ Rake::FileUtilsExt.nowrite_flag = false
303
391
  TESTING_REQUIRE.clear
304
392
  end
305
393
 
306
394
  def teardown
307
395
  clear_argv
308
- RakeFileUtils.verbose_flag = false
309
- RakeFileUtils.nowrite_flag = false
396
+ Rake::FileUtilsExt.verbose_flag = false
397
+ Rake::FileUtilsExt.nowrite_flag = false
310
398
  end
311
-
399
+
312
400
  def clear_argv
313
401
  while ! ARGV.empty?
314
402
  ARGV.pop
@@ -316,225 +404,299 @@ class TestApplicationOptions < Test::Unit::TestCase
316
404
  end
317
405
 
318
406
  def test_default_options
319
- opts = command_line
320
- assert_nil opts.classic_namespace
321
- assert_nil opts.dryrun
322
- assert_nil opts.full_description
323
- assert_nil opts.ignore_system
324
- assert_nil opts.load_system
325
- assert_nil opts.nosearch
326
- assert_equal ['rakelib'], opts.rakelib
327
- assert_nil opts.show_prereqs
328
- assert_nil opts.show_task_pattern
329
- assert_nil opts.show_tasks
330
- assert_nil opts.silent
331
- assert_nil opts.trace
332
- assert_equal ['rakelib'], opts.rakelib
333
- assert ! RakeFileUtils.verbose_flag
334
- assert ! RakeFileUtils.nowrite_flag
407
+ in_environment("RAKEOPT" => nil) do
408
+ opts = command_line
409
+ assert_nil opts.classic_namespace
410
+ assert_nil opts.dryrun
411
+ assert_nil opts.ignore_system
412
+ assert_nil opts.load_system
413
+ assert_nil opts.nosearch
414
+ assert_equal ['rakelib'], opts.rakelib
415
+ assert_nil opts.show_prereqs
416
+ assert_nil opts.show_task_pattern
417
+ assert_nil opts.show_tasks
418
+ assert_nil opts.silent
419
+ assert_nil opts.trace
420
+ assert_equal ['rakelib'], opts.rakelib
421
+ assert ! Rake::FileUtilsExt.verbose_flag
422
+ assert ! Rake::FileUtilsExt.nowrite_flag
423
+ end
335
424
  end
336
425
 
337
426
  def test_dry_run
338
- flags('--dry-run', '-n') do |opts|
339
- assert opts.dryrun
340
- assert opts.trace
341
- assert RakeFileUtils.verbose_flag
342
- assert RakeFileUtils.nowrite_flag
427
+ in_environment do
428
+ flags('--dry-run', '-n') do |opts|
429
+ assert opts.dryrun
430
+ assert opts.trace
431
+ assert Rake::FileUtilsExt.verbose_flag
432
+ assert Rake::FileUtilsExt.nowrite_flag
433
+ end
343
434
  end
344
435
  end
345
436
 
346
437
  def test_describe
347
- flags('--describe') do |opts|
348
- assert opts.full_description
349
- assert opts.show_tasks
350
- assert_equal(//.to_s, opts.show_task_pattern.to_s)
438
+ in_environment do
439
+ flags('--describe') do |opts|
440
+ assert_equal :describe, opts.show_tasks
441
+ assert_equal(//.to_s, opts.show_task_pattern.to_s)
442
+ end
351
443
  end
352
444
  end
353
445
 
354
446
  def test_describe_with_pattern
355
- flags('--describe=X') do |opts|
356
- assert opts.full_description
357
- assert opts.show_tasks
358
- assert_equal(/X/.to_s, opts.show_task_pattern.to_s)
447
+ in_environment do
448
+ flags('--describe=X') do |opts|
449
+ assert_equal :describe, opts.show_tasks
450
+ assert_equal(/X/.to_s, opts.show_task_pattern.to_s)
451
+ end
359
452
  end
360
453
  end
361
454
 
362
455
  def test_execute
363
- $xyzzy = 0
364
- flags('--execute=$xyzzy=1', '-e $xyzzy=1') do |opts|
365
- assert_equal 1, $xyzzy
366
- assert_equal :exit, @exit
456
+ in_environment do
367
457
  $xyzzy = 0
458
+ flags('--execute=$xyzzy=1', '-e $xyzzy=1') do |opts|
459
+ assert_equal 1, $xyzzy
460
+ assert_equal :exit, @exit
461
+ $xyzzy = 0
462
+ end
368
463
  end
369
464
  end
370
465
 
371
466
  def test_execute_and_continue
372
- $xyzzy = 0
373
- flags('--execute-continue=$xyzzy=1', '-E $xyzzy=1') do |opts|
374
- assert_equal 1, $xyzzy
375
- assert_not_equal :exit, @exit
467
+ in_environment do
376
468
  $xyzzy = 0
469
+ flags('--execute-continue=$xyzzy=1', '-E $xyzzy=1') do |opts|
470
+ assert_equal 1, $xyzzy
471
+ assert_not_equal :exit, @exit
472
+ $xyzzy = 0
473
+ end
377
474
  end
378
475
  end
379
476
 
380
477
  def test_execute_and_print
381
- $xyzzy = 0
382
- flags('--execute-print=$xyzzy="pugh"', '-p $xyzzy="pugh"') do |opts|
383
- assert_equal 'pugh', $xyzzy
384
- assert_equal :exit, @exit
385
- assert_match(/^pugh$/, @out)
478
+ in_environment do
386
479
  $xyzzy = 0
480
+ flags('--execute-print=$xyzzy="pugh"', '-p $xyzzy="pugh"') do |opts|
481
+ assert_equal 'pugh', $xyzzy
482
+ assert_equal :exit, @exit
483
+ assert_match(/^pugh$/, @out)
484
+ $xyzzy = 0
485
+ end
387
486
  end
388
487
  end
389
488
 
390
489
  def test_help
391
- flags('--help', '-H', '-h') do |opts|
392
- assert_match(/\Arake/, @out)
393
- assert_match(/\boptions\b/, @out)
394
- assert_match(/\btargets\b/, @out)
395
- assert_equal :exit, @exit
396
- assert_equal :exit, @exit
490
+ in_environment do
491
+ flags('--help', '-H', '-h') do |opts|
492
+ assert_match(/\Arake/, @out)
493
+ assert_match(/\boptions\b/, @out)
494
+ assert_match(/\btargets\b/, @out)
495
+ assert_equal :exit, @exit
496
+ assert_equal :exit, @exit
497
+ end
397
498
  end
398
499
  end
399
500
 
400
501
  def test_libdir
401
- flags(['--libdir', 'xx'], ['-I', 'xx'], ['-Ixx']) do |opts|
402
- $:.include?('xx')
502
+ in_environment do
503
+ flags(['--libdir', 'xx'], ['-I', 'xx'], ['-Ixx']) do |opts|
504
+ $:.include?('xx')
505
+ end
403
506
  end
404
507
  ensure
405
508
  $:.delete('xx')
406
509
  end
407
510
 
408
511
  def test_rakefile
409
- flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
410
- assert_equal ['RF'], @app.instance_eval { @rakefiles }
512
+ in_environment do
513
+ flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
514
+ assert_equal ['RF'], @app.instance_eval { @rakefiles }
515
+ end
411
516
  end
412
517
  end
413
518
 
414
519
  def test_rakelib
415
- flags(['--rakelibdir', 'A:B:C'], ['--rakelibdir=A:B:C'], ['-R', 'A:B:C'], ['-RA:B:C']) do |opts|
416
- assert_equal ['A', 'B', 'C'], opts.rakelib
520
+ in_environment do
521
+ flags(['--rakelibdir', 'A:B:C'], ['--rakelibdir=A:B:C'], ['-R', 'A:B:C'], ['-RA:B:C']) do |opts|
522
+ assert_equal ['A', 'B', 'C'], opts.rakelib
523
+ end
417
524
  end
418
525
  end
419
526
 
420
527
  def test_require
421
- flags(['--require', 'test/reqfile'], '-rtest/reqfile2', '-rtest/reqfile3') do |opts|
528
+ in_environment do
529
+ flags(['--require', 'test/reqfile'], '-rtest/reqfile2', '-rtest/reqfile3') do |opts|
530
+ end
531
+ assert TESTING_REQUIRE.include?(1)
532
+ assert TESTING_REQUIRE.include?(2)
533
+ assert TESTING_REQUIRE.include?(3)
534
+ assert_equal 3, TESTING_REQUIRE.size
422
535
  end
423
- assert TESTING_REQUIRE.include?(1)
424
- assert TESTING_REQUIRE.include?(2)
425
- assert TESTING_REQUIRE.include?(3)
426
- assert_equal 3, TESTING_REQUIRE.size
427
536
  end
428
537
 
429
538
  def test_missing_require
430
- ex = assert_exception(LoadError) do
431
- flags(['--require', 'test/missing']) do |opts|
539
+ in_environment do
540
+ ex = assert_exception(LoadError) do
541
+ flags(['--require', 'test/missing']) do |opts|
542
+ end
432
543
  end
544
+ assert_match(/such file/, ex.message)
545
+ assert_match(/test\/missing/, ex.message)
433
546
  end
434
- assert_match(/no such file/, ex.message)
435
- assert_match(/test\/missing/, ex.message)
436
547
  end
437
548
 
438
549
  def test_prereqs
439
- flags('--prereqs', '-P') do |opts|
440
- assert opts.show_prereqs
550
+ in_environment do
551
+ flags('--prereqs', '-P') do |opts|
552
+ assert opts.show_prereqs
553
+ end
441
554
  end
442
555
  end
443
556
 
444
557
  def test_quiet
445
- flags('--quiet', '-q') do |opts|
446
- assert ! RakeFileUtils.verbose_flag
447
- assert ! opts.silent
558
+ in_environment do
559
+ flags('--quiet', '-q') do |opts|
560
+ assert ! Rake::FileUtilsExt.verbose_flag
561
+ assert ! opts.silent
562
+ end
448
563
  end
449
564
  end
450
565
 
451
566
  def test_no_search
452
- flags('--nosearch', '--no-search', '-N') do |opts|
453
- assert opts.nosearch
567
+ in_environment do
568
+ flags('--nosearch', '--no-search', '-N') do |opts|
569
+ assert opts.nosearch
570
+ end
454
571
  end
455
572
  end
456
573
 
457
574
  def test_silent
458
- flags('--silent', '-s') do |opts|
459
- assert ! RakeFileUtils.verbose_flag
460
- assert opts.silent
575
+ in_environment do
576
+ flags('--silent', '-s') do |opts|
577
+ assert ! Rake::FileUtilsExt.verbose_flag
578
+ assert opts.silent
579
+ end
461
580
  end
462
581
  end
463
582
 
464
583
  def test_system
465
- flags('--system', '-g') do |opts|
466
- assert opts.load_system
584
+ in_environment do
585
+ flags('--system', '-g') do |opts|
586
+ assert opts.load_system
587
+ end
467
588
  end
468
589
  end
469
590
 
470
591
  def test_no_system
471
- flags('--no-system', '-G') do |opts|
472
- assert opts.ignore_system
592
+ in_environment do
593
+ flags('--no-system', '-G') do |opts|
594
+ assert opts.ignore_system
595
+ end
473
596
  end
474
597
  end
475
598
 
476
599
  def test_trace
477
- flags('--trace', '-t') do |opts|
478
- assert opts.trace
479
- assert RakeFileUtils.verbose_flag
480
- assert ! RakeFileUtils.nowrite_flag
600
+ in_environment do
601
+ flags('--trace', '-t') do |opts|
602
+ assert opts.trace
603
+ assert Rake::FileUtilsExt.verbose_flag
604
+ assert ! Rake::FileUtilsExt.nowrite_flag
605
+ end
481
606
  end
482
607
  end
483
608
 
484
609
  def test_trace_rules
485
- flags('--rules') do |opts|
486
- assert opts.trace_rules
610
+ in_environment do
611
+ flags('--rules') do |opts|
612
+ assert opts.trace_rules
613
+ end
487
614
  end
488
615
  end
489
616
 
490
617
  def test_tasks
491
- flags('--tasks', '-T') do |opts|
492
- assert opts.show_tasks
493
- assert_equal(//.to_s, opts.show_task_pattern.to_s)
618
+ in_environment do
619
+ flags('--tasks', '-T') do |opts|
620
+ assert_equal :tasks, opts.show_tasks
621
+ assert_equal(//.to_s, opts.show_task_pattern.to_s)
622
+ end
623
+ flags(['--tasks', 'xyz'], ['-Txyz']) do |opts|
624
+ assert_equal :tasks, opts.show_tasks
625
+ assert_equal(/xyz/.to_s, opts.show_task_pattern.to_s)
626
+ end
494
627
  end
495
- flags(['--tasks', 'xyz'], ['-Txyz']) do |opts|
496
- assert opts.show_tasks
497
- assert_equal(/xyz/, opts.show_task_pattern)
628
+ end
629
+
630
+ def test_where
631
+ in_environment do
632
+ flags('--where', '-W') do |opts|
633
+ assert_equal :lines, opts.show_tasks
634
+ assert_equal(//.to_s, opts.show_task_pattern.to_s)
635
+ end
636
+ flags(['--where', 'xyz'], ['-Wxyz']) do |opts|
637
+ assert_equal :lines, opts.show_tasks
638
+ assert_equal(/xyz/.to_s, opts.show_task_pattern.to_s)
639
+ end
640
+ end
641
+ end
642
+
643
+ def test_no_deprecated_messages
644
+ in_environment do
645
+ flags('--no-deprecation-warnings', '-X') do |opts|
646
+ assert opts.ignore_deprecate
647
+ end
498
648
  end
499
649
  end
500
650
 
501
651
  def test_verbose
502
- flags('--verbose', '-V') do |opts|
503
- assert RakeFileUtils.verbose_flag
504
- assert ! opts.silent
652
+ in_environment do
653
+ flags('--verbose', '-V') do |opts|
654
+ assert Rake::FileUtilsExt.verbose_flag
655
+ assert ! opts.silent
656
+ end
505
657
  end
506
658
  end
507
659
 
508
660
  def test_version
509
- flags('--version', '-V') do |opts|
510
- assert_match(/\bversion\b/, @out)
511
- assert_match(/\b#{RAKEVERSION}\b/, @out)
512
- assert_equal :exit, @exit
661
+ in_environment do
662
+ flags('--version', '-V') do |opts|
663
+ assert_match(/\bversion\b/, @out)
664
+ assert_match(/\b#{RAKEVERSION}\b/, @out)
665
+ assert_equal :exit, @exit
666
+ end
513
667
  end
514
668
  end
515
-
669
+
516
670
  def test_classic_namespace
517
- flags(['--classic-namespace'], ['-C', '-T', '-P', '-n', '-s', '-t']) do |opts|
518
- assert opts.classic_namespace
519
- assert_equal opts.show_tasks, $show_tasks
520
- assert_equal opts.show_prereqs, $show_prereqs
521
- assert_equal opts.trace, $trace
522
- assert_equal opts.dryrun, $dryrun
523
- assert_equal opts.silent, $silent
671
+ in_environment do
672
+ error_messages = capture_stderr do
673
+ flags(['--classic-namespace'], ['-C', '-T', '-P', '-n', '-s', '-t']) do |opts|
674
+ assert opts.classic_namespace
675
+ assert_equal opts.show_tasks, $show_tasks
676
+ assert_equal opts.show_prereqs, $show_prereqs
677
+ assert_equal opts.trace, $trace
678
+ assert_equal opts.dryrun, $dryrun
679
+ assert_equal opts.silent, $silent
680
+ end
681
+ end
682
+ assert_match(/deprecated/, error_messages)
524
683
  end
525
684
  end
526
685
 
527
686
  def test_bad_option
528
- capture_stderr do
529
- ex = assert_exception(OptionParser::InvalidOption) do
530
- flags('--bad-option')
531
- end
532
- if ex.message =~ /^While/ # Ruby 1.9 error message
533
- assert_match(/while parsing/i, ex.message)
534
- else # Ruby 1.8 error message
535
- assert_match(/(invalid|unrecognized) option/i, ex.message)
536
- assert_match(/--bad-option/, ex.message)
687
+ in_environment do
688
+ error_messages = capture_stderr do
689
+ ex = assert_exception(OptionParser::InvalidOption) do
690
+ flags('--bad-option')
691
+ end
692
+ if ex.message =~ /^While/ # Ruby 1.9 error message
693
+ assert_match(/while parsing/i, ex.message)
694
+ else # Ruby 1.8 error message
695
+ assert_match(/(invalid|unrecognized) option/i, ex.message)
696
+ assert_match(/--bad-option/, ex.message)
697
+ end
537
698
  end
699
+ assert_equal '', error_messages
538
700
  end
539
701
  end
540
702
 
@@ -542,12 +704,12 @@ class TestApplicationOptions < Test::Unit::TestCase
542
704
  command_line("a", "b")
543
705
  assert_equal ["a", "b"], @tasks.sort
544
706
  end
545
-
707
+
546
708
  def test_default_task_collection
547
709
  command_line()
548
710
  assert_equal ["default"], @tasks
549
711
  end
550
-
712
+
551
713
  def test_environment_definition
552
714
  ENV.delete('TESTKEY')
553
715
  command_line("a", "TESTKEY=12")
@@ -555,13 +717,13 @@ class TestApplicationOptions < Test::Unit::TestCase
555
717
  assert '12', ENV['TESTKEY']
556
718
  end
557
719
 
558
- private
720
+ private
559
721
 
560
722
  def flags(*sets)
561
723
  sets.each do |set|
562
724
  ARGV.clear
563
- @out = capture_stdout {
564
- @exit = catch(:system_exit) { opts = command_line(*set) }
725
+ @out = capture_stdout {
726
+ @exit = catch(:system_exit) { command_line(*set) }
565
727
  }
566
728
  yield(@app.options) if block_given?
567
729
  end
@@ -586,31 +748,31 @@ class TestTaskArgumentParsing < Test::Unit::TestCase
586
748
  def setup
587
749
  @app = Rake::Application.new
588
750
  end
589
-
751
+
590
752
  def test_name_only
591
753
  name, args = @app.parse_task_string("name")
592
754
  assert_equal "name", name
593
755
  assert_equal [], args
594
756
  end
595
-
757
+
596
758
  def test_empty_args
597
759
  name, args = @app.parse_task_string("name[]")
598
760
  assert_equal "name", name
599
761
  assert_equal [], args
600
762
  end
601
-
763
+
602
764
  def test_one_argument
603
765
  name, args = @app.parse_task_string("name[one]")
604
766
  assert_equal "name", name
605
767
  assert_equal ["one"], args
606
768
  end
607
-
769
+
608
770
  def test_two_arguments
609
771
  name, args = @app.parse_task_string("name[one,two]")
610
772
  assert_equal "name", name
611
773
  assert_equal ["one", "two"], args
612
774
  end
613
-
775
+
614
776
  def test_can_handle_spaces_between_args
615
777
  name, args = @app.parse_task_string("name[one, two,\tthree , \tfour]")
616
778
  assert_equal "name", name
@@ -672,4 +834,30 @@ class TestTaskArgumentParsing < Test::Unit::TestCase
672
834
  assert_equal 80, app.terminal_width
673
835
  end
674
836
  end
837
+
838
+ def test_no_rakeopt
839
+ in_environment do
840
+ ARGV << '--trace'
841
+ app = Rake::Application.new
842
+ app.init
843
+ assert !app.options.silent
844
+ end
845
+ end
846
+
847
+ def test_rakeopt_with_blank_options
848
+ in_environment("RAKEOPT" => "") do
849
+ ARGV << '--trace'
850
+ app = Rake::Application.new
851
+ app.init
852
+ assert !app.options.silent
853
+ end
854
+ end
855
+
856
+ def test_rakeopt_with_silent_options
857
+ in_environment("RAKEOPT" => "-s") do
858
+ app = Rake::Application.new
859
+ app.init
860
+ assert app.options.silent
861
+ end
862
+ end
675
863
  end