rake 0.8.7 → 0.9.0.beta.0

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 (122) hide show
  1. data/.gemtest +0 -0
  2. data/CHANGES +77 -9
  3. data/{README → README.rdoc} +14 -10
  4. data/Rakefile +113 -110
  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 +60 -28
  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/install.rb +14 -12
  26. data/lib/rake.rb +28 -2470
  27. data/lib/rake/alt_system.rb +7 -6
  28. data/lib/rake/application.rb +585 -0
  29. data/lib/rake/classic_namespace.rb +1 -0
  30. data/lib/rake/clean.rb +14 -14
  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 +146 -0
  41. data/lib/rake/early_time.rb +18 -0
  42. data/lib/rake/environment.rb +40 -0
  43. data/lib/rake/ext/core.rb +27 -0
  44. data/lib/rake/ext/module.rb +39 -0
  45. data/lib/rake/ext/string.rb +167 -0
  46. data/lib/rake/ext/time.rb +14 -0
  47. data/lib/rake/file_creation_task.rb +24 -0
  48. data/lib/rake/file_list.rb +403 -0
  49. data/lib/rake/file_task.rb +47 -0
  50. data/lib/rake/file_utils.rb +112 -0
  51. data/lib/rake/file_utils_ext.rb +132 -0
  52. data/lib/rake/gempackagetask.rb +6 -90
  53. data/lib/rake/invocation_chain.rb +51 -0
  54. data/lib/rake/invocation_exception_mixin.rb +16 -0
  55. data/lib/rake/loaders/makefile.rb +13 -15
  56. data/lib/rake/multi_task.rb +16 -0
  57. data/lib/rake/name_space.rb +25 -0
  58. data/lib/rake/packagetask.rb +13 -12
  59. data/lib/rake/pathmap.rb +1 -0
  60. data/lib/rake/pseudo_status.rb +24 -0
  61. data/lib/rake/rake_module.rb +25 -0
  62. data/lib/rake/rake_test_loader.rb +10 -2
  63. data/lib/rake/rdoctask.rb +211 -190
  64. data/lib/rake/ruby182_test_unit_fix.rb +9 -7
  65. data/lib/rake/rule_recursion_overflow_error.rb +20 -0
  66. data/lib/rake/runtest.rb +4 -6
  67. data/lib/rake/task.rb +327 -0
  68. data/lib/rake/task_argument_error.rb +7 -0
  69. data/lib/rake/task_arguments.rb +74 -0
  70. data/lib/rake/task_manager.rb +329 -0
  71. data/lib/rake/tasklib.rb +1 -2
  72. data/lib/rake/testtask.rb +51 -26
  73. data/lib/rake/version.rb +12 -0
  74. data/lib/rake/win32.rb +4 -4
  75. data/test/contrib/test_sys.rb +7 -30
  76. data/test/data/comments/Rakefile +18 -0
  77. data/test/data/default/Rakefile +1 -1
  78. data/test/data/dryrun/Rakefile +1 -1
  79. data/test/data/file_creation_task/Rakefile +1 -1
  80. data/test/data/namespace/Rakefile +9 -0
  81. data/test/data/rakelib/test1.rb +4 -2
  82. data/test/data/verbose/Rakefile +34 -0
  83. data/test/functional/functional_test.rb +25 -0
  84. data/test/{session_functional.rb → functional/session_based_tests.rb} +134 -23
  85. data/test/in_environment.rb +6 -4
  86. data/test/{test_application.rb → lib/application_test.rb} +277 -136
  87. data/test/{test_clean.rb → lib/clean_test.rb} +1 -0
  88. data/test/{test_definitions.rb → lib/definitions_test.rb} +2 -2
  89. data/test/lib/dsl_test.rb +52 -0
  90. data/test/{test_earlytime.rb → lib/earlytime_test.rb} +1 -2
  91. data/test/lib/environment_test.rb +18 -0
  92. data/test/{test_extension.rb → lib/extension_test.rb} +2 -2
  93. data/test/{test_file_creation_task.rb → lib/file_creation_task_test.rb} +0 -0
  94. data/test/{test_file_task.rb → lib/file_task_test.rb} +3 -3
  95. data/test/{test_filelist.rb → lib/filelist_test.rb} +28 -24
  96. data/test/{test_fileutils.rb → lib/fileutils_test.rb} +26 -21
  97. data/test/{test_ftp.rb → lib/ftp_test.rb} +0 -0
  98. data/test/{test_invocation_chain.rb → lib/invocation_chain_test.rb} +0 -0
  99. data/test/{test_makefile_loader.rb → lib/makefile_loader_test.rb} +0 -0
  100. data/test/{test_multitask.rb → lib/multitask_test.rb} +14 -6
  101. data/test/{test_namespace.rb → lib/namespace_test.rb} +0 -0
  102. data/test/lib/package_task_test.rb +82 -0
  103. data/test/{test_pathmap.rb → lib/pathmap_test.rb} +3 -2
  104. data/test/{test_pseudo_status.rb → lib/pseudo_status_test.rb} +0 -0
  105. data/test/{test_rake.rb → lib/rake_test.rb} +1 -1
  106. data/test/{test_rdoc_task.rb → lib/rdoc_task_test.rb} +19 -23
  107. data/test/{test_require.rb → lib/require_test.rb} +8 -2
  108. data/test/{test_rules.rb → lib/rules_test.rb} +1 -2
  109. data/test/{test_task_arguments.rb → lib/task_arguments_test.rb} +5 -5
  110. data/test/{test_task_manager.rb → lib/task_manager_test.rb} +5 -5
  111. data/test/{test_tasks.rb → lib/task_test.rb} +69 -4
  112. data/test/{test_tasklib.rb → lib/tasklib_test.rb} +0 -0
  113. data/test/{test_test_task.rb → lib/test_task_test.rb} +3 -3
  114. data/test/lib/testtask_test.rb +49 -0
  115. data/test/{test_top_level_functions.rb → lib/top_level_functions_test.rb} +3 -3
  116. data/test/{test_win32.rb → lib/win32_test.rb} +19 -0
  117. data/test/rake_test_setup.rb +4 -9
  118. data/test/ruby_version_test.rb +3 -0
  119. data/test/test_helper.rb +12 -0
  120. metadata +100 -44
  121. data/test/functional.rb +0 -15
  122. data/test/test_package_task.rb +0 -118
