rake 0.7.3 → 0.8.7

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 (66) hide show
  1. data/CHANGES +126 -1
  2. data/README +86 -132
  3. data/Rakefile +111 -64
  4. data/TODO +1 -0
  5. data/bin/rake +24 -0
  6. data/doc/command_line_usage.rdoc +102 -0
  7. data/doc/rakefile.rdoc +126 -3
  8. data/doc/release_notes/rake-0.7.3.rdoc +0 -0
  9. data/doc/release_notes/rake-0.8.0.rdoc +114 -0
  10. data/doc/release_notes/rake-0.8.2.rdoc +165 -0
  11. data/doc/release_notes/rake-0.8.3.rdoc +112 -0
  12. data/doc/release_notes/rake-0.8.4.rdoc +147 -0
  13. data/doc/release_notes/rake-0.8.5.rdoc +53 -0
  14. data/doc/release_notes/rake-0.8.6.rdoc +55 -0
  15. data/doc/release_notes/rake-0.8.7.rdoc +55 -0
  16. data/lib/rake/alt_system.rb +108 -0
  17. data/lib/rake/contrib/ftptools.rb +24 -10
  18. data/lib/rake/contrib/publisher.rb +1 -1
  19. data/lib/rake/contrib/sys.rb +5 -2
  20. data/lib/rake/gempackagetask.rb +2 -6
  21. data/lib/rake/loaders/makefile.rb +17 -15
  22. data/lib/rake/rdoctask.rb +83 -21
  23. data/lib/rake/ruby182_test_unit_fix.rb +0 -0
  24. data/lib/rake/tasklib.rb +8 -3
  25. data/lib/rake/testtask.rb +1 -1
  26. data/lib/rake/win32.rb +55 -0
  27. data/lib/rake.rb +861 -386
  28. data/test/check_expansion.rb +5 -0
  29. data/test/check_no_expansion.rb +5 -0
  30. data/test/data/file_creation_task/Rakefile +4 -1
  31. data/test/data/multidesc/Rakefile +3 -0
  32. data/test/data/sample.mf +6 -1
  33. data/test/data/statusreturn/Rakefile +8 -0
  34. data/test/filecreation.rb +0 -2
  35. data/test/functional.rb +3 -1
  36. data/test/in_environment.rb +30 -0
  37. data/test/rake_test_setup.rb +24 -0
  38. data/test/session_functional.rb +145 -24
  39. data/test/shellcommand.rb +0 -0
  40. data/test/test_application.rb +345 -95
  41. data/test/test_definitions.rb +4 -1
  42. data/test/test_earlytime.rb +2 -2
  43. data/test/test_extension.rb +63 -0
  44. data/test/test_file_task.rb +20 -16
  45. data/test/test_filelist.rb +59 -10
  46. data/test/test_fileutils.rb +59 -38
  47. data/test/test_ftp.rb +5 -1
  48. data/test/test_invocation_chain.rb +81 -0
  49. data/test/test_makefile_loader.rb +5 -2
  50. data/test/test_namespace.rb +37 -14
  51. data/test/test_package_task.rb +3 -15
  52. data/test/test_pathmap.rb +24 -2
  53. data/test/test_pseudo_status.rb +26 -0
  54. data/test/test_rake.rb +9 -2
  55. data/test/test_rdoc_task.rb +88 -0
  56. data/test/test_require.rb +3 -1
  57. data/test/test_rules.rb +56 -12
  58. data/test/test_task_arguments.rb +89 -0
  59. data/test/test_task_manager.rb +27 -2
  60. data/test/test_tasklib.rb +12 -0
  61. data/test/test_tasks.rb +248 -20
  62. data/test/test_test_task.rb +3 -2
  63. data/test/test_top_level_functions.rb +10 -3
  64. data/test/test_win32.rb +72 -0
  65. metadata +105 -69
  66. /data/test/contrib/{testsys.rb → test_sys.rb} +0 -0
@@ -8,18 +8,21 @@ end
8
8
 
9
9
  require 'test/unit'
10
10
  require 'rake'
11
+ require 'test/rake_test_setup'
11
12
  require 'test/capture_stdout'
