elliottcable-echoe 3.1.1

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