@@ -1,11 +1,13 @@
1
1
  module InEnvironment
2
2
  private
3
-
3
+
4
4
  # Create an environment for a test. At the completion of the yielded
5
5
  # block, the environment is restored to its original conditions.
6
- def in_environment(settings)
7
- original_settings = set_env(settings)
8
- yield
6
+ def in_environment(settings=nil)
7
+ settings ||= {}
8
+ full_settings = {"RAKEOPT" => nil}.merge(settings)
9
+ original_settings = set_env(full_settings)
10
+ yield
9
11
  ensure
10
12
  set_env(original_settings)
11
13
  end
@@ -21,8 +21,15 @@ 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
@@ -33,6 +40,7 @@ class TestApplication < Test::Unit::TestCase
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
+ err = 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}\)/, err)
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
+ err = 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}\)/, err)
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
+ err = 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}\)/, err)
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
@@ -283,7 +344,7 @@ class TestApplication < Test::Unit::TestCase
283
344
  ARGV.clear
284
345
  ARGV << '-f' << '-s' << '--xyzzy'
285
346
  assert_exception(SystemExit) {
286
- err = capture_stderr { capture_stdout { @app.run } }
347
+ capture_stderr { capture_stdout { @app.run } }
287
348
  }
288
349
  ensure
289
350
  ARGV.clear
@@ -295,20 +356,21 @@ end
295
356
  class TestApplicationOptions < Test::Unit::TestCase
296
357
  include CaptureStdout
297
358
  include TestMethods
