jimweirich-rake 0.8.1.5

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 (94) hide show
  1. data/CHANGES +364 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +242 -0
  4. data/Rakefile +413 -0
  5. data/TODO +20 -0
  6. data/bin/rake +31 -0
  7. data/doc/example/Rakefile1 +38 -0
  8. data/doc/example/Rakefile2 +35 -0
  9. data/doc/example/a.c +6 -0
  10. data/doc/example/b.c +6 -0
  11. data/doc/example/main.c +11 -0
  12. data/doc/glossary.rdoc +51 -0
  13. data/doc/jamis.rb +591 -0
  14. data/doc/proto_rake.rdoc +127 -0
  15. data/doc/rake.1.gz +0 -0
  16. data/doc/rakefile.rdoc +411 -0
  17. data/doc/rational.rdoc +151 -0
  18. data/doc/release_notes/rake-0.4.14.rdoc +23 -0
  19. data/doc/release_notes/rake-0.4.15.rdoc +35 -0
  20. data/doc/release_notes/rake-0.5.0.rdoc +53 -0
  21. data/doc/release_notes/rake-0.5.3.rdoc +78 -0
  22. data/doc/release_notes/rake-0.5.4.rdoc +46 -0
  23. data/doc/release_notes/rake-0.6.0.rdoc +141 -0
  24. data/doc/release_notes/rake-0.7.0.rdoc +119 -0
  25. data/doc/release_notes/rake-0.7.1.rdoc +59 -0
  26. data/doc/release_notes/rake-0.7.2.rdoc +121 -0
  27. data/doc/release_notes/rake-0.7.3.rdoc +47 -0
  28. data/doc/release_notes/rake-0.8.0.rdoc +114 -0
  29. data/install.rb +88 -0
  30. data/lib/rake/classic_namespace.rb +8 -0
  31. data/lib/rake/clean.rb +33 -0
  32. data/lib/rake/contrib/compositepublisher.rb +24 -0
  33. data/lib/rake/contrib/ftptools.rb +153 -0
  34. data/lib/rake/contrib/publisher.rb +75 -0
  35. data/lib/rake/contrib/rubyforgepublisher.rb +18 -0
  36. data/lib/rake/contrib/sshpublisher.rb +47 -0
  37. data/lib/rake/contrib/sys.rb +209 -0
  38. data/lib/rake/gempackagetask.rb +103 -0
  39. data/lib/rake/loaders/makefile.rb +40 -0
  40. data/lib/rake/packagetask.rb +184 -0
  41. data/lib/rake/rake_test_loader.rb +5 -0
  42. data/lib/rake/rdoctask.rb +147 -0
  43. data/lib/rake/ruby182_test_unit_fix.rb +23 -0
  44. data/lib/rake/runtest.rb +23 -0
  45. data/lib/rake/tasklib.rb +18 -0
  46. data/lib/rake/testtask.rb +161 -0
  47. data/lib/rake.rb +2312 -0
  48. data/test/capture_stdout.rb +26 -0
  49. data/test/contrib/testsys.rb +47 -0
  50. data/test/data/chains/Rakefile +15 -0
  51. data/test/data/default/Rakefile +19 -0
  52. data/test/data/dryrun/Rakefile +22 -0
  53. data/test/data/file_creation_task/Rakefile +30 -0
  54. data/test/data/imports/Rakefile +19 -0
  55. data/test/data/imports/deps.mf +1 -0
  56. data/test/data/multidesc/Rakefile +17 -0
  57. data/test/data/namespace/Rakefile +57 -0
  58. data/test/data/rakelib/test1.rb +3 -0
  59. data/test/data/rbext/rakefile.rb +3 -0
  60. data/test/data/sample.mf +9 -0
  61. data/test/data/statusreturn/Rakefile +8 -0
  62. data/test/data/unittest/Rakefile +1 -0
  63. data/test/filecreation.rb +32 -0
  64. data/test/functional.rb +15 -0
  65. data/test/rake_test_setup.rb +5 -0
  66. data/test/reqfile.rb +3 -0
  67. data/test/reqfile2.rb +3 -0
  68. data/test/session_functional.rb +267 -0
  69. data/test/shellcommand.rb +3 -0
  70. data/test/test_application.rb +504 -0
  71. data/test/test_clean.rb +14 -0
  72. data/test/test_definitions.rb +82 -0
  73. data/test/test_earlytime.rb +35 -0
  74. data/test/test_extension.rb +63 -0
  75. data/test/test_file_creation_task.rb +62 -0
  76. data/test/test_file_task.rb +139 -0
  77. data/test/test_filelist.rb +618 -0
  78. data/test/test_fileutils.rb +239 -0
  79. data/test/test_ftp.rb +59 -0
  80. data/test/test_invocation_chain.rb +75 -0
  81. data/test/test_makefile_loader.rb +23 -0
  82. data/test/test_multitask.rb +45 -0
  83. data/test/test_namespace.rb +36 -0
  84. data/test/test_package_task.rb +116 -0
  85. data/test/test_pathmap.rb +209 -0
  86. data/test/test_rake.rb +34 -0
  87. data/test/test_require.rb +33 -0
  88. data/test/test_rules.rb +347 -0
  89. data/test/test_task_arguments.rb +76 -0
  90. data/test/test_task_manager.rb +148 -0
  91. data/test/test_tasks.rb +372 -0
  92. data/test/test_test_task.rb +75 -0
  93. data/test/test_top_level_functions.rb +84 -0
  94. metadata +173 -0
