~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/rake/test_rake_functional.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require File.expand_path('../helper', __FILE__)
 
2
require 'fileutils'
 
3
require 'open3'
 
4
 
 
5
class TestRakeFunctional < Rake::TestCase
 
6
 
 
7
  def setup
 
8
    @rake_path = File.expand_path("../../../bin/rake", __FILE__)
 
9
    lib_path = File.expand_path("../../../lib", __FILE__)
 
10
    @ruby_options = ["-I#{lib_path}", "-I."]
 
11
    @verbose = ENV['VERBOSE']
 
12
 
 
13
    if @verbose
 
14
      puts
 
15
      puts
 
16
      puts '-' * 80
 
17
      puts @__name__
 
18
      puts '-' * 80
 
19
    end
 
20
 
 
21
    super
 
22
  end
 
23
 
 
24
  def test_rake_default
 
25
    rakefile_default
 
26
 
 
27
    rake
 
28
 
 
29
    assert_match(/^DEFAULT$/, @out)
 
30
  end
 
31
 
 
32
  def test_rake_error_on_bad_task
 
33
    rakefile_default
 
34
 
 
35
    rake '-t', 'xyz'
 
36
 
 
37
    assert_match(/rake aborted/, @err)
 
38
  end
 
39
 
 
40
  def test_env_available_at_top_scope
 
41
    rakefile_default
 
42
 
 
43
    rake "TESTTOPSCOPE=1"
 
44
 
 
45
    assert_match(/^TOPSCOPE$/, @out)
 
46
  end
 
47
 
 
48
  def test_env_available_at_task_scope
 
49
    rakefile_default
 
50
 
 
51
    rake 'TESTTASKSCOPE=1', 'task_scope'
 
52
 
 
53
    assert_match(/^TASKSCOPE$/, @out)
 
54
  end
 
55
 
 
56
  def test_multi_desc
 
57
    ENV['RAKE_COLUMNS'] = '80'
 
58
    rakefile_multidesc
 
59
 
 
60
    rake "-T"
 