359
+ include InEnvironment
298
360
 
299
361
  def setup
300
362
  clear_argv
301
- RakeFileUtils.verbose_flag = false
302
- RakeFileUtils.nowrite_flag = false
363
+ Rake::FileUtilsExt.verbose_flag = false
364
+ Rake::FileUtilsExt.nowrite_flag = false
303
365
  TESTING_REQUIRE.clear
304
366
  end
305
367
 
306
368
  def teardown
307
369
  clear_argv
308
- RakeFileUtils.verbose_flag = false
309
- RakeFileUtils.nowrite_flag = false
370
+ Rake::FileUtilsExt.verbose_flag = false
371
+ Rake::FileUtilsExt.nowrite_flag = false
310
372
  end
311
-
373
+
312
374
  def clear_argv
313
375
  while ! ARGV.empty?
314
376
  ARGV.pop
@@ -316,225 +378,278 @@ class TestApplicationOptions < Test::Unit::TestCase
316
378
  end
317
379
 
318
380
  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
381
+ in_environment("RAKEOPT" => nil) do
382
+ opts = command_line
383
+ assert_nil opts.classic_namespace
384
+ assert_nil opts.dryrun
385
+ assert_nil opts.ignore_system
386
+ assert_nil opts.load_system
387
+ assert_nil opts.nosearch
388
+ assert_equal ['rakelib'], opts.rakelib
389
+ assert_nil opts.show_prereqs
390
+ assert_nil opts.show_task_pattern
391
+ assert_nil opts.show_tasks
392
+ assert_nil opts.silent
393
+ assert_nil opts.trace
394
+ assert_equal ['rakelib'], opts.rakelib
395
+ assert ! Rake::FileUtilsExt.verbose_flag
396
+ assert ! Rake::FileUtilsExt.nowrite_flag
397
+ end
335
398
  end
336
399
 
337
400
  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
401
+ in_environment do
402
+ flags('--dry-run', '-n') do |opts|
403
+ assert opts.dryrun
404
+ assert opts.trace
405
+ assert Rake::FileUtilsExt.verbose_flag
406
+ assert Rake::FileUtilsExt.nowrite_flag
407
+ end
343
408
  end
344
409
  end
345
410
 
346
411
  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)
412
+ in_environment do
413
+ flags('--describe') do |opts|
414
+ assert_equal :describe, opts.show_tasks
415
+ assert_equal(//.to_s, opts.show_task_pattern.to_s)
416
+ end
351
417
  end
352
418
  end
353
419
 
354
420
  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)
421
+ in_environment do
422
+ flags('--describe=X') do |opts|
423
+ assert_equal :describe, opts.show_tasks
424
+ assert_equal(/X/.to_s, opts.show_task_pattern.to_s)
425
+ end
359
426
  end
360
427
  end
361
428
 
362
429
  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
430
+ in_environment do
367
431
  $xyzzy = 0
432
+ flags('--execute=$xyzzy=1', '-e $xyzzy=1') do |opts|
433
+ assert_equal 1, $xyzzy
434
+ assert_equal :exit, @exit
435
+ $xyzzy = 0
436
+ end
368
437
  end
369
438
  end
370
439
 
371
440
  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
441
+ in_environment do
376
442
  $xyzzy = 0
443
+ flags('--execute-continue=$xyzzy=1', '-E $xyzzy=1') do |opts|
444
+ assert_equal 1, $xyzzy
445
+ assert_not_equal :exit, @exit
446
+ $xyzzy = 0
447
+ end
377
448
  end
378
449
  end
379
450
 
380
451
  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)
452
+ in_environment do
386
453
  $xyzzy = 0
454
+ flags('--execute-print=$xyzzy="pugh"', '-p $xyzzy="pugh"') do |opts|
455
+ assert_equal 'pugh', $xyzzy
456
+ assert_equal :exit, @exit
457
+ assert_match(/^pugh$/, @out)
458
+ $xyzzy = 0
459
+ end
387
460
  end