@@ -0,0 +1,504 @@
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
+
14
+ TESTING_REQUIRE = [ ]
15
+
16
+ ######################################################################
17
+ class TestApplication < Test::Unit::TestCase
18
+ include CaptureStdout
19
+
20
+ def setup
21
+ @app = Rake::Application.new
22
+ @app.options.rakelib = []
23
+ end
24
+
25
+ def test_constant_warning
26
+ err = capture_stderr do @app.instance_eval { const_warning("Task") } end
27
+ assert_match(/warning/i, err)
28
+ assert_match(/deprecated/i, err)
29
+ assert_match(/Task/i, err)
30
+ end
31
+
32
+ def test_display_tasks
33
+ @app.options.show_task_pattern = //
34
+ @app.last_description = "COMMENT"
35
+ @app.define_task(Rake::Task, "t")
36
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
37
+ assert_match(/^rake t/, out)
38
+ assert_match(/# COMMENT/, out)
39
+ end
40
+
41
+ def test_display_tasks_with_long_comments
42
+ ENV['RAKE_COLUMNS'] = '80'
43
+ @app.options.show_task_pattern = //
44
+ @app.last_description = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
45
+ @app.define_task(Rake::Task, "t")
46
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
47
+ assert_match(/^rake t/, out)
48
+ assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
49
+ ensure
50
+ ENV['RAKE_COLUMNS'] = nil
51
+ end
52
+
53
+ def test_display_tasks_with_full_descriptions
54
+ @app.options.show_task_pattern = //
55
+ @app.options.full_description = true
56
+ @app.last_description = "COMMENT"
57
+ @app.define_task(Rake::Task, "t")
58
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
59
+ assert_match(/^rake t$/, out)
60
+ assert_match(/^ {4}COMMENT$/, out)
61
+ end
62
+
63
+ def test_finding_rakefile
64
+ assert @app.instance_eval { have_rakefile }
65
+ assert_equal "rakefile", @app.rakefile.downcase
66
+ end
67
+
68
+ def test_not_finding_rakefile
69
+ @app.instance_eval { @rakefiles = ['NEVER_FOUND'] }
70
+ assert( ! @app.instance_eval do have_rakefile end )
71
+ assert_nil @app.rakefile
72
+ end
73
+
74
+ def test_load_rakefile
75
+ original_dir = Dir.pwd
76
+ Dir.chdir("test/data/unittest")
77
+ @app.instance_eval do
78
+ handle_options
79
+ options.silent = true
80
+ load_rakefile
81
+ end
82
+ assert_equal "rakefile", @app.rakefile.downcase
83
+ assert_match(%r(unittest$), Dir.pwd)
84
+ ensure
85
+ Dir.chdir(original_dir)
86
+ end
87
+
88
+ def test_load_rakefile_from_subdir
89
+ original_dir = Dir.pwd
90
+ Dir.chdir("test/data/unittest/subdir")
91
+ @app.instance_eval do
92
+ handle_options
93
+ options.silent = true
94
+ load_rakefile
95
+ end
96
+ assert_equal "rakefile", @app.rakefile.downcase
97
+ assert_match(%r(unittest$), Dir.pwd)
98
+ ensure
99
+ Dir.chdir(original_dir)
100
+ end
101
+
102
+ def test_load_rakefile_not_found
103
+ original_dir = Dir.pwd
104
+ Dir.chdir("/")
105
+ @app.instance_eval do
106
+ handle_options
107
+ options.silent = true
108
+ end
109
+ ex = assert_raise(RuntimeError) do
110
+ @app.instance_eval do raw_load_rakefile end
111
+ end
112
+ assert_match(/no rakefile found/i, ex.message)
113
+ ensure
114
+ Dir.chdir(original_dir)
115
+ end
116
+
117
+ def test_not_caring_about_finding_rakefile
118
+ @app.instance_eval do @rakefiles = [''] end
119
+ assert(@app.instance_eval do have_rakefile end)
120
+ assert_equal '', @app.rakefile
121
+ end
122
+
123
+ def test_loading_imports
124
+ mock = flexmock("loader")
125
+ mock.should_receive(:load).with("x.dummy").once
126
+ @app.instance_eval do
127
+ add_loader("dummy", mock)
128
+ add_import("x.dummy")
129
+ load_imports
130
+ end
131
+ end
132
+
133
+ def test_building_imported_files_on_demand
134
+ mock = flexmock("loader")
135
+ mock.should_receive(:load).with("x.dummy").once
136
+ mock.should_receive(:make_dummy).with_no_args.once
137
+ @app.instance_eval do
138
+ intern(Rake::Task, "x.dummy").enhance do mock.make_dummy end
139
+ add_loader("dummy", mock)
140
+ add_import("x.dummy")
141
+ load_imports
142
+ end
143
+ end
144
+
145
+ def test_good_run
146
+ ran = false
147
+ ARGV.clear
148
+ ARGV << '--rakelib=""'
149
+ @app.options.silent = true
150
+ @app.instance_eval do
151
+ intern(Rake::Task, "default").enhance { ran = true }
152
+ end
153
+ @app.run
154
+ assert ran
155
+ end
156
+
157
+ def test_display_task_run
158
+ ran = false
159
+ ARGV.clear
160
+ ARGV << '-f' << '-s' << '--tasks' << '--rakelib=""'
161
+ @app.last_description = "COMMENT"
162
+ @app.define_task(Rake::Task, "default")
163
+ out = capture_stdout { @app.run }
164
+ assert @app.options.show_tasks
165
+ assert ! ran
166
+ assert_match(/rake default/, out)
167
+ assert_match(/# COMMENT/, out)
168
+ end
169
+
170
+ def test_display_prereqs
171
+ ran = false
172
+ ARGV.clear
173
+ ARGV << '-f' << '-s' << '--prereqs' << '--rakelib=""'
174
+ @app.last_description = "COMMENT"
175
+ t = @app.define_task(Rake::Task, "default")
176
+ t.enhance([:a, :b])
177
+ @app.define_task(Rake::Task, "a")
178
+ @app.define_task(Rake::Task, "b")
179
+ out = capture_stdout { @app.run }
180
+ assert @app.options.show_prereqs
181
+ assert ! ran
182
+ assert_match(/rake a$/, out)
183
+ assert_match(/rake b$/, out)
184
+ assert_match(/rake default\n( *(a|b)\n){2}/m, out)
185
+ end
186
+
187
+ def test_bad_run
188
+ @app.intern(Rake::Task, "default").enhance { fail }
189
+ ARGV.clear
190
+ ARGV << '-f' << '-s' << '--rakelib=""'
191
+ assert_raise(SystemExit) {
192
+ err = capture_stderr { @app.run }
193
+ assert_match(/see full trace/, err)
194
+ }
195
+ ensure
196
+ ARGV.clear
197
+ end
198
+
199
+ def test_bad_run_with_trace
200
+ @app.intern(Rake::Task, "default").enhance { fail }
201
+ ARGV.clear
202
+ ARGV << '-f' << '-s' << '-t'
203
+ assert_raise(SystemExit) {
204
+ err = capture_stderr { capture_stdout { @app.run } }
205
+ assert_no_match(/see full trace/, err)
206
+ }
207
+ ensure
208
+ ARGV.clear
209
+ end
210
+
211
+ def test_run_with_bad_options
212
+ @app.intern(Rake::Task, "default").enhance { fail }
213
+ ARGV.clear
214
+ ARGV << '-f' << '-s' << '--xyzzy'
215
+ assert_raise(SystemExit) {
216
+ err = capture_stderr { capture_stdout { @app.run } }
217
+ }
218
+ ensure
219
+ ARGV.clear
220
+ end
221
+
222
+ end
223
+
224
+
225
+ ######################################################################
226
+ class TestApplicationOptions < Test::Unit::TestCase
227
+ include CaptureStdout
228
+
229
+ def setup
230
+ clear_argv
231
+ RakeFileUtils.verbose_flag = false
232
+ RakeFileUtils.nowrite_flag = false
233
+ end
234
+
235
+ def teardown
236
+ clear_argv
237
+ RakeFileUtils.verbose_flag = false
238
+ RakeFileUtils.nowrite_flag = false
239
+ end
240
+
241
+ def clear_argv
242
+ while ! ARGV.empty?
243
+ ARGV.pop
244
+ end
245
+ end
246
+
247
+ def test_default_options
248
+ opts = command_line
249
+ assert_nil opts.show_task_pattern
250
+ assert_nil opts.dryrun
251
+ assert_nil opts.trace
252
+ assert_nil opts.nosearch
253
+ assert_nil opts.silent
254
+ assert_nil opts.show_prereqs
255
+ assert_nil opts.show_tasks
256
+ assert_nil opts.classic_namespace
257
+ assert_equal ['rakelib'], opts.rakelib
258
+ assert ! RakeFileUtils.verbose_flag
259
+ assert ! RakeFileUtils.nowrite_flag
260
+ end
261
+
262
+ def test_bad_options
263
+ assert_raise OptionParser::InvalidOption do
264
+ capture_stderr do
265
+ flags('--bad', '-t') do |opts|
266
+ end
267
+ end
268
+ end
269
+ end
270
+
271
+ def test_trace_option
272
+ flags('--trace', '-t') do |opts|
273
+ assert opts.trace
274
+ assert RakeFileUtils.verbose_flag
275
+ assert ! RakeFileUtils.nowrite_flag
276
+ end
277
+ end
278
+
279
+ def test_dry_run
280
+ flags('--dry-run', '-n') do |opts|
281
+ assert opts.dryrun
282
+ assert opts.trace
283
+ assert RakeFileUtils.verbose_flag
284
+ assert RakeFileUtils.nowrite_flag
285
+ end
286
+ end
287
+
288
+ def test_help
289
+ flags('--help', '-H', '-h') do |opts|
290
+ assert_match(/\Arake/, @out)
291
+ assert_match(/\boptions\b/, @out)
292
+ assert_match(/\btargets\b/, @out)
293
+ assert_equal :exit, @exit
294
+ assert_equal :exit, @exit
295
+ end
296
+ end
297
+
298
+ def test_describe
299
+ flags('--describe') do |opts|
300
+ assert opts.full_description
301
+ assert opts.show_tasks
302
+ assert_equal(//.to_s, opts.show_task_pattern.to_s)
303
+ end
304
+ end
305
+
306
+ def test_libdir
307
+ flags(['--libdir', 'xx'], ['-I', 'xx'], ['-Ixx']) do |opts|
308
+ $:.include?('xx')
309
+ end
310
+ ensure
311
+ $:.delete('xx')
312
+ end
313
+
314
+ def test_nosearch
315
+ flags('--nosearch', '-N') do |opts|
316
+ assert opts.nosearch
317
+ end
318
+ end
319
+
320
+ def test_show_prereqs
321
+ flags('--prereqs', '-P') do |opts|
322
+ assert opts.show_prereqs
323
+ end
324
+ end
325
+
326
+ def test_quiet
327
+ flags('--quiet', '-q') do |opts|
328
+ assert ! RakeFileUtils.verbose_flag
329
+ assert ! opts.silent
330
+ end
331
+ end
332
+
333
+ def test_silent
334
+ flags('--silent', '-s') do |opts|
335
+ assert ! RakeFileUtils.verbose_flag
336
+ assert opts.silent
337
+ end
338
+ end
339
+
340
+ def test_rakefile
341
+ flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
342
+ assert_equal ['RF'], @app.instance_eval { @rakefiles }
343
+ end
344
+ end
345
+
346
+ def test_rakelib
347
+ flags(['--rakelibdir', 'A:B:C'], ['--rakelibdir=A:B:C'], ['-R', 'A:B:C'], ['-RA:B:C']) do |opts|
348
+ assert_equal ['A', 'B', 'C'], opts.rakelib
349
+ end
350
+ end
351
+
352
+ def test_require
353
+ flags(['--require', 'test/reqfile'], '-rtest/reqfile2', '-rtest/reqfile3') do |opts|
354
+ end
355
+ assert TESTING_REQUIRE.include?(1)
356
+ assert TESTING_REQUIRE.include?(2)
357
+ assert TESTING_REQUIRE.include?(3)
358
+ assert_equal 3, TESTING_REQUIRE.size
359
+ end
360
+
361
+ def test_missing_require
362
+ ex = assert_raises(LoadError) do
363
+ flags(['--require', 'test/missing']) do |opts|
364
+ end
365
+ end
366
+ assert_match(/no such file/, ex.message)
367
+ assert_match(/test\/missing/, ex.message)
368
+ end
369
+
370
+ def test_tasks
371
+ flags('--tasks', '-T') do |opts|
372
+ assert opts.show_tasks
373
+ assert_equal(//.to_s, opts.show_task_pattern.to_s)
374
+ end
375
+ flags(['--tasks', 'xyz'], ['-Txyz']) do |opts|
376
+ assert opts.show_tasks
377
+ assert_equal(/xyz/, opts.show_task_pattern)
378
+ end
379
+ end
380
+
381
+ def test_verbose
382
+ flags('--verbose', '-V') do |opts|
383
+ assert RakeFileUtils.verbose_flag
384
+ assert ! opts.silent
385
+ end
386
+ end
387
+
388
+ def test_version
389
+ flags('--version', '-V') do |opts|
390
+ assert_match(/\bversion\b/, @out)
391
+ assert_match(/\b#{RAKEVERSION}\b/, @out)
392
+ assert_equal :exit, @exit
393
+ end
394
+ end
395
+
396
+ def test_classic_namespace
397
+ flags(['--classic-namespace'], ['-C', '-T', '-P', '-n', '-s', '-t']) do |opts|
398
+ assert opts.classic_namespace
399
+ assert_equal opts.show_tasks, $show_tasks
400
+ assert_equal opts.show_prereqs, $show_prereqs
401
+ assert_equal opts.trace, $trace
402
+ assert_equal opts.dryrun, $dryrun
403
+ assert_equal opts.silent, $silent
404
+ end
405
+ end
406
+
407
+ def test_bad_option
408
+ capture_stderr do
409
+ ex = assert_raise(OptionParser::InvalidOption) do
410
+ flags('--bad-option')
411
+ end
412
+ if ex.message =~ /^While/ # Ruby 1.9 error message
413
+ assert_match(/while parsing/i, ex.message)
414
+ else # Ruby 1.8 error message
415
+ assert_match(/(invalid|unrecognized) option/i, ex.message)
416
+ assert_match(/--bad-option/, ex.message)
417
+ end
418
+ end
419
+ end
420
+
421
+ def test_task_collection
422
+ command_line("a", "b")
423
+ assert_equal ["a", "b"], @tasks.sort
424
+ end
425
+
426
+ def test_default_task_collection
427
+ command_line()
428
+ assert_equal ["default"], @tasks
429
+ end
430
+
431
+ def test_environment_definition
432
+ ENV.delete('TESTKEY')
433
+ command_line("a", "TESTKEY=12")
434
+ assert_equal ["a"], @tasks.sort
435
+ assert '12', ENV['TESTKEY']
436
+ end
437
+
438
+ private
439
+
440
+ def flags(*sets)
441
+ sets.each do |set|
442
+ @out = capture_stdout {
443
+ @exit = catch(:system_exit) { opts = command_line(*set) }
444
+ }
445
+ yield(@app.options) if block_given?
446
+ end
447
+ end
448
+
449
+ def command_line(*options)
450
+ options.each do |opt| ARGV << opt end
451
+ @app = Rake::Application.new
452
+ def @app.exit(*args)
453
+ throw :system_exit, :exit
454
+ end
455
+ @app.instance_eval do
456
+ collect_tasks handle_options
457
+ end
458
+ @tasks = @app.top_level_tasks
459
+ @app.options
460
+ end
461
+ end
462
+
463
+ class TestTaskArgumentParsing < Test::Unit::TestCase
464
+ def setup
465
+ @app = Rake::Application.new
466
+ end
467
+
468
+ def test_name_only
469
+ name, args = @app.parse_task_string("name")
470
+ assert_equal "name", name
471
+ assert_equal [], args
472
+ end
473
+
474
+ def test_empty_args
475
+ name, args = @app.parse_task_string("name[]")
476
+ assert_equal "name", name
477
+ assert_equal [], args
478
+ end
479
+
480
+ def test_one_argument
481
+ name, args = @app.parse_task_string("name[one]")
482
+ assert_equal "name", name
483
+ assert_equal ["one"], args
484
+ end
485
+
486
+ def test_two_arguments
487
+ name, args = @app.parse_task_string("name[one,two]")
488
+ assert_equal "name", name
489
+ assert_equal ["one", "two"], args
490
+ end
491
+
492
+ def test_can_handle_spaces_between_args
493
+ name, args = @app.parse_task_string("name[one, two,\tthree , \tfour]")
494
+ assert_equal "name", name
495
+ assert_equal ["one", "two", "three", "four"], args
496
+ end
497
+
498
+ def test_keeps_embedded_spaces
499
+ name, args = @app.parse_task_string("name[a one ana, two]")
500
+ assert_equal "name", name
501
+ assert_equal ["a one ana", "two"], args
502
+ end
503
+
504
+ 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
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'fileutils'
5
+ require 'rake'
6
+ require 'test/filecreation'
7
+
8
+ ######################################################################
9
+ class TestDefinitions < Test::Unit::TestCase
10
+ include Rake
11
+ EXISTINGFILE = "testdata/existing"
12
+
13
+ def setup
14
+ Task.clear
15
+ end
16
+
17
+ def test_task
18
+ done = false
19
+ task :one => [:two] do done = true end
20
+ task :two
21
+ task :three => [:one, :two]
22
+ check_tasks(:one, :two, :three)
23
+ assert done, "Should be done"
24
+ end
25
+
26
+ def test_file_task
27
+ done = false
28
+ file "testdata/one" => "testdata/two" do done = true end
29
+ file "testdata/two"
30
+ file "testdata/three" => ["testdata/one", "testdata/two"]
31
+ check_tasks("testdata/one", "testdata/two", "testdata/three")
32
+ assert done, "Should be done"
33
+ end
34
+
35
+ def check_tasks(n1, n2, n3)
36
+ t = Task[n1]
37
+ assert Task === t, "Should be a Task"
38
+ assert_equal n1.to_s, t.name
39
+ assert_equal [n2.to_s], t.prerequisites.collect{|n| n.to_s}
40
+ t.invoke
41
+ t2 = Task[n2]
42
+ assert_equal FileList[], t2.prerequisites
43
+ t3 = Task[n3]
44
+ assert_equal [n1.to_s, n2.to_s], t3.prerequisites.collect{|n|n.to_s}
45
+ end
46
+
47
+ def test_incremental_definitions
48
+ runs = []
49
+ task :t1 => [:t2] do runs << "A"; 4321 end
50
+ task :t1 => [:t3] do runs << "B"; 1234 end
51
+ task :t1 => [:t3]
52
+ task :t2
53
+ task :t3
54
+ Task[:t1].invoke
55
+ assert_equal ["A", "B"], runs
56
+ assert_equal ["t2", "t3"], Task[:t1].prerequisites
57
+ end
58
+
59
+ def test_missing_dependencies
60
+ task :x => ["testdata/missing"]
61
+ assert_raises(RuntimeError) { Task[:x].invoke }
62
+ end
63
+
64
+ def test_implicit_file_dependencies
65
+ runs = []
66
+ create_existing_file
67
+ task :y => [EXISTINGFILE] do |t| runs << t.name end
68
+ Task[:y].invoke
69
+ assert_equal runs, ['y']
70
+ end
71
+
72
+ private # ----------------------------------------------------------
73
+
74
+ def create_existing_file
75
+ Dir.mkdir File.dirname(EXISTINGFILE) unless
76
+ File.exist?(File.dirname(EXISTINGFILE))
77
+ open(EXISTINGFILE, "w") do |f| f.puts "HI" end unless
78
+ File.exist?(EXISTINGFILE)
79
+ end
80
+
81
+ end
82
+
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake'
5
+
6
+ class TestEarlyTime < Test::Unit::TestCase
7
+ def test_create
8
+ early = Rake::EarlyTime.instance
9
+ time = Time.mktime(1920, 1, 1, 0, 0, 0)
10
+ assert early <= Time.now
11
+ assert early < Time.now
12
+ assert early != Time.now
13
+ assert Time.now > early
14
+ assert Time.now >= early
15
+ assert Time.now != early
16
+ end
17
+
18
+ def test_equality
19
+ early = Rake::EarlyTime.instance
20
+ assert_equal early, early, "two early times should be equal"
21
+ end
22
+
23
+ def test_original_time_compare_is_not_messed_up
24
+ t1 = Time.mktime(1920, 1, 1, 0, 0, 0)
25
+ t2 = Time.now
26
+ assert t1 < t2
27
+ assert t2 > t1
28
+ assert t1 == t1
29
+ assert t2 == t2
30
+ end
31
+
32
+ def test_to_s
33
+ assert_equal "<EARLY TIME>", Rake::EARLY.to_s
34
+ end
35
+ end
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake'
5
+ require 'stringio'
6
+
7
+ ######################################################################
8
+ class TestExtension < Test::Unit::TestCase
9
+
10
+ module Redirect
11
+ def error_redirect
12
+ old_err = $stderr
13
+ result = StringIO.new
14
+ $stderr = result
15
+ yield
16
+ result
17
+ ensure
18
+ $stderr = old_err
19
+ end
20
+ end
21
+
22
+ class Sample
23
+ extend Redirect
24
+
25
+ def duplicate_method
26
+ :original
27
+ end
28
+
29
+ OK_ERRS = error_redirect do
30
+ rake_extension("a") do
31
+ def ok_method
32
+ end
33
+ end
34
+ end
35
+
36
+
37
+ DUP_ERRS = error_redirect do
38
+ rake_extension("duplicate_method") do
39
+ def duplicate_method
40
+ :override
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ def test_methods_actually_exist
47
+ sample = Sample.new
48
+ sample.ok_method
49
+ sample.duplicate_method
50
+ end
51
+
52
+ def test_no_warning_when_defining_ok_method
53
+ assert_equal "", Sample::OK_ERRS.string
54
+ end
55
+
56
+ def test_extension_complains_when_a_method_that_is_present
57
+ assert_match(/warning:/i, Sample::DUP_ERRS.string)
58
+ assert_match(/already exists/i, Sample::DUP_ERRS.string)
59
+ assert_match(/duplicate_method/i, Sample::DUP_ERRS.string)
60
+ assert_equal :original, Sample.new.duplicate_method
61
+ end
62
+
63
+ end