12
- require 'flexmock'
13
+ require 'test/in_environment'
13
14
 
14
15
  TESTING_REQUIRE = [ ]
15
16
 
16
17
  ######################################################################
17
18
  class TestApplication < Test::Unit::TestCase
18
19
  include CaptureStdout
19
- include FlexMock::TestCase
20
+ include InEnvironment
21
+ include TestMethods
20
22
 
21
23
  def setup
22
24
  @app = Rake::Application.new
25
+ @app.options.rakelib = []
23
26
  end
24
27
 
25
28
  def test_constant_warning
@@ -31,16 +34,83 @@ class TestApplication < Test::Unit::TestCase
31
34
 
32
35
  def test_display_tasks
33
36
  @app.options.show_task_pattern = //
34
- @app.last_comment = "COMMENT"
37
+ @app.last_description = "COMMENT"
35
38
  @app.define_task(Rake::Task, "t")
36
39
  out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
37
40
  assert_match(/^rake t/, out)
38
41
  assert_match(/# COMMENT/, out)
39
42
  end
40
43
 
44
+ def test_display_tasks_with_long_comments
45
+ in_environment('RAKE_COLUMNS' => '80') do
46
+ @app.options.show_task_pattern = //
47
+ @app.last_description = "1234567890" * 8
48
+ @app.define_task(Rake::Task, "t")
49
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
50
+ assert_match(/^rake t/, out)
51
+ assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
52
+ end
53
+ end
54
+
55
+ def test_display_tasks_with_task_name_wider_than_tty_display
56
+ in_environment('RAKE_COLUMNS' => '80') do
57
+ @app.options.show_task_pattern = //
58
+ description = "something short"
59
+ task_name = "task name" * 80
60
+ @app.last_description = "something short"
61
+ @app.define_task(Rake::Task, task_name )
62
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
63
+ # Ensure the entire task name is output and we end up showing no description
64
+ assert_match(/rake #{task_name} # .../, out)
65
+ end
66
+ end
67
+
68
+ def test_display_tasks_with_very_long_task_name_to_a_non_tty_shows_name_and_comment
69
+ @app.options.show_task_pattern = //
70
+ @app.tty_output = false
71
+ description = "something short"
72
+ task_name = "task name" * 80
73
+ @app.last_description = "something short"
74
+ @app.define_task(Rake::Task, task_name )
75
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
76
+ # Ensure the entire task name is output and we end up showing no description
77
+ assert_match(/rake #{task_name} # #{description}/, out)
78
+ end
79
+
80
+ def test_display_tasks_with_long_comments_to_a_non_tty_shows_entire_comment
81
+ @app.options.show_task_pattern = //
82
+ @app.tty_output = false
83
+ @app.last_description = "1234567890" * 8
84
+ @app.define_task(Rake::Task, "t")
85
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
86
+ assert_match(/^rake t/, out)
87
+ assert_match(/# #{@app.last_description}/, out)
88
+ end
89
+
90
+ def test_display_tasks_with_long_comments_to_a_non_tty_with_columns_set_truncates_comments
91
+ in_environment("RAKE_COLUMNS" => '80') do
92
+ @app.options.show_task_pattern = //
93
+ @app.tty_output = false
94
+ @app.last_description = "1234567890" * 8
95
+ @app.define_task(Rake::Task, "t")
96
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
97
+ assert_match(/^rake t/, out)
98
+ assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
99
+ end
100
+ end
101
+
102
+ def test_display_tasks_with_full_descriptions
103
+ @app.options.show_task_pattern = //
104
+ @app.options.full_description = true
105
+ @app.last_description = "COMMENT"
106
+ @app.define_task(Rake::Task, "t")
107
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
108
+ assert_match(/^rake t$/, out)
109
+ assert_match(/^ {4}COMMENT$/, out)
110
+ end
111
+
41
112
  def test_finding_rakefile
42
- assert @app.instance_eval { have_rakefile }
43
- assert_equal "rakefile", @app.rakefile.downcase
113
+ assert_match(/Rakefile/i, @app.instance_eval { have_rakefile })
44
114
  end
45
115
 
46
116
  def test_not_finding_rakefile
@@ -50,52 +120,59 @@ class TestApplication < Test::Unit::TestCase
50
120
  end
51
121
 
52
122
  def test_load_rakefile
53
- original_dir = Dir.pwd
54
- Dir.chdir("test/data/unittest")
55
- @app.instance_eval do
56
- handle_options
57
- options.silent = true
58
- load_rakefile
123
+ in_environment("PWD" => "test/data/unittest") do
124
+ @app.instance_eval do
125
+ handle_options
126
+ options.silent = true
127
+ load_rakefile
128
+ end
129
+ assert_equal "rakefile", @app.rakefile.downcase
130
+ assert_match(%r(unittest$), Dir.pwd)
59
131
  end
60
- assert_equal "rakefile", @app.rakefile.downcase
61
- assert_match(%r(unittest$), Dir.pwd)
62
- ensure
63
- Dir.chdir(original_dir)
64
132
  end
65
133
 
66
134
  def test_load_rakefile_from_subdir
67
- original_dir = Dir.pwd
68
- Dir.chdir("test/data/unittest/subdir")
69
- @app.instance_eval do
70
- handle_options
71
- options.silent = true
72
- load_rakefile
135
+ in_environment("PWD" => "test/data/unittest/subdir") do
136
+ @app.instance_eval do
137
+ handle_options
138
+ options.silent = true
139
+ load_rakefile
140
+ end
141
+ assert_equal "rakefile", @app.rakefile.downcase
142
+ assert_match(%r(unittest$), Dir.pwd)
73
143
  end
74
- assert_equal "rakefile", @app.rakefile.downcase
75
- assert_match(%r(unittest$), Dir.pwd)
76
- ensure
77
- Dir.chdir(original_dir)
78
144
  end
79
145
 
80
146
  def test_load_rakefile_not_found
81
- original_dir = Dir.pwd
82
- Dir.chdir("/")
83
- @app.instance_eval do
84
- handle_options
85
- options.silent = true
147
+ in_environment("PWD" => "/", "RAKE_SYSTEM" => 'not_exist') do
148
+ @app.instance_eval do
149
+ handle_options
150
+ options.silent = true
151
+ end
152
+ ex = assert_exception(RuntimeError) do
153
+ @app.instance_eval do raw_load_rakefile end
154
+ end
155
+ assert_match(/no rakefile found/i, ex.message)
86
156
  end
87
- ex = assert_raise(RuntimeError) do
88
- @app.instance_eval do raw_load_rakefile end
157
+ end
158
+
159
+ def test_load_from_system_rakefile
160
+ in_environment('RAKE_SYSTEM' => 'test/data/sys') do
161
+ @app.options.rakelib = []
162
+ @app.instance_eval do
163
+ handle_options
164
+ options.silent = true
165
+ options.load_system = true
166
+ options.rakelib = []
167
+ load_rakefile
168
+ end
169
+ assert_equal "test/data/sys", @app.system_dir
170
+ assert_nil @app.rakefile
89
171
  end
90
- assert_match(/no rakefile found/i, ex.message)
91
- ensure
92
- Dir.chdir(original_dir)
93
172
  end
94
173
 
95
- def test_not_caring_about_finding_rakefile
96
- @app.instance_eval do @rakefiles = [''] end
97
- assert(@app.instance_eval do have_rakefile end)
98
- assert_equal '', @app.rakefile
174
+ def test_windows
175
+ assert ! (@app.windows? && @app.unix?)
99
176
  end
100
177
 
101
178
  def test_loading_imports
@@ -120,21 +197,38 @@ class TestApplication < Test::Unit::TestCase
120
197
  end
121
198
  end
122
199
 
200
+ def test_handle_options_should_strip_options_from_ARGV
201
+ assert !@app.options.trace
202
+
203
+ valid_option = '--trace'
204
+ ARGV.clear
205
+ ARGV << valid_option
206
+
207
+ @app.handle_options
208
+
209
+ assert !ARGV.include?(valid_option)
210
+ assert @app.options.trace
211
+ end
212
+
123
213
  def test_good_run
124
214
  ran = false
215
+ ARGV.clear
216
+ ARGV << '--rakelib=""'
125
217
  @app.options.silent = true
126
218
  @app.instance_eval do
127
219
  intern(Rake::Task, "default").enhance { ran = true }
128
220
  end
129
- @app.run
221
+ in_environment("PWD" => "test/data/default") do
222
+ @app.run
223
+ end
130
224
  assert ran
131
225
  end
132
226
 
133
227
  def test_display_task_run
134
228
  ran = false
135
229
  ARGV.clear
136
- ARGV << '-f' << '-s' << '--tasks'
137
- @app.last_comment = "COMMENT"
230
+ ARGV << '-f' << '-s' << '--tasks' << '--rakelib=""'
231
+ @app.last_description = "COMMENT"
138
232
  @app.define_task(Rake::Task, "default")
139
233
  out = capture_stdout { @app.run }
140
234
  assert @app.options.show_tasks
@@ -146,8 +240,8 @@ class TestApplication < Test::Unit::TestCase
146
240
  def test_display_prereqs
147
241
  ran = false
148
242
  ARGV.clear
149
- ARGV << '-f' << '-s' << '--prereqs'
150
- @app.last_comment = "COMMENT"
243
+ ARGV << '-f' << '-s' << '--prereqs' << '--rakelib=""'
244
+ @app.last_description = "COMMENT"
151
245
  t = @app.define_task(Rake::Task, "default")
152
246
  t.enhance([:a, :b])
153
247
  @app.define_task(Rake::Task, "a")
@@ -163,8 +257,8 @@ class TestApplication < Test::Unit::TestCase
163
257
  def test_bad_run
164
258
  @app.intern(Rake::Task, "default").enhance { fail }
165
259
  ARGV.clear
166
- ARGV << '-f' << '-s'
167
- assert_raise(SystemExit) {
260
+ ARGV << '-f' << '-s' << '--rakelib=""'
261
+ assert_exception(SystemExit) {
168
262
  err = capture_stderr { @app.run }
169
263
  assert_match(/see full trace/, err)
170
264
  }
@@ -176,7 +270,7 @@ class TestApplication < Test::Unit::TestCase
176
270
  @app.intern(Rake::Task, "default").enhance { fail }
177
271
  ARGV.clear
178
272
  ARGV << '-f' << '-s' << '-t'
179
- assert_raise(SystemExit) {
273
+ assert_exception(SystemExit) {
180
274
  err = capture_stderr { capture_stdout { @app.run } }
181
275
  assert_no_match(/see full trace/, err)
182
276
  }
@@ -188,24 +282,25 @@ class TestApplication < Test::Unit::TestCase
188
282
  @app.intern(Rake::Task, "default").enhance { fail }
189
283
  ARGV.clear
190
284
  ARGV << '-f' << '-s' << '--xyzzy'
191
- assert_raise(SystemExit) {
285
+ assert_exception(SystemExit) {
192
286
  err = capture_stderr { capture_stdout { @app.run } }
193
287
  }
194
288
  ensure
195
289
  ARGV.clear
196
290
  end
197
-
198
291
  end
199
292
 
200
293
 
201
294
  ######################################################################
202
295
  class TestApplicationOptions < Test::Unit::TestCase
203
296
  include CaptureStdout
297
+ include TestMethods
204
298
 
205
299
  def setup
206
300
  clear_argv
207
301
  RakeFileUtils.verbose_flag = false
208
302
  RakeFileUtils.nowrite_flag = false
303
+ TESTING_REQUIRE.clear
209
304
  end
210
305
 
211
306
  def teardown
@@ -222,27 +317,23 @@ class TestApplicationOptions < Test::Unit::TestCase
222
317
 
223
318
  def test_default_options
224
319
  opts = command_line
225
- assert_nil opts.show_task_pattern
320
+ assert_nil opts.classic_namespace
226
321
  assert_nil opts.dryrun
227
- assert_nil opts.trace
322
+ assert_nil opts.full_description
323
+ assert_nil opts.ignore_system
324
+ assert_nil opts.load_system
228
325
  assert_nil opts.nosearch
229
- assert_nil opts.silent
326
+ assert_equal ['rakelib'], opts.rakelib
230
327
  assert_nil opts.show_prereqs
328
+ assert_nil opts.show_task_pattern
231
329
  assert_nil opts.show_tasks
232
- assert_nil opts.classic_namespace
233
- assert_equal 'rakelib', opts.rakelib
330
+ assert_nil opts.silent
331
+ assert_nil opts.trace
332
+ assert_equal ['rakelib'], opts.rakelib
234
333
  assert ! RakeFileUtils.verbose_flag
235
334
  assert ! RakeFileUtils.nowrite_flag
236
335
  end
237
336
 
238
- def test_trace_option
239
- flags('--trace', '-t') do |opts|
240
- assert opts.trace
241
- assert RakeFileUtils.verbose_flag
242
- assert ! RakeFileUtils.nowrite_flag
243
- end
244
- end
245
-
246
337
  def test_dry_run
247
338
  flags('--dry-run', '-n') do |opts|
248
339
  assert opts.dryrun
@@ -252,20 +343,57 @@ class TestApplicationOptions < Test::Unit::TestCase
252
343
  end
253
344
  end
254
345
 
255
- def test_help
256
- flags('--help', '-H') do |opts, output|
257
- assert_match(/\Arake/, @out)
258
- assert_match(/--help/, @out)
346
+ 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)
351
+ end
352
+ end
353
+
354
+ 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)
359
+ end
360
+ end
361
+
362
+ def test_execute
363
+ $xyzzy = 0
364
+ flags('--execute=$xyzzy=1', '-e $xyzzy=1') do |opts|
365
+ assert_equal 1, $xyzzy
259
366
  assert_equal :exit, @exit
367
+ $xyzzy = 0
368
+ end
369
+ end
370
+
371
+ 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
376
+ $xyzzy = 0
260
377
  end
261
378
  end
262
379
 
263
- def test_usage
264
- flags('--usage', '-h') do |opts, output|
380
+ 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)
386
+ $xyzzy = 0
387
+ end
388
+ end
389
+
390
+ def test_help
391
+ flags('--help', '-H', '-h') do |opts|
265
392
  assert_match(/\Arake/, @out)
266
393
  assert_match(/\boptions\b/, @out)
267
394
  assert_match(/\btargets\b/, @out)
268
395
  assert_equal :exit, @exit
396
+ assert_equal :exit, @exit
269
397
  end
270
398
  end
271
399
 
@@ -277,13 +405,37 @@ class TestApplicationOptions < Test::Unit::TestCase
277
405
  $:.delete('xx')
278
406
  end
279
407
 
280
- def test_nosearch
281
- flags('--nosearch', '-N') do |opts|
282
- assert opts.nosearch
408
+ def test_rakefile
409
+ flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
410
+ assert_equal ['RF'], @app.instance_eval { @rakefiles }
283
411
  end
284
412
  end
285
413
 
286
- def test_show_prereqs
414
+ 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
417
+ end
418
+ end
419
+
420
+ def test_require
421
+ flags(['--require', 'test/reqfile'], '-rtest/reqfile2', '-rtest/reqfile3') do |opts|
422
+ 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
+ end
428
+
429
+ def test_missing_require
430
+ ex = assert_exception(LoadError) do
431
+ flags(['--require', 'test/missing']) do |opts|
432
+ end
433
+ end
434
+ assert_match(/no such file/, ex.message)
435
+ assert_match(/test\/missing/, ex.message)
436
+ end
437
+
438
+ def test_prereqs
287
439
  flags('--prereqs', '-P') do |opts|
288
440
  assert opts.show_prereqs
289
441
  end
@@ -296,6 +448,12 @@ class TestApplicationOptions < Test::Unit::TestCase
296
448
  end
297
449
  end
298
450
 
451
+ def test_no_search
452
+ flags('--nosearch', '--no-search', '-N') do |opts|
453
+ assert opts.nosearch
454
+ end
455
+ end
456
+
299
457
  def test_silent
300
458
  flags('--silent', '-s') do |opts|
301
459
  assert ! RakeFileUtils.verbose_flag
@@ -303,34 +461,30 @@ class TestApplicationOptions < Test::Unit::TestCase
303
461
  end
304
462
  end
305
463
 
306
- def test_rakefile
307
- flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
308
- assert_equal ['RF'], @app.instance_eval { @rakefiles }
464
+ def test_system
465
+ flags('--system', '-g') do |opts|
466
+ assert opts.load_system
309
467
  end
310
468
  end
311
469
 
312
- def test_rakelib
313
- flags(['--rakelibdir', 'A:B:C'], ['--rakelibdir=A:B:C'], ['-R', 'A:B:C'], ['-RA:B:C']) do |opts|
314
- assert_equal ['A', 'B', 'C'], opts.rakelib
470
+ def test_no_system
471
+ flags('--no-system', '-G') do |opts|
472
+ assert opts.ignore_system
315
473
  end
316
474
  end
317
475
 
318
- def test_require
319
- flags(['--require', 'test/reqfile'], '-rtest/reqfile2', '-rtest/reqfile3') do |opts|
476
+ def test_trace
477
+ flags('--trace', '-t') do |opts|
478
+ assert opts.trace
479
+ assert RakeFileUtils.verbose_flag
480
+ assert ! RakeFileUtils.nowrite_flag
320
481
  end
321
- assert TESTING_REQUIRE.include?(1)
322
- assert TESTING_REQUIRE.include?(2)
323
- assert TESTING_REQUIRE.include?(3)
324
- assert_equal 3, TESTING_REQUIRE.size
325
482
  end
326
483
 
327
- def test_missing_require
328
- ex = assert_raises(LoadError) do
329
- flags(['--require', 'test/missing']) do |opts|
330
- end
484
+ def test_trace_rules
485
+ flags('--rules') do |opts|
486
+ assert opts.trace_rules
331
487
  end
332
- assert_match(/no such file/, ex.message)
333
- assert_match(/test\/missing/, ex.message)
334
488
  end
335
489
 
336
490
  def test_tasks
@@ -372,11 +526,15 @@ class TestApplicationOptions < Test::Unit::TestCase
372
526
 
373
527
  def test_bad_option
374
528
  capture_stderr do
375
- ex = assert_raise(GetoptLong::InvalidOption) do
529
+ ex = assert_exception(OptionParser::InvalidOption) do
376
530
  flags('--bad-option')
377
531
  end
378
- assert_match(/unrecognized option/, ex.message)
379
- assert_match(/--bad-option/, ex.message)
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)
537
+ end
380
538
  end
381
539
  end
382
540
 
@@ -391,16 +549,17 @@ class TestApplicationOptions < Test::Unit::TestCase
391
549
  end
392
550
 
393
551
  def test_environment_definition
394
- ENV['TESTKEY'] = nil
552
+ ENV.delete('TESTKEY')
395
553
  command_line("a", "TESTKEY=12")
396
554
  assert_equal ["a"], @tasks.sort
397
555
  assert '12', ENV['TESTKEY']
398
556
  end
399
-
557
+
400
558
  private
401
559
 
402
560
  def flags(*sets)
403
561
  sets.each do |set|
562
+ ARGV.clear
404
563
  @out = capture_stdout {
405
564
  @exit = catch(:system_exit) { opts = command_line(*set) }
406
565
  }
@@ -423,3 +582,94 @@ class TestApplicationOptions < Test::Unit::TestCase
423
582
  end
424
583
  end
425
584
 
585
+ class TestTaskArgumentParsing < Test::Unit::TestCase
586
+ def setup
587
+ @app = Rake::Application.new
588
+ end
589
+
590
+ def test_name_only
591
+ name, args = @app.parse_task_string("name")
592
+ assert_equal "name", name
593
+ assert_equal [], args
594
+ end
595
+
596
+ def test_empty_args
597
+ name, args = @app.parse_task_string("name[]")
598
+ assert_equal "name", name
599
+ assert_equal [], args
600
+ end
601
+
602
+ def test_one_argument
603
+ name, args = @app.parse_task_string("name[one]")
604
+ assert_equal "name", name
605
+ assert_equal ["one"], args
606
+ end
607
+
608
+ def test_two_arguments
609
+ name, args = @app.parse_task_string("name[one,two]")
610
+ assert_equal "name", name
611
+ assert_equal ["one", "two"], args
612
+ end
613
+
614
+ def test_can_handle_spaces_between_args
615
+ name, args = @app.parse_task_string("name[one, two,\tthree , \tfour]")
616
+ assert_equal "name", name
617
+ assert_equal ["one", "two", "three", "four"], args
618
+ end
619
+
620
+ def test_keeps_embedded_spaces
621
+ name, args = @app.parse_task_string("name[a one ana, two]")
622
+ assert_equal "name", name
623
+ assert_equal ["a one ana", "two"], args
624
+ end
625
+
626
+ end
627
+
628
+ class TestTaskArgumentParsing < Test::Unit::TestCase
629
+ include InEnvironment
630
+
631
+ def test_terminal_width_using_env
632
+ app = Rake::Application.new
633
+ in_environment('RAKE_COLUMNS' => '1234') do
634
+ assert_equal 1234, app.terminal_width
635
+ end
636
+ end
637
+
638
+ def test_terminal_width_using_stty
639
+ app = Rake::Application.new
640
+ flexmock(app,
641
+ :unix? => true,
642
+ :dynamic_width_stty => 1235,
643
+ :dynamic_width_tput => 0)
644
+ in_environment('RAKE_COLUMNS' => nil) do
645
+ assert_equal 1235, app.terminal_width
646
+ end
647
+ end
648
+
649
+ def test_terminal_width_using_tput
650
+ app = Rake::Application.new
651
+ flexmock(app,
652
+ :unix? => true,
653
+ :dynamic_width_stty => 0,
654
+ :dynamic_width_tput => 1236)
655
+ in_environment('RAKE_COLUMNS' => nil) do
656
+ assert_equal 1236, app.terminal_width
657
+ end
658
+ end
659
+
660
+ def test_terminal_width_using_hardcoded_80
661
+ app = Rake::Application.new
662
+ flexmock(app, :unix? => false)
663
+ in_environment('RAKE_COLUMNS' => nil) do
664
+ assert_equal 80, app.terminal_width
665
+ end
666
+ end
667
+
668
+ def test_terminal_width_with_failure
669
+ app = Rake::Application.new
670
+ flexmock(app).should_receive(:unix?).and_throw(RuntimeError)
671
+ in_environment('RAKE_COLUMNS' => nil) do
672
+ assert_equal 80, app.terminal_width
673
+ end
674
+ end
675
+ end
@@ -4,10 +4,13 @@ require 'test/unit'
4
4
  require 'fileutils'
5
5
  require 'rake'
6
6
  require 'test/filecreation'
7
+ require 'test/rake_test_setup'
7
8
 
8
9
  ######################################################################
9
10
  class TestDefinitions < Test::Unit::TestCase
10
11
  include Rake
12
+ include TestMethods
13
+
11
14
  EXISTINGFILE = "testdata/existing"
12
15
 
13
16
  def setup
@@ -58,7 +61,7 @@ class TestDefinitions < Test::Unit::TestCase
58
61
 
59
62
  def test_missing_dependencies
60
63
  task :x => ["testdata/missing"]
61
- assert_raises(RuntimeError) { Task[:x].invoke }
64
+ assert_exception(RuntimeError) { Task[:x].invoke }
62
65
  end
63
66
 
64
67
  def test_implicit_file_dependencies
@@ -6,7 +6,7 @@ require 'rake'
6
6
  class TestEarlyTime < Test::Unit::TestCase
7
7
  def test_create
8
8
  early = Rake::EarlyTime.instance
9
- time = Time.mktime(1920, 1, 1, 0, 0, 0)
9
+ time = Time.mktime(1970, 1, 1, 0, 0, 0)
10
10
  assert early <= Time.now
11
11
  assert early < Time.now
12
12
  assert early != Time.now
@@ -21,7 +21,7 @@ class TestEarlyTime < Test::Unit::TestCase
21
21
  end
22
22
 
23
23
  def test_original_time_compare_is_not_messed_up
24
- t1 = Time.mktime(1920, 1, 1, 0, 0, 0)
24
+ t1 = Time.mktime(1970, 1, 1, 0, 0, 0)
25
25
  t2 = Time.now
26
26
  assert t1 < t2
27
27
  assert t2 > t1