388
461
  end
389
462
 
390
463
  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
464
+ in_environment do
465
+ flags('--help', '-H', '-h') do |opts|
466
+ assert_match(/\Arake/, @out)
467
+ assert_match(/\boptions\b/, @out)
468
+ assert_match(/\btargets\b/, @out)
469
+ assert_equal :exit, @exit
470
+ assert_equal :exit, @exit
471
+ end
397
472
  end
398
473
  end
399
474
 
400
475
  def test_libdir
401
- flags(['--libdir', 'xx'], ['-I', 'xx'], ['-Ixx']) do |opts|
402
- $:.include?('xx')
476
+ in_environment do
477
+ flags(['--libdir', 'xx'], ['-I', 'xx'], ['-Ixx']) do |opts|
478
+ $:.include?('xx')
479
+ end
403
480
  end
404
481
  ensure
405
482
  $:.delete('xx')
406
483
  end
407
484
 
408
485
  def test_rakefile
409
- flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
410
- assert_equal ['RF'], @app.instance_eval { @rakefiles }
486
+ in_environment do
487
+ flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
488
+ assert_equal ['RF'], @app.instance_eval { @rakefiles }
489
+ end
411
490
  end
412
491
  end
413
492
 
414
493
  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
494
+ in_environment do
495
+ flags(['--rakelibdir', 'A:B:C'], ['--rakelibdir=A:B:C'], ['-R', 'A:B:C'], ['-RA:B:C']) do |opts|
496
+ assert_equal ['A', 'B', 'C'], opts.rakelib
497
+ end
417
498
  end
418
499
  end
419
500
 
420
501
  def test_require
421
- flags(['--require', 'test/reqfile'], '-rtest/reqfile2', '-rtest/reqfile3') do |opts|
502
+ in_environment do
503
+ flags(['--require', 'test/reqfile'], '-rtest/reqfile2', '-rtest/reqfile3') do |opts|
504
+ end
505
+ assert TESTING_REQUIRE.include?(1)
506
+ assert TESTING_REQUIRE.include?(2)
507
+ assert TESTING_REQUIRE.include?(3)
508
+ assert_equal 3, TESTING_REQUIRE.size
422
509
  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
510
  end
428
511
 
429
512
  def test_missing_require
430
- ex = assert_exception(LoadError) do
431
- flags(['--require', 'test/missing']) do |opts|
513
+ in_environment do
514
+ ex = assert_exception(LoadError) do
515
+ flags(['--require', 'test/missing']) do |opts|
516
+ end
432
517
  end
518
+ assert_match(/such file/, ex.message)
519
+ assert_match(/test\/missing/, ex.message)
433
520
  end
434
- assert_match(/no such file/, ex.message)
435
- assert_match(/test\/missing/, ex.message)
436
521
  end
437
522
 
438
523
  def test_prereqs
439
- flags('--prereqs', '-P') do |opts|
440
- assert opts.show_prereqs
524
+ in_environment do
525
+ flags('--prereqs', '-P') do |opts|
526
+ assert opts.show_prereqs
527
+ end
441
528
  end
442
529
  end
443
530
 
444
531
  def test_quiet
445
- flags('--quiet', '-q') do |opts|
446
- assert ! RakeFileUtils.verbose_flag
447
- assert ! opts.silent
532
+ in_environment do
533
+ flags('--quiet', '-q') do |opts|
534
+ assert ! Rake::FileUtilsExt.verbose_flag
535
+ assert ! opts.silent
536
+ end
448
537
  end
449
538
  end
450
539
 
451
540
  def test_no_search
452
- flags('--nosearch', '--no-search', '-N') do |opts|
453
- assert opts.nosearch
541
+ in_environment do
542
+ flags('--nosearch', '--no-search', '-N') do |opts|
543
+ assert opts.nosearch
544
+ end
454
545
  end
455
546
  end
456
547
 
457
548
  def test_silent
