rake 10.1.0.beta.3 → 10.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rake might be problematic. Click here for more details.

@@ -0,0 +1,444 @@
1
+ module RakefileDefinitions
2
+ include FileUtils
3
+
4
+ def rakefile_access
5
+ rakefile <<-ACCESS
6
+ TOP_LEVEL_CONSTANT = 0
7
+
8
+ def a_top_level_function
9
+ end
10
+
11
+ task :default => [:work, :obj, :const]
12
+
13
+ task :work do
14
+ begin
15
+ a_top_level_function
16
+ puts "GOOD:M Top level methods can be called in tasks"
17
+ rescue NameError => ex
18
+ puts "BAD:M Top level methods can not be called in tasks"
19
+ end
20
+ end
21
+
22
+ # TODO: remove `disabled_' when DeprecatedObjectDSL removed
23
+ task :obj
24
+ task :disabled_obj do
25
+ begin
26
+ Object.new.instance_eval { task :xyzzy }
27
+ puts "BAD:D Rake DSL are polluting objects"
28
+ rescue StandardError => ex
29
+ puts "GOOD:D Rake DSL are not polluting objects"
30
+ end
31
+ end
32
+
33
+ task :const do
34
+ begin
35
+ TOP_LEVEL_CONSTANT
36
+ puts "GOOD:C Top level constants are available in tasks"
37
+ rescue StandardError => ex
38
+ puts "BAD:C Top level constants are NOT available in tasks"
39
+ end
40
+ end
41
+ ACCESS
42
+ end
43
+
44
+ def rakefile_chains
45
+ rakefile <<-DEFAULT
46
+ task :default => "play.app"
47
+
48
+ file "play.scpt" => "base" do |t|
49
+ cp t.prerequisites.first, t.name
50
+ end
51
+
52
+ rule ".app" => ".scpt" do |t|
53
+ cp t.source, t.name
54
+ end
55
+
56
+ file 'base' do
57
+ touch 'base'
58
+ end
59
+ DEFAULT
60
+ end
61
+
62
+ def rakefile_comments
63
+ rakefile <<-COMMENTS
64
+ # comment for t1
65
+ task :t1 do
66
+ end
67
+
68
+ # no comment or task because there's a blank line
69
+
70
+ task :t2 do
71
+ end
72
+
73
+ desc "override comment for t3"
74
+ # this is not the description
75
+ multitask :t3 do
76
+ end
77
+
78
+ # this is not the description
79
+ desc "override comment for t4"
80
+ file :t4 do
81
+ end
82
+ COMMENTS
83
+ end
84
+
85
+ def rakefile_default
86
+ rakefile <<-DEFAULT
87
+ if ENV['TESTTOPSCOPE']
88
+ puts "TOPSCOPE"
89
+ end
90
+
91
+ task :default do
92
+ puts "DEFAULT"
93
+ end
94
+
95
+ task :other => [:default] do
96
+ puts "OTHER"
97
+ end
98
+
99
+ task :task_scope do
100
+ if ENV['TESTTASKSCOPE']
101
+ puts "TASKSCOPE"
102
+ end
103
+ end
104
+ DEFAULT
105
+ end
106
+
107
+ def rakefile_dryrun
108
+ rakefile <<-DRYRUN
109
+ task :default => ["temp_main"]
110
+
111
+ file "temp_main" => [:all_apps] do touch "temp_main" end
112
+
113
+ task :all_apps => [:one, :two]
114
+ task :one => ["temp_one"]
115
+ task :two => ["temp_two"]
116
+
117
+ file "temp_one" do |t|
118
+ touch "temp_one"
119
+ end
120
+ file "temp_two" do |t|
121
+ touch "temp_two"
122
+ end
123
+
124
+ task :clean do
125
+ ["temp_one", "temp_two", "temp_main"].each do |file|
126
+ rm_f file
127
+ end
128
+ end
129
+ DRYRUN
130
+
131
+ FileUtils.touch 'temp_main'
132
+ FileUtils.touch 'temp_two'
133
+ end
134
+
135
+ def rakefile_extra
136
+ rakefile 'task :default'
137
+
138
+ FileUtils.mkdir_p 'rakelib'
139
+
140
+ open File.join('rakelib', 'extra.rake'), 'w' do |io|
141
+ io << <<-EXTRA_RAKE
142
+ # Added for testing
143
+
144
+ namespace :extra do
145
+ desc "An Extra Task"
146
+ task :extra do
147
+ puts "Read all about it"
148
+ end
149
+ end
150
+ EXTRA_RAKE
151
+ end
152
+ end
153
+
154
+ def rakefile_file_creation
155
+ rakefile <<-'FILE_CREATION'
156
+ N = 2
157
+
158
+ task :default => :run
159
+
160
+ BUILD_DIR = 'build'
161
+ task :clean do
162
+ rm_rf 'build'
163
+ rm_rf 'src'
164
+ end
165
+
166
+ task :run
167
+
168
+ TARGET_DIR = 'build/copies'
169
+
170
+ FileList['src/*'].each do |src|
171
+ directory TARGET_DIR
172
+ target = File.join TARGET_DIR, File.basename(src)
173
+ file target => [src, TARGET_DIR] do
174
+ cp src, target
175
+ end
176
+ task :run => target
177
+ end
178
+
179
+ task :prep => :clean do
180
+ mkdir_p 'src'
181
+ N.times do |n|
182
+ touch "src/foo#{n}"
183
+ end
184
+ end
185
+ FILE_CREATION
186
+ end
187
+
188
+ def rakefile_imports
189
+ rakefile <<-IMPORTS
190
+ require 'rake/loaders/makefile'
191
+
192
+ task :default
193
+
194
+ task :other do
195
+ puts "OTHER"
196
+ end
197
+
198
+ file "dynamic_deps" do |t|
199
+ open(t.name, "w") do |f| f.puts "puts 'DYNAMIC'" end
200
+ end
201
+
202
+ import "dynamic_deps"
203
+ import "static_deps"
204
+ import "static_deps"
205
+ import "deps.mf"
206
+ puts "FIRST"
207
+ IMPORTS
208
+
209
+ open 'deps.mf', 'w' do |io|
210
+ io << <<-DEPS
211
+ default: other
212
+ DEPS
213
+ end
214
+
215
+ open "static_deps", "w" do |f|
216
+ f.puts 'puts "STATIC"'
217
+ end
218
+ end
219
+
220
+ def rakefile_multidesc
221
+ rakefile <<-MULTIDESC
222
+ task :b
223
+
224
+ desc "A"
225
+ task :a
226
+
227
+ desc "B"
228
+ task :b
229
+
230
+ desc "A2"
231
+ task :a
232
+
233
+ task :c
234
+
235
+ desc "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
236
+ task :d
237
+ MULTIDESC
238
+ end
239
+
240
+ def rakefile_namespace
241
+ rakefile <<-NAMESPACE
242
+ desc "copy"
243
+ task :copy do
244
+ puts "COPY"
245
+ end
246
+
247
+ namespace "nest" do
248
+ desc "nest copy"
249
+ task :copy do
250
+ puts "NEST COPY"
251
+ end
252
+ task :xx => :copy
253
+ end
254
+
255
+ anon_ns = namespace do
256
+ desc "anonymous copy task"
257
+ task :copy do
258
+ puts "ANON COPY"
259
+ end
260
+ end
261
+
262
+ desc "Top level task to run the anonymous version of copy"
263
+ task :anon => anon_ns[:copy]
264
+
265
+ namespace "very" do
266
+ namespace "nested" do
267
+ task "run" => "rake:copy"
268
+ end
269
+ end
270
+
271
+ namespace "a" do
272
+ desc "Run task in the 'a' namespace"
273
+ task "run" do
274
+ puts "IN A"
275
+ end
276
+ end
277
+
278
+ namespace "b" do
279
+ desc "Run task in the 'b' namespace"
280
+ task "run" => "a:run" do
281
+ puts "IN B"
282
+ end
283
+ end
284
+
285
+ namespace "file1" do
286
+ file "xyz.rb" do
287
+ puts "XYZ1"
288
+ end
289
+ end
290
+
291
+ namespace "file2" do
292
+ file "xyz.rb" do
293
+ puts "XYZ2"
294
+ end
295
+ end
296
+
297
+ namespace "scopedep" do
298
+ task :prepare do
299
+ touch "scopedep.rb"
300
+ puts "PREPARE"
301
+ end
302
+ file "scopedep.rb" => [:prepare] do
303
+ puts "SCOPEDEP"
304
+ end
305
+ end
306
+ NAMESPACE
307
+ end
308
+
309
+ def rakefile_nosearch
310
+ FileUtils.touch 'dummy'
311
+ end
312
+
313
+ def rakefile_rakelib
314
+ FileUtils.mkdir_p 'rakelib'
315
+
316
+ Dir.chdir 'rakelib' do
317
+ open 'test1.rb', 'w' do |io|
318
+ io << <<-TEST1
319
+ task :default do
320
+ puts "TEST1"
321
+ end
322
+ TEST1
323
+ end
324
+
325
+ open 'test2.rake', 'w' do |io|
326
+ io << <<-TEST1
327
+ task :default do
328
+ puts "TEST2"
329
+ end
330
+ TEST1
331
+ end
332
+ end
333
+ end
334
+
335
+ def rakefile_rbext
336
+ open 'rakefile.rb', 'w' do |io|
337
+ io << 'task :default do puts "OK" end'
338
+ end
339
+ end
340
+
341
+ def rakefile_unittest
342
+ rakefile '# Empty Rakefile for Unit Test'
343
+
344
+ readme = File.join 'subdir', 'README'
345
+ FileUtils.mkdir_p File.dirname readme
346
+
347
+ FileUtils.touch readme
348
+ end
349
+
350
+ def rakefile_verbose
351
+ rakefile <<-VERBOSE
352
+ task :standalone_verbose_true do
353
+ verbose true
354
+ sh "#{RUBY} -e '0'"
355
+ end
356
+
357
+ task :standalone_verbose_false do
358
+ verbose false
359
+ sh "#{RUBY} -e '0'"
360
+ end
361
+
362
+ task :inline_verbose_default do
363
+ sh "#{RUBY} -e '0'"
364
+ end
365
+
366
+ task :inline_verbose_false do
367
+ sh "#{RUBY} -e '0'", :verbose => false
368
+ end
369
+
370
+ task :inline_verbose_true do
371
+ sh "#{RUBY} -e '0'", :verbose => true
372
+ end
373
+
374
+ task :block_verbose_true do
375
+ verbose(true) do
376
+ sh "#{RUBY} -e '0'"
377
+ end
378
+ end
379
+
380
+ task :block_verbose_false do
381
+ verbose(false) do
382
+ sh "#{RUBY} -e '0'"
383
+ end
384
+ end
385
+ VERBOSE
386
+ end
387
+
388
+ def rakefile_test_signal
389
+ rakefile <<-TEST_SIGNAL
390
+ require 'rake/testtask'
391
+
392
+ Rake::TestTask.new(:a) do |t|
393
+ t.test_files = ['a_test.rb']
394
+ end
395
+
396
+ Rake::TestTask.new(:b) do |t|
397
+ t.test_files = ['b_test.rb']
398
+ end
399
+
400
+ task :test do
401
+ Rake::Task[:a].invoke
402
+ Rake::Task[:b].invoke
403
+ end
404
+
405
+ task :default => :test
406
+ TEST_SIGNAL
407
+ open 'a_test.rb', 'w' do |io|
408
+ io << 'puts "ATEST"' << "\n"
409
+ io << '$stdout.flush' << "\n"
410
+ io << 'Process.kill("TERM", $$)' << "\n"
411
+ end
412
+ open 'b_test.rb', 'w' do |io|
413
+ io << 'puts "BTEST"' << "\n"
414
+ io << '$stdout.flush' << "\n"
415
+ end
416
+ end
417
+
418
+ def rakefile_failing_test_task
419
+ rakefile <<-TEST_TASK
420
+ require 'rake/testtask'
421
+
422
+ task :default => :test
423
+ Rake::TestTask.new(:test) do |t|
424
+ t.test_files = ['a_test.rb']
425
+ end
426
+ TEST_TASK
427
+ open 'a_test.rb', 'w' do |io|
428
+ io << "require 'minitest/autorun'\n"
429
+ io << "class ExitTaskTest < MiniTest::Unit::TestCase\n"
430
+ io << " def test_exit\n"
431
+ io << " assert false, 'this should fail'\n"
432
+ io << " end\n"
433
+ io << "end\n"
434
+ end
435
+ end
436
+
437
+ def rakefile_stand_alone_filelist
438
+ open 'stand_alone_filelist.rb', 'w' do |io|
439
+ io << "require 'rake/file_list'\n"
440
+ io << "FL = Rake::FileList['*.rb']\n"
441
+ io << "puts FL\n"
442
+ end
443
+ end
444
+ end
@@ -0,0 +1,33 @@
1
+ module RubyRunner
2
+ include FileUtils
3
+
4
+ # Run a shell Ruby command with command line options (using the
5
+ # default test options). Output is captured in @out and @err
6
+ def ruby(*option_list)
7
+ run_ruby(@ruby_options + option_list)
8
+ end
9
+
10
+ # Run a command line rake with the give rake options. Default
11
+ # command line ruby options are included. Output is captured in
12
+ # @out and @err
13
+ def rake(*rake_options)
14
+ run_ruby @ruby_options + [@rake_exec] + rake_options
15
+ end
16
+
17
+ # Low level ruby command runner ...
18
+ def run_ruby(option_list)
19
+ puts "COMMAND: [#{RUBY} #{option_list.join ' '}]" if @verbose
20
+
21
+ inn, out, err, wait = Open3.popen3(RUBY, *option_list)
22
+ inn.close
23
+
24
+ @exit = wait ? wait.value : $?
25
+ @out = out.read
26
+ @err = err.read
27
+
28
+ puts "OUTPUT: [#{@out}]" if @verbose
29
+ puts "ERROR: [#{@err}]" if @verbose
30
+ puts "EXIT: [#{@exit.inspect}]" if @verbose
31
+ puts "PWD: [#{Dir.pwd}]" if @verbose
32
+ end
33
+ end