61
 
 
62
    assert_match %r{^rake a *# A / A2 *$}, @out
 
63
    assert_match %r{^rake b *# B *$}, @out
 
64
    refute_match %r{^rake c}, @out
 
65
    assert_match %r{^rake d *# x{65}\.\.\.$}, @out
 
66
  end
 
67
 
 
68
  def test_long_description
 
69
    rakefile_multidesc
 
70
 
 
71
    rake "--describe"
 
72
 
 
73
    assert_match %r{^rake a\n *A / A2 *$}m, @out
 
74
    assert_match %r{^rake b\n *B *$}m, @out
 
75
    assert_match %r{^rake d\n *x{80}}m, @out
 
76
    refute_match %r{^rake c\n}m, @out
 
77
  end
 
78
 
 
79
  def test_proper_namespace_access
 
80
    rakefile_access
 
81
 
 
82
    rake
 
83
 
 
84
    refute_match %r{^BAD:}, @out
 
85
  end
 
86
 
 
87
  def test_rbext
 
88
    rakefile_rbext
 
89
 
 
90
    rake "-N"
 
91
 
 
92
    assert_match %r{^OK$}, @out
 
93
  end
 
94
 
 
95
  def test_system
 
96
    rake_system_dir
 
97
 
 
98
    rake '-g', "sys1"
 
99
 
 
100
    assert_match %r{^SYS1}, @out
 
101
  end
 
102
 
 
103
  def test_system_excludes_rakelib_files_too
 
104
    rake_system_dir
 
105
 
 
106
    rake '-g', "sys1", '-T', 'extra'
 
107
 
 
108
    refute_match %r{extra:extra}, @out
 
109
  end
 
110
 
 
111
  def test_by_default_rakelib_files_are_included
 
112
    rake_system_dir
 
113
    rakefile_extra
 
114
 
 
115
    rake '-T', 'extra', '--trace'
 
116
 
 
117
    assert_match %r{extra:extra}, @out
 
118
  end
 
119
 
 
120
  def test_implicit_system
 
121
    rake_system_dir
 
122
    Dir.chdir @tempdir
 
123
 
 
124
    rake "sys1", "--trace"
 
125
 
 
126
    assert_match %r{^SYS1}, @out
 
127
  end
 
128
 
 
129
  def test_no_system
 
130
    rake_system_dir
 
131
    rakefile_extra
 
132
 
 
133
    rake '-G', "sys1"
 
134
 
 
135
    assert_match %r{^Don't know how to build task}, @err # emacs wart: '
 
136
  end
 
137
 
 
138
  def test_nosearch_with_rakefile_uses_local_rakefile
 
139
    rakefile_default
 
140
 
 
141
    rake "--nosearch"
 
142
 
 
143
    assert_match %r{^DEFAULT}, @out
 
144
  end
 
145
 
 
146
  def test_nosearch_without_rakefile_finds_system
 
147
    rakefile_nosearch
 
148
    rake_system_dir
 
149
 
 
150
    rake "--nosearch", "sys1"
 
151
 
 
152
    assert_match %r{^SYS1}, @out
 
153
  end
 
154
 
 
155
  def test_nosearch_without_rakefile_and_no_system_fails
 
156
    rakefile_nosearch
 
157
    ENV['RAKE_SYSTEM'] = 'not_exist'
 
158
 
 
159
    rake "--nosearch"
 
160
 
 
161
    assert_match %r{^No Rakefile found}, @err
 
162
  end
 
163
 
 
164
  def test_invalid_command_line_options
 
165
    rakefile_default
 
166
 
 
167
    rake "--bad-options"
 
168
 
 
169
    assert_match %r{invalid +option}i, @err
 
170
  end
 
171
 
 
172
  def test_inline_verbose_default_should_show_command
 
173
    rakefile_verbose
 
174
 
 
175
    rake "inline_verbose_default"
 
176
 
 
177
    assert_match(/#{Regexp.quote(RUBY)} -e/, @err)
 
178
  end
 
179
 
 
180
  def test_inline_verbose_true_should_show_command
 
181
    rakefile_verbose
 
182
 
 
183
    rake "inline_verbose_true"
 
184
 
 
185
    assert_match(/#{Regexp.quote(RUBY)} -e/, @err)
 
186
  end
 
187
 
 
188
  def test_inline_verbose_false_should_not_show_command
 
189
    rakefile_verbose
 
190
 
 
191
    rake "inline_verbose_false"
 
192
 
 
193
    refute_match(/#{Regexp.quote(RUBY)} -e/, @err)
 
194
  end
 
195
 
 
196
  def test_block_verbose_false_should_not_show_command
 
197
    rakefile_verbose
 
198
 
 
199
    rake "block_verbose_false"
 
200
 
 
201
    refute_match(/#{Regexp.quote(RUBY)} -e/, @err)
 
202
  end
 
203
 
 
204
  def test_block_verbose_true_should_show_command
 
205
    rakefile_verbose
 
206
 
 
207
    rake "block_verbose_true"
 
208
 
 
209
    assert_match(/#{Regexp.quote(RUBY)} -e/, @err)
 
210
  end
 
211
 
 
212
  def test_standalone_verbose_true_should_show_command
 
213
    rakefile_verbose
 
214
 
 
215
    rake "standalone_verbose_true"
 
216
 
 
217
    assert_match(/#{Regexp.quote(RUBY)} -e/, @err)
 
218
  end
 
219
 
 
220
  def test_standalone_verbose_false_should_not_show_command
 
221
    rakefile_verbose
 
222
 
 
223
    rake "standalone_verbose_false"
 
224
 
 
225
    refute_match(/#{Regexp.quote(RUBY)} -e/, @err)
 
226
  end
 
227
 
 
228
  def test_dry_run
 
229
    rakefile_default
 
230
 
 
231
    rake "-n", "other"
 
232
 
 
233
    assert_match %r{Execute \(dry run\) default}, @err
 
234
    assert_match %r{Execute \(dry run\) other}, @err
 
235
    refute_match %r{DEFAULT}, @out
 
236
    refute_match %r{OTHER}, @out
 
237
  end
 
238
 
 
239
  # Test for the trace/dry_run bug found by Brian Chandler
 
240
  def test_dry_run_bug
 
241
    rakefile_dryrun
 
242
 
 
243
    rake
 
244
 
 
245
    FileUtils.rm_f 'temp_one'
 
246
 
 
247
    rake "--dry-run"
 
248
 
 
249
    refute_match(/No such file/, @out)
 
250
  end
 
251
 
 
252
  # Test for the trace/dry_run bug found by Brian Chandler
 
253
  def test_trace_bug
 
254
    rakefile_dryrun
 
255
 
 
256
    rake
 
257
 
 
258
    FileUtils.rm_f 'temp_one'
 
259
 
 
260
    rake "--trace"
 
261
 
 
262
    refute_match(/No such file/, @out)
 
263
  end
 
264
 
 
265
  def test_imports
 
266
    rakefile_imports
 
267
 
 
268
    rake
 
269
 
 
270
    assert File.exist?(File.join(@tempdir, 'dynamic_deps')),
 
271
           "'dynamic_deps' file should exist"
 
272
    assert_match(/^FIRST$\s+^DYNAMIC$\s+^STATIC$\s+^OTHER$/, @out)
 
273
  end
 
274
 
 
275
  def test_rules_chaining_to_file_task
 
276
    rakefile_chains
 
277
 
 
278
    rake
 
279
 
 
280
    assert File.exist?(File.join(@tempdir, 'play.app')),
 
281
           "'play.app' file should exist"
 
282
  end
 
283
 
 
284
  def test_file_creation_task
 
285
    rakefile_file_creation
 
286
 
 
287
    rake "prep"
 
288
    rake "run"
 
289
    rake "run"
 
290
 
 
291
    assert(@err !~ /^cp src/, "Should not recopy data")
 
292
  end
 
293
 
 
294
  def test_dash_f_with_no_arg_foils_rakefile_lookup
 
295
    rakefile_rakelib
 
296
 
 
297
    rake '-I', 'rakelib', '-rtest1', '-f'
 
298
 
 
299
    assert_match(/^TEST1$/, @out)
 
300
  end
 
301
 
 
302
  def test_dot_rake_files_can_be_loaded_with_dash_r
 
303
    rakefile_rakelib
 
304
 
 
305
    rake '-I', 'rakelib', '-rtest2', '-f'
 
306
 
 
307
    assert_empty @err
 
308
    assert_match(/^TEST2$/, @out)
 
309
  end
 
310
 
 
311
  def test_can_invoke_task_in_toplevel_namespace
 
312
    rakefile_namespace
 
313
 
 
314
    rake "copy"
 
315
 
 
316
    assert_match(/^COPY$/, @out)
 
317
  end
 
318
 
 
319
  def test_can_invoke_task_in_nested_namespace
 
320
    rakefile_namespace
 
321
 
 
322
    rake "nest:copy"
 
323
 
 
324
    assert_match(/^NEST COPY$/, @out)
 
325
  end
 
326
 
 
327
  def test_tasks_can_reference_task_in_same_namespace
 
328
    rakefile_namespace
 
329
 
 
330
    rake "nest:xx"
 
331
 
 
332
    assert_match(/^NEST COPY$/m, @out)
 
333
  end
 
334
 
 
335
  def test_tasks_can_reference_task_in_other_namespaces
 
336
    rakefile_namespace
 
337
 
 
338
    rake "b:run"
 
339
 
 
340
    assert_match(/^IN A\nIN B$/m, @out)
 
341
  end
 
342
 
 
343
  def test_anonymous_tasks_can_be_invoked_indirectly
 
344
    rakefile_namespace
 
345
 
 
346
    rake "anon"
 
347
 
 
348
    assert_match(/^ANON COPY$/m, @out)
 
349
  end
 
350
 
 
351
  def test_rake_namespace_refers_to_toplevel
 
352
    rakefile_namespace
 
353
 
 
354
    rake "very:nested:run"
 
355
 
 
356
    assert_match(/^COPY$/m, @out)
 
357
  end
 
358
 
 
359
  def test_file_task_are_not_scoped_by_namespaces
 
360
    rakefile_namespace
 
361
 
 
362
    rake "xyz.rb"
 
363
 
 
364
    assert_match(/^XYZ1\nXYZ2$/m, @out)
 
365
  end
 
366
 
 
367
  def test_file_task_dependencies_scoped_by_namespaces
 
368
    rakefile_namespace
 
369
 
 
370
    rake "scopedep.rb"
 
371
 
 
372
    assert_match(/^PREPARE\nSCOPEDEP$/m, @out)
 
373
  end
 
374
 
 
375
  def test_comment_before_task_acts_like_desc
 
376
    rakefile_comments
 
377
 
 
378
    rake "-T"
 
379
 
 
380
    refute_match(/comment for t1/, @out)
 
381
  end
 
382
 
 
383
  def test_comment_separated_from_task_by_blank_line_is_not_picked_up
 
384
    rakefile_comments
 
385
 
 
386
    rake "-T"
 
387
 
 
388
    refute_match("t2", @out)
 
389
  end
 
390
 
 
391
  def test_comment_after_desc_is_ignored
 
392
    rakefile_comments
 
393
 
 
394
    rake "-T"
 
395
 
 
396
    assert_match("override comment for t3", @out)
 
397
  end
 
398
 
 
399
  def test_comment_before_desc_is_ignored
 
400
    rakefile_comments
 
401
 
 
402
    rake "-T"
 
403
 
 
404
    assert_match("override comment for t4", @out)
 
405
  end
 
406
 
 
407
  def test_correct_number_of_tasks_reported
 
408
    rakefile_comments
 
409
 
 
410
    rake "-T"
 
411
 
 
412
    assert_equal(2, @out.split(/\n/).grep(/t\d/).size)
 
413
  end
 
414
 
 
415
  def test_file_list_is_requirable_separately
 
416
    ruby '-rrake/file_list', '-e', 'puts Rake::FileList["a"].size'
 
417
    assert_equal "1\n", @out
 
418
  end
 
419
 
 
420
  private
 
421
 
 
422
  # Run a shell Ruby command with command line options (using the
 
423
  # default test options). Output is captured in @out and @err
 
424
  def ruby(*option_list)
 
425
    run_ruby(@ruby_options + option_list)
 
426
  end
 
427
 
 
428
  # Run a command line rake with the give rake options.  Default
 
429
  # command line ruby options are included.  Output is captured in
 
430
  # @out and @err
 
431
  def rake(*rake_options)
 
432
    run_ruby @ruby_options + [@rake_path] + rake_options
 
433
  end
 
434
 
 
435
  # Low level ruby command runner ...
 
436
  def run_ruby(option_list)
 
437
    puts "COMMAND: [#{RUBY} #{option_list.join ' '}]" if @verbose
 
438
 
 
439
    inn, out, err = Open3.popen3(Gem.ruby, *option_list)
 
440
    inn.close
 
441
 
 
442
    @out = out.read
 
443
    @err = err.read
 
444
 
 
445
    puts "OUTPUT:  [#{@out}]" if @verbose
 
446
    puts "ERROR:   [#{@err}]" if @verbose
 
447
    puts "PWD:     [#{Dir.pwd}]" if @verbose
 
448
  end
 
449
 
 
450
end