458
- flags('--silent', '-s') do |opts|
459
- assert ! RakeFileUtils.verbose_flag
460
- assert opts.silent
549
+ in_environment do
550
+ flags('--silent', '-s') do |opts|
551
+ assert ! Rake::FileUtilsExt.verbose_flag
552
+ assert opts.silent
553
+ end
461
554
  end
462
555
  end
463
556
 
464
557
  def test_system
465
- flags('--system', '-g') do |opts|
466
- assert opts.load_system
558
+ in_environment do
559
+ flags('--system', '-g') do |opts|
560
+ assert opts.load_system
561
+ end
467
562
  end
468
563
  end
469
564
 
470
565
  def test_no_system
471
- flags('--no-system', '-G') do |opts|
472
- assert opts.ignore_system
566
+ in_environment do
567
+ flags('--no-system', '-G') do |opts|
568
+ assert opts.ignore_system
569
+ end
473
570
  end
474
571
  end
475
572
 
476
573
  def test_trace
477
- flags('--trace', '-t') do |opts|
478
- assert opts.trace
479
- assert RakeFileUtils.verbose_flag
480
- assert ! RakeFileUtils.nowrite_flag
574
+ in_environment do
575
+ flags('--trace', '-t') do |opts|
576
+ assert opts.trace
577
+ assert Rake::FileUtilsExt.verbose_flag
578
+ assert ! Rake::FileUtilsExt.nowrite_flag
579
+ end
481
580
  end
482
581
  end
483
582
 
484
583
  def test_trace_rules
485
- flags('--rules') do |opts|
486
- assert opts.trace_rules
584
+ in_environment do
585
+ flags('--rules') do |opts|
586
+ assert opts.trace_rules
587
+ end
487
588
  end
488
589
  end
489
590
 
490
591
  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)
