craigmarksmith-rake 0.8.3.100

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/CHANGES +427 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +196 -0
  4. data/Rakefile +416 -0
  5. data/TODO +20 -0
  6. data/bin/rake +31 -0
  7. data/doc/command_line_usage.rdoc +102 -0
  8. data/doc/example/Rakefile1 +38 -0
  9. data/doc/example/Rakefile2 +35 -0
  10. data/doc/example/a.c +6 -0
  11. data/doc/example/b.c +6 -0
  12. data/doc/example/main.c +11 -0
  13. data/doc/glossary.rdoc +51 -0
  14. data/doc/jamis.rb +591 -0
  15. data/doc/proto_rake.rdoc +127 -0
  16. data/doc/rake.1.gz +0 -0
  17. data/doc/rakefile.rdoc +534 -0
  18. data/doc/rational.rdoc +151 -0
  19. data/doc/release_notes/rake-0.4.14.rdoc +23 -0
  20. data/doc/release_notes/rake-0.4.15.rdoc +35 -0
  21. data/doc/release_notes/rake-0.5.0.rdoc +53 -0
  22. data/doc/release_notes/rake-0.5.3.rdoc +78 -0
  23. data/doc/release_notes/rake-0.5.4.rdoc +46 -0
  24. data/doc/release_notes/rake-0.6.0.rdoc +141 -0
  25. data/doc/release_notes/rake-0.7.0.rdoc +119 -0
  26. data/doc/release_notes/rake-0.7.1.rdoc +59 -0
  27. data/doc/release_notes/rake-0.7.2.rdoc +121 -0
  28. data/doc/release_notes/rake-0.7.3.rdoc +47 -0
  29. data/doc/release_notes/rake-0.8.0.rdoc +114 -0
  30. data/doc/release_notes/rake-0.8.2.rdoc +165 -0
  31. data/doc/release_notes/rake-0.8.3.rdoc +112 -0
  32. data/doc/release_notes/rake-0.8.4.rdoc +147 -0
  33. data/install.rb +88 -0
  34. data/lib/rake/classic_namespace.rb +8 -0
  35. data/lib/rake/clean.rb +33 -0
  36. data/lib/rake/contrib/compositepublisher.rb +24 -0
  37. data/lib/rake/contrib/ftptools.rb +153 -0
  38. data/lib/rake/contrib/publisher.rb +75 -0
  39. data/lib/rake/contrib/rubyforgepublisher.rb +18 -0
  40. data/lib/rake/contrib/sshpublisher.rb +47 -0
  41. data/lib/rake/contrib/sys.rb +209 -0
  42. data/lib/rake/gempackagetask.rb +97 -0
  43. data/lib/rake/loaders/makefile.rb +42 -0
  44. data/lib/rake/packagetask.rb +184 -0
  45. data/lib/rake/rake_test_loader.rb +5 -0
  46. data/lib/rake/rdoctask.rb +209 -0
  47. data/lib/rake/ruby182_test_unit_fix.rb +23 -0
  48. data/lib/rake/runtest.rb +23 -0
  49. data/lib/rake/tasklib.rb +23 -0
  50. data/lib/rake/testtask.rb +161 -0
  51. data/lib/rake/win32.rb +55 -0
  52. data/lib/rake.rb +2519 -0
  53. data/test/capture_stdout.rb +26 -0
  54. data/test/check_expansion.rb +5 -0
  55. data/test/contrib/test_sys.rb +47 -0
  56. data/test/data/chains/Rakefile +15 -0
  57. data/test/data/default/Rakefile +19 -0
  58. data/test/data/dryrun/Rakefile +22 -0
  59. data/test/data/file_creation_task/Rakefile +33 -0
  60. data/test/data/imports/Rakefile +19 -0
  61. data/test/data/imports/deps.mf +1 -0
  62. data/test/data/multidesc/Rakefile +17 -0
  63. data/test/data/namespace/Rakefile +57 -0
  64. data/test/data/rakelib/test1.rb +3 -0
  65. data/test/data/rbext/rakefile.rb +3 -0
  66. data/test/data/sample.mf +14 -0
  67. data/test/data/statusreturn/Rakefile +8 -0
  68. data/test/data/unittest/Rakefile +1 -0
  69. data/test/filecreation.rb +32 -0
  70. data/test/functional.rb +15 -0
  71. data/test/in_environment.rb +30 -0
  72. data/test/rake_test_setup.rb +24 -0
  73. data/test/reqfile.rb +3 -0
  74. data/test/reqfile2.rb +3 -0
  75. data/test/session_functional.rb +339 -0
  76. data/test/shellcommand.rb +3 -0
  77. data/test/test_application.rb +690 -0
  78. data/test/test_clean.rb +14 -0
  79. data/test/test_definitions.rb +85 -0
  80. data/test/test_earlytime.rb +35 -0
  81. data/test/test_extension.rb +63 -0
  82. data/test/test_file_creation_task.rb +62 -0
  83. data/test/test_file_task.rb +143 -0
  84. data/test/test_filelist.rb +623 -0
  85. data/test/test_fileutils.rb +251 -0
  86. data/test/test_ftp.rb +59 -0
  87. data/test/test_invocation_chain.rb +81 -0
  88. data/test/test_makefile_loader.rb +26 -0
  89. data/test/test_multitask.rb +45 -0
  90. data/test/test_namespace.rb +55 -0
  91. data/test/test_package_task.rb +118 -0
  92. data/test/test_pathmap.rb +210 -0
  93. data/test/test_rake.rb +41 -0
  94. data/test/test_rdoc_task.rb +88 -0
  95. data/test/test_require.rb +35 -0
  96. data/test/test_rules.rb +349 -0
  97. data/test/test_task_arguments.rb +89 -0
  98. data/test/test_task_manager.rb +173 -0
  99. data/test/test_tasklib.rb +12 -0
  100. data/test/test_tasks.rb +374 -0
  101. data/test/test_test_task.rb +77 -0
  102. data/test/test_top_level_functions.rb +86 -0
  103. data/test/test_win32.rb +72 -0
  104. metadata +186 -0
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ exit((ARGV[0] || "0").to_i)
@@ -0,0 +1,690 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'rubygems'
5
+ rescue LoadError
6
+ # got no gems
7
+ end
8
+
9
+ require 'test/unit'
10
+ require 'rake'
11
+ require 'test/rake_test_setup'
12
+ require 'test/capture_stdout'
13
+ require 'test/in_environment'
14
+
15
+ TESTING_REQUIRE = [ ]
16
+
17
+ ######################################################################
18
+ class TestApplication < Test::Unit::TestCase
19
+ include CaptureStdout
20
+ include InEnvironment
21
+ include TestMethods
22
+
23
+ def setup
24
+ @app = Rake::Application.new
25
+ @app.options.rakelib = []
26
+ end
27
+
28
+ 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)
33
+ end
34
+
35
+ def test_display_tasks
36
+ @app.options.show_task_pattern = //
37
+ @app.last_description = "COMMENT"
38
+ @app.define_task(Rake::Task, "t")
39
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
40
+ assert_match(/^rake t/, out)
41
+ assert_match(/# COMMENT/, out)
42
+ end
43
+
44
+ def test_interactive_task
45
+ flexmock(@app)
46
+ @app.should_receive(:readline).and_return(0).once
47
+ @app.options.show_task_pattern = //
48
+ @app.options.interactive = true
49
+ @app.last_description = "COMMENT"
50
+ test_task = Rake::Task
51
+ flexmock(test_task)
52
+ test_task.new_instances.should_receive(:invoke).once
53
+ @app.define_task(test_task, "t")
54
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
55
+ assert_match(/^0\) rake t/, out)
56
+ assert_match(/# COMMENT/, out)
57
+ end
58
+
59
+ def test_display_tasks_with_long_comments
60
+ in_environment('RAKE_COLUMNS' => '80') do
61
+ @app.options.show_task_pattern = //
62
+ @app.last_description = "1234567890" * 8
63
+ @app.define_task(Rake::Task, "t")
64
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
65
+ assert_match(/^rake t/, out)
66
+ assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
67
+ end
68
+ end
69
+
70
+ def test_display_tasks_with_task_name_wider_than_tty_display
71
+ in_environment('RAKE_COLUMNS' => '80') do
72
+ @app.options.show_task_pattern = //
73
+ description = "something short"
74
+ task_name = "task name" * 80
75
+ @app.last_description = "something short"
76
+ @app.define_task(Rake::Task, task_name )
77
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
78
+ # Ensure the entire task name is output and we end up showing no description
79
+ assert_match(/rake #{task_name} # .../, out)
80
+ end
81
+ end
82
+
83
+ def test_display_tasks_with_very_long_task_name_to_a_non_tty_shows_name_and_comment
84
+ @app.options.show_task_pattern = //
85
+ @app.tty_output = false
86
+ description = "something short"
87
+ task_name = "task name" * 80
88
+ @app.last_description = "something short"
89
+ @app.define_task(Rake::Task, task_name )
90
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
91
+ # Ensure the entire task name is output and we end up showing no description
92
+ assert_match(/rake #{task_name} # #{description}/, out)
93
+ end
94
+
95
+ def test_display_tasks_with_long_comments_to_a_non_tty_shows_entire_comment
96
+ @app.options.show_task_pattern = //
97
+ @app.tty_output = false
98
+ @app.last_description = "1234567890" * 8
99
+ @app.define_task(Rake::Task, "t")
100
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
101
+ assert_match(/^rake t/, out)
102
+ assert_match(/# #{@app.last_description}/, out)
103
+ end
104
+
105
+ def test_display_tasks_with_long_comments_to_a_non_tty_with_columns_set_truncates_comments
106
+ in_environment("RAKE_COLUMNS" => '80') do
107
+ @app.options.show_task_pattern = //
108
+ @app.tty_output = false
109
+ @app.last_description = "1234567890" * 8
110
+ @app.define_task(Rake::Task, "t")
111
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
112
+ assert_match(/^rake t/, out)
113
+ assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
114
+ end
115
+ end
116
+
117
+ def test_display_tasks_with_full_descriptions
118
+ @app.options.show_task_pattern = //
119
+ @app.options.full_description = true
120
+ @app.last_description = "COMMENT"
121
+ @app.define_task(Rake::Task, "t")
122
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
123
+ assert_match(/^rake t$/, out)
124
+ assert_match(/^ {4}COMMENT$/, out)
125
+ end
126
+
127
+ def test_finding_rakefile
128
+ assert_match(/Rakefile/i, @app.instance_eval { have_rakefile })
129
+ end
130
+
131
+ def test_not_finding_rakefile
132
+ @app.instance_eval { @rakefiles = ['NEVER_FOUND'] }
133
+ assert( ! @app.instance_eval do have_rakefile end )
134
+ assert_nil @app.rakefile
135
+ end
136
+
137
+ def test_load_rakefile
138
+ in_environment("PWD" => "test/data/unittest") do
139
+ @app.instance_eval do
140
+ handle_options
141
+ options.silent = true
142
+ load_rakefile
143
+ end
144
+ assert_equal "rakefile", @app.rakefile.downcase
145
+ assert_match(%r(unittest$), Dir.pwd)
146
+ end
147
+ end
148
+
149
+ def test_load_rakefile_from_subdir
150
+ in_environment("PWD" => "test/data/unittest/subdir") do
151
+ @app.instance_eval do
152
+ handle_options
153
+ options.silent = true
154
+ load_rakefile
155
+ end
156
+ assert_equal "rakefile", @app.rakefile.downcase
157
+ assert_match(%r(unittest$), Dir.pwd)
158
+ end
159
+ end
160
+
161
+ def test_load_rakefile_not_found
162
+ in_environment("PWD" => "/", "RAKE_SYSTEM" => 'not_exist') do
163
+ @app.instance_eval do
164
+ handle_options
165
+ options.silent = true
166
+ end
167
+ ex = assert_exception(RuntimeError) do
168
+ @app.instance_eval do raw_load_rakefile end
169
+ end
170
+ assert_match(/no rakefile found/i, ex.message)
171
+ end
172
+ end
173
+
174
+ def test_load_from_system_rakefile
175
+ in_environment('RAKE_SYSTEM' => 'test/data/sys') do
176
+ @app.options.rakelib = []
177
+ @app.instance_eval do
178
+ handle_options
179
+ options.silent = true
180
+ options.load_system = true
181
+ options.rakelib = []
182
+ load_rakefile
183
+ end
184
+ assert_equal "test/data/sys", @app.system_dir
185
+ assert_nil @app.rakefile
186
+ end
187
+ end
188
+
189
+ def test_windows
190
+ assert ! (@app.windows? && @app.unix?)
191
+ end
192
+
193
+ def test_loading_imports
194
+ mock = flexmock("loader")
195
+ mock.should_receive(:load).with("x.dummy").once
196
+ @app.instance_eval do
197
+ add_loader("dummy", mock)
198
+ add_import("x.dummy")
199
+ load_imports
200
+ end
201
+ end
202
+
203
+ def test_building_imported_files_on_demand
204
+ mock = flexmock("loader")
205
+ mock.should_receive(:load).with("x.dummy").once
206
+ mock.should_receive(:make_dummy).with_no_args.once
207
+ @app.instance_eval do
208
+ intern(Rake::Task, "x.dummy").enhance do mock.make_dummy end
209
+ add_loader("dummy", mock)
210
+ add_import("x.dummy")
211
+ load_imports
212
+ end
213
+ end
214
+
215
+ def test_handle_options_should_strip_options_from_ARGV
216
+ assert !@app.options.trace
217
+
218
+ valid_option = '--trace'
219
+ ARGV.clear
220
+ ARGV << valid_option
221
+
222
+ @app.handle_options
223
+
224
+ assert !ARGV.include?(valid_option)
225
+ assert @app.options.trace
226
+ end
227
+
228
+ def test_good_run
229
+ ran = false
230
+ ARGV.clear
231
+ ARGV << '--rakelib=""'
232
+ @app.options.silent = true
233
+ @app.instance_eval do
234
+ intern(Rake::Task, "default").enhance { ran = true }
235
+ end
236
+ in_environment("PWD" => "test/data/default") do
237
+ @app.run
238
+ end
239
+ assert ran
240
+ end
241
+
242
+ def test_display_task_run
243
+ ran = false
244
+ ARGV.clear
245
+ ARGV << '-f' << '-s' << '--tasks' << '--rakelib=""'
246
+ @app.last_description = "COMMENT"
247
+ @app.define_task(Rake::Task, "default")
248
+ out = capture_stdout { @app.run }
249
+ assert @app.options.show_tasks
250
+ assert ! ran
251
+ assert_match(/rake default/, out)
252
+ assert_match(/# COMMENT/, out)
253
+ end
254
+
255
+ def test_display_prereqs
256
+ ran = false
257
+ ARGV.clear
258
+ ARGV << '-f' << '-s' << '--prereqs' << '--rakelib=""'
259
+ @app.last_description = "COMMENT"
260
+ t = @app.define_task(Rake::Task, "default")
261
+ t.enhance([:a, :b])
262
+ @app.define_task(Rake::Task, "a")
263
+ @app.define_task(Rake::Task, "b")
264
+ out = capture_stdout { @app.run }
265
+ assert @app.options.show_prereqs
266
+ assert ! ran
267
+ assert_match(/rake a$/, out)
268
+ assert_match(/rake b$/, out)
269
+ assert_match(/rake default\n( *(a|b)\n){2}/m, out)
270
+ end
271
+
272
+ def test_bad_run
273
+ @app.intern(Rake::Task, "default").enhance { fail }
274
+ ARGV.clear
275
+ ARGV << '-f' << '-s' << '--rakelib=""'
276
+ assert_exception(SystemExit) {
277
+ err = capture_stderr { @app.run }
278
+ assert_match(/see full trace/, err)
279
+ }
280
+ ensure
281
+ ARGV.clear
282
+ end
283
+
284
+ def test_bad_run_with_trace
285
+ @app.intern(Rake::Task, "default").enhance { fail }
286
+ ARGV.clear
287
+ ARGV << '-f' << '-s' << '-t'
288
+ assert_exception(SystemExit) {
289
+ err = capture_stderr { capture_stdout { @app.run } }
290
+ assert_no_match(/see full trace/, err)
291
+ }
292
+ ensure
293
+ ARGV.clear
294
+ end
295
+
296
+ def test_run_with_bad_options
297
+ @app.intern(Rake::Task, "default").enhance { fail }
298
+ ARGV.clear
299
+ ARGV << '-f' << '-s' << '--xyzzy'
300
+ assert_exception(SystemExit) {
301
+ err = capture_stderr { capture_stdout { @app.run } }
302
+ }
303
+ ensure
304
+ ARGV.clear
305
+ end
306
+ end
307
+
308
+
309
+ ######################################################################
310
+ class TestApplicationOptions < Test::Unit::TestCase
311
+ include CaptureStdout
312
+ include TestMethods
313
+
314
+ def setup
315
+ clear_argv
316
+ RakeFileUtils.verbose_flag = false
317
+ RakeFileUtils.nowrite_flag = false
318
+ TESTING_REQUIRE.clear
319
+ end
320
+
321
+ def teardown
322
+ clear_argv
323
+ RakeFileUtils.verbose_flag = false
324
+ RakeFileUtils.nowrite_flag = false
325
+ end
326
+
327
+ def clear_argv
328
+ while ! ARGV.empty?
329
+ ARGV.pop
330
+ end
331
+ end
332
+
333
+ def test_default_options
334
+ opts = command_line
335
+ assert_nil opts.classic_namespace
336
+ assert_nil opts.dryrun
337
+ assert_nil opts.full_description
338
+ assert_nil opts.ignore_system
339
+ assert_nil opts.load_system
340
+ assert_nil opts.nosearch
341
+ assert_equal ['rakelib'], opts.rakelib
342
+ assert_nil opts.show_prereqs
343
+ assert_nil opts.show_task_pattern
344
+ assert_nil opts.show_tasks
345
+ assert_nil opts.silent
346
+ assert_nil opts.trace
347
+ assert_equal ['rakelib'], opts.rakelib
348
+ assert ! RakeFileUtils.verbose_flag
349
+ assert ! RakeFileUtils.nowrite_flag
350
+ end
351
+
352
+ def test_dry_run
353
+ flags('--dry-run', '-n') do |opts|
354
+ assert opts.dryrun
355
+ assert opts.trace
356
+ assert RakeFileUtils.verbose_flag
357
+ assert RakeFileUtils.nowrite_flag
358
+ end
359
+ end
360
+
361
+ def test_describe
362
+ flags('--describe') do |opts|
363
+ assert opts.full_description
364
+ assert opts.show_tasks
365
+ assert_equal(//.to_s, opts.show_task_pattern.to_s)
366
+ end
367
+ end
368
+
369
+ def test_describe_with_pattern
370
+ flags('--describe=X') do |opts|
371
+ assert opts.full_description
372
+ assert opts.show_tasks
373
+ assert_equal(/X/.to_s, opts.show_task_pattern.to_s)
374
+ end
375
+ end
376
+
377
+ def test_execute
378
+ $xyzzy = 0
379
+ flags('--execute=$xyzzy=1', '-e $xyzzy=1') do |opts|
380
+ assert_equal 1, $xyzzy
381
+ assert_equal :exit, @exit
382
+ $xyzzy = 0
383
+ end
384
+ end
385
+
386
+ def test_execute_and_continue
387
+ $xyzzy = 0
388
+ flags('--execute-continue=$xyzzy=1', '-E $xyzzy=1') do |opts|
389
+ assert_equal 1, $xyzzy
390
+ assert_not_equal :exit, @exit
391
+ $xyzzy = 0
392
+ end
393
+ end
394
+
395
+ def test_execute_and_print
396
+ $xyzzy = 0
397
+ flags('--execute-print=$xyzzy="pugh"', '-p $xyzzy="pugh"') do |opts|
398
+ assert_equal 'pugh', $xyzzy
399
+ assert_equal :exit, @exit
400
+ assert_match(/^pugh$/, @out)
401
+ $xyzzy = 0
402
+ end
403
+ end
404
+
405
+ def test_help
406
+ flags('--help', '-H', '-h') do |opts|
407
+ assert_match(/\Arake/, @out)
408
+ assert_match(/\boptions\b/, @out)
409
+ assert_match(/\btargets\b/, @out)
410
+ assert_equal :exit, @exit
411
+ assert_equal :exit, @exit
412
+ end
413
+ end
414
+
415
+ def test_libdir
416
+ flags(['--libdir', 'xx'], ['-I', 'xx'], ['-Ixx']) do |opts|
417
+ $:.include?('xx')
418
+ end
419
+ ensure
420
+ $:.delete('xx')
421
+ end
422
+
423
+ def test_rakefile
424
+ flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
425
+ assert_equal ['RF'], @app.instance_eval { @rakefiles }
426
+ end
427
+ end
428
+
429
+ def test_rakelib
430
+ flags(['--rakelibdir', 'A:B:C'], ['--rakelibdir=A:B:C'], ['-R', 'A:B:C'], ['-RA:B:C']) do |opts|
431
+ assert_equal ['A', 'B', 'C'], opts.rakelib
432
+ end
433
+ end
434
+
435
+ def test_require
436
+ flags(['--require', 'test/reqfile'], '-rtest/reqfile2', '-rtest/reqfile3') do |opts|
437
+ end
438
+ assert TESTING_REQUIRE.include?(1)
439
+ assert TESTING_REQUIRE.include?(2)
440
+ assert TESTING_REQUIRE.include?(3)
441
+ assert_equal 3, TESTING_REQUIRE.size
442
+ end
443
+
444
+ def test_missing_require
445
+ ex = assert_exception(LoadError) do
446
+ flags(['--require', 'test/missing']) do |opts|
447
+ end
448
+ end
449
+ assert_match(/no such file/, ex.message)
450
+ assert_match(/test\/missing/, ex.message)
451
+ end
452
+
453
+ def test_prereqs
454
+ flags('--prereqs', '-P') do |opts|
455
+ assert opts.show_prereqs
456
+ end
457
+ end
458
+
459
+ def test_quiet
460
+ flags('--quiet', '-q') do |opts|
461
+ assert ! RakeFileUtils.verbose_flag
462
+ assert ! opts.silent
463
+ end
464
+ end
465
+
466
+ def test_no_search
467
+ flags('--nosearch', '--no-search', '-N') do |opts|
468
+ assert opts.nosearch
469
+ end
470
+ end
471
+
472
+ def test_silent
473
+ flags('--silent', '-s') do |opts|
474
+ assert ! RakeFileUtils.verbose_flag
475
+ assert opts.silent
476
+ end
477
+ end
478
+
479
+ def test_system
480
+ flags('--system', '-g') do |opts|
481
+ assert opts.load_system
482
+ end
483
+ end
484
+
485
+ def test_no_system
486
+ flags('--no-system', '-G') do |opts|
487
+ assert opts.ignore_system
488
+ end
489
+ end
490
+
491
+ def test_trace
492
+ flags('--trace', '-t') do |opts|
493
+ assert opts.trace
494
+ assert RakeFileUtils.verbose_flag
495
+ assert ! RakeFileUtils.nowrite_flag
496
+ end
497
+ end
498
+
499
+ def test_trace_rules
500
+ flags('--rules') do |opts|
501
+ assert opts.trace_rules
502
+ end
503
+ end
504
+
505
+ def test_tasks
506
+ flags('--tasks', '-T') do |opts|
507
+ assert opts.show_tasks
508
+ assert_equal(//.to_s, opts.show_task_pattern.to_s)
509
+ end
510
+ flags(['--tasks', 'xyz'], ['-Txyz']) do |opts|
511
+ assert opts.show_tasks
512
+ assert_equal(/xyz/, opts.show_task_pattern)
513
+ end
514
+ end
515
+
516
+ def test_verbose
517
+ flags('--verbose', '-V') do |opts|
518
+ assert RakeFileUtils.verbose_flag
519
+ assert ! opts.silent
520
+ end
521
+ end
522
+
523
+ def test_version
524
+ flags('--version', '-V') do |opts|
525
+ assert_match(/\bversion\b/, @out)
526
+ assert_match(/\b#{RAKEVERSION}\b/, @out)
527
+ assert_equal :exit, @exit
528
+ end
529
+ end
530
+
531
+ def test_classic_namespace
532
+ flags(['--classic-namespace'], ['-C', '-T', '-P', '-n', '-s', '-t']) do |opts|
533
+ assert opts.classic_namespace
534
+ assert_equal opts.show_tasks, $show_tasks
535
+ assert_equal opts.show_prereqs, $show_prereqs
536
+ assert_equal opts.trace, $trace
537
+ assert_equal opts.dryrun, $dryrun
538
+ assert_equal opts.silent, $silent
539
+ end
540
+ end
541
+
542
+ def test_bad_option
543
+ capture_stderr do
544
+ ex = assert_exception(OptionParser::InvalidOption) do
545
+ flags('--bad-option')
546
+ end
547
+ if ex.message =~ /^While/ # Ruby 1.9 error message
548
+ assert_match(/while parsing/i, ex.message)
549
+ else # Ruby 1.8 error message
550
+ assert_match(/(invalid|unrecognized) option/i, ex.message)
551
+ assert_match(/--bad-option/, ex.message)
552
+ end
553
+ end
554
+ end
555
+
556
+ def test_task_collection
557
+ command_line("a", "b")
558
+ assert_equal ["a", "b"], @tasks.sort
559
+ end
560
+
561
+ def test_default_task_collection
562
+ command_line()
563
+ assert_equal ["default"], @tasks
564
+ end
565
+
566
+ def test_environment_definition
567
+ ENV.delete('TESTKEY')
568
+ command_line("a", "TESTKEY=12")
569
+ assert_equal ["a"], @tasks.sort
570
+ assert '12', ENV['TESTKEY']
571
+ end
572
+
573
+ private
574
+
575
+ def flags(*sets)
576
+ sets.each do |set|
577
+ ARGV.clear
578
+ @out = capture_stdout {
579
+ @exit = catch(:system_exit) { opts = command_line(*set) }
580
+ }
581
+ yield(@app.options) if block_given?
582
+ end
583
+ end
584
+
585
+ def command_line(*options)
586
+ options.each do |opt| ARGV << opt end
587
+ @app = Rake::Application.new
588
+ def @app.exit(*args)
589
+ throw :system_exit, :exit
590
+ end
591
+ @app.instance_eval do
592
+ handle_options
593
+ collect_tasks
594
+ end
595
+ @tasks = @app.top_level_tasks
596
+ @app.options
597
+ end
598
+ end
599
+
600
+ class TestTaskArgumentParsing < Test::Unit::TestCase
601
+ def setup
602
+ @app = Rake::Application.new
603
+ end
604
+
605
+ def test_name_only
606
+ name, args = @app.parse_task_string("name")
607
+ assert_equal "name", name
608
+ assert_equal [], args
609
+ end
610
+
611
+ def test_empty_args
612
+ name, args = @app.parse_task_string("name[]")
613
+ assert_equal "name", name
614
+ assert_equal [], args
615
+ end
616
+
617
+ def test_one_argument
618
+ name, args = @app.parse_task_string("name[one]")
619
+ assert_equal "name", name
620
+ assert_equal ["one"], args
621
+ end
622
+
623
+ def test_two_arguments
624
+ name, args = @app.parse_task_string("name[one,two]")
625
+ assert_equal "name", name
626
+ assert_equal ["one", "two"], args
627
+ end
628
+
629
+ def test_can_handle_spaces_between_args
630
+ name, args = @app.parse_task_string("name[one, two,\tthree , \tfour]")
631
+ assert_equal "name", name
632
+ assert_equal ["one", "two", "three", "four"], args
633
+ end
634
+
635
+ def test_keeps_embedded_spaces
636
+ name, args = @app.parse_task_string("name[a one ana, two]")
637
+ assert_equal "name", name
638
+ assert_equal ["a one ana", "two"], args
639
+ end
640
+
641
+ end
642
+
643
+ class TestTaskArgumentParsing < Test::Unit::TestCase
644
+ include InEnvironment
645
+
646
+ def test_terminal_width_using_env
647
+ app = Rake::Application.new
648
+ in_environment('RAKE_COLUMNS' => '1234') do
649
+ assert_equal 1234, app.terminal_width
650
+ end
651
+ end
652
+
653
+ def test_terminal_width_using_stty
654
+ app = Rake::Application.new
655
+ flexmock(app,
656
+ :unix? => true,
657
+ :dynamic_width_stty => 1235,
658
+ :dynamic_width_tput => 0)
659
+ in_environment('RAKE_COLUMNS' => nil) do
660
+ assert_equal 1235, app.terminal_width
661
+ end
662
+ end
663
+
664
+ def test_terminal_width_using_tput
665
+ app = Rake::Application.new
666
+ flexmock(app,
667
+ :unix? => true,
668
+ :dynamic_width_stty => 0,
669
+ :dynamic_width_tput => 1236)
670
+ in_environment('RAKE_COLUMNS' => nil) do
671
+ assert_equal 1236, app.terminal_width
672
+ end
673
+ end
674
+
675
+ def test_terminal_width_using_hardcoded_80
676
+ app = Rake::Application.new
677
+ flexmock(app, :unix? => false)
678
+ in_environment('RAKE_COLUMNS' => nil) do
679
+ assert_equal 80, app.terminal_width
680
+ end
681
+ end
682
+
683
+ def test_terminal_width_with_failure
684
+ app = Rake::Application.new
685
+ flexmock(app).should_receive(:unix?).and_throw(RuntimeError)
686
+ in_environment('RAKE_COLUMNS' => nil) do
687
+ assert_equal 80, app.terminal_width
688
+ end
689
+ end
690
+ end