494
- end
495
- flags(['--tasks', 'xyz'], ['-Txyz']) do |opts|
496
- assert opts.show_tasks
497
- assert_equal(/xyz/, opts.show_task_pattern)
592
+ in_environment do
593
+ flags('--tasks', '-T') do |opts|
594
+ assert_equal :tasks, opts.show_tasks
595
+ assert_equal(//.to_s, opts.show_task_pattern.to_s)
596
+ end
597
+ flags(['--tasks', 'xyz'], ['-Txyz']) do |opts|
598
+ assert_equal :tasks, opts.show_tasks
599
+ assert_equal(/xyz/, opts.show_task_pattern)
600
+ end
498
601
  end
499
602
  end
500
603
 
501
604
  def test_verbose
502
- flags('--verbose', '-V') do |opts|
503
- assert RakeFileUtils.verbose_flag
504
- assert ! opts.silent
605
+ in_environment do
606
+ flags('--verbose', '-V') do |opts|
607
+ assert Rake::FileUtilsExt.verbose_flag
608
+ assert ! opts.silent
609
+ end
505
610
  end
506
611
  end
507
612
 
508
613
  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
614
+ in_environment do
615
+ flags('--version', '-V') do |opts|
616
+ assert_match(/\bversion\b/, @out)
617
+ assert_match(/\b#{RAKEVERSION}\b/, @out)
618
+ assert_equal :exit, @exit
619
+ end
513
620
  end
514
621
  end
515
-
622
+
516
623
  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
624
+ in_environment do
625
+ error_output = capture_stderr do
626
+ flags(['--classic-namespace'], ['-C', '-T', '-P', '-n', '-s', '-t']) do |opts|
627
+ assert opts.classic_namespace
628
+ assert_equal opts.show_tasks, $show_tasks
629
+ assert_equal opts.show_prereqs, $show_prereqs
630
+ assert_equal opts.trace, $trace
631
+ assert_equal opts.dryrun, $dryrun
632
+ assert_equal opts.silent, $silent
633
+ end
634
+ end
635
+ assert_match(/deprecated/, error_output)
524
636
  end
525
637
  end
526
638
 
527
639
  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)
640
+ in_environment do
641
+ error_output = capture_stderr do
642
+ ex = assert_exception(OptionParser::InvalidOption) do
643
+ flags('--bad-option')
644
+ end
645
+ if ex.message =~ /^While/ # Ruby 1.9 error message
646
+ assert_match(/while parsing/i, ex.message)
647
+ else # Ruby 1.8 error message
648
+ assert_match(/(invalid|unrecognized) option/i, ex.message)
649
+ assert_match(/--bad-option/, ex.message)
650
+ end
537
651
  end
652
+ assert_equal '', error_output
538
653
  end
539
654
  end
540
655
 
@@ -542,12 +657,12 @@ class TestApplicationOptions < Test::Unit::TestCase
542
657
  command_line("a", "b")
543
658
  assert_equal ["a", "b"], @tasks.sort
544
659
  end
545
-
660
+
546
661
  def test_default_task_collection
547
662
  command_line()
548
663
  assert_equal ["default"], @tasks
549
664
  end
550
-
665
+
551
666
  def test_environment_definition
552
667
  ENV.delete('TESTKEY')
553
668
  command_line("a", "TESTKEY=12")
@@ -555,13 +670,13 @@ class TestApplicationOptions < Test::Unit::TestCase
555
670
  assert '12', ENV['TESTKEY']
556
671
  end
557
672
 
558
- private
673
+ private
559
674
 
560
675
  def flags(*sets)
561
676
  sets.each do |set|
562
677
  ARGV.clear
563
- @out = capture_stdout {
564
- @exit = catch(:system_exit) { opts = command_line(*set) }
678
+ @out = capture_stdout {
679
+ @exit = catch(:system_exit) { command_line(*set) }
565
680
  }
566
681
  yield(@app.options) if block_given?
567
682
  end
@@ -586,31 +701,31 @@ class TestTaskArgumentParsing < Test::Unit::TestCase
586
701
  def setup
587
702
  @app = Rake::Application.new
588
703
  end
589
-
704
+
590
705
  def test_name_only
591
706
  name, args = @app.parse_task_string("name")
592
707
  assert_equal "name", name
593
708
  assert_equal [], args
594
709
  end
595
-
710
+
596
711
  def test_empty_args
597
712
  name, args = @app.parse_task_string("name[]")
598
713
  assert_equal "name", name
599
714
  assert_equal [], args
600
715
  end
601
-
716
+
602
717
  def test_one_argument
603
718
  name, args = @app.parse_task_string("name[one]")
604
719
  assert_equal "name", name
605
720
  assert_equal ["one"], args
606
721
  end
607
-
722
+
608
723
  def test_two_arguments
609
724
  name, args = @app.parse_task_string("name[one,two]")
610
725
  assert_equal "name", name
611
726
  assert_equal ["one", "two"], args
612
727
  end
613
-
728
+
614
729
  def test_can_handle_spaces_between_args
615
730
  name, args = @app.parse_task_string("name[one, two,\tthree , \tfour]")
616
731
  assert_equal "name", name
@@ -672,4 +787,30 @@ class TestTaskArgumentParsing < Test::Unit::TestCase
672
787
  assert_equal 80, app.terminal_width
673
788
  end
674
789
  end
790
+
791
+ def test_no_rakeopt
792
+ in_environment do
793
+ ARGV << '--trace'
794
+ app = Rake::Application.new
795
+ app.init
796
+ assert !app.options.silent
797
+ end
798
+ end
799
+
800
+ def test_rakeopt_with_blank_options
801
+ in_environment("RAKEOPT" => "") do
802
+ ARGV << '--trace'
803
+ app = Rake::Application.new
804
+ app.init
805
+ assert !app.options.silent
806
+ end
807
+ end
808
+
809
+ def test_rakeopt_with_silent_options
810
+ in_environment("RAKEOPT" => "-s") do
811
+ app = Rake::Application.new
812
+ app.init
813
+ assert app.options.silent
814
+ end
815
+ end
675
816
  end