1
require File.expand_path('../helper', __FILE__)
5
class TestRakeFunctional < Rake::TestCase
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']
29
assert_match(/^DEFAULT$/, @out)
32
def test_rake_error_on_bad_task
37
assert_match(/rake aborted/, @err)
40
def test_env_available_at_top_scope
45
assert_match(/^TOPSCOPE$/, @out)
48
def test_env_available_at_task_scope
51
rake 'TESTTASKSCOPE=1', 'task_scope'
53
assert_match(/^TASKSCOPE$/, @out)
57
ENV['RAKE_COLUMNS'] = '80'
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
68
def test_long_description
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
79
def test_proper_namespace_access
84
refute_match %r{^BAD:}, @out
92
assert_match %r{^OK$}, @out
100
assert_match %r{^SYS1}, @out
103
def test_system_excludes_rakelib_files_too
106
rake '-g', "sys1", '-T', 'extra'
108
refute_match %r{extra:extra}, @out
111
def test_by_default_rakelib_files_are_included
115
rake '-T', 'extra', '--trace'
117
assert_match %r{extra:extra}, @out
120
def test_implicit_system
124
rake "sys1", "--trace"
126
assert_match %r{^SYS1}, @out
135
assert_match %r{^Don't know how to build task}, @err # emacs wart: '
138
def test_nosearch_with_rakefile_uses_local_rakefile
143
assert_match %r{^DEFAULT}, @out
146
def test_nosearch_without_rakefile_finds_system
150
rake "--nosearch", "sys1"
152
assert_match %r{^SYS1}, @out
155
def test_nosearch_without_rakefile_and_no_system_fails
157
ENV['RAKE_SYSTEM'] = 'not_exist'
161
assert_match %r{^No Rakefile found}, @err
164
def test_invalid_command_line_options
169
assert_match %r{invalid +option}i, @err
172
def test_inline_verbose_default_should_show_command
175
rake "inline_verbose_default"
177
assert_match(/#{Regexp.quote(RUBY)} -e/, @err)
180
def test_inline_verbose_true_should_show_command
183
rake "inline_verbose_true"
185
assert_match(/#{Regexp.quote(RUBY)} -e/, @err)
188
def test_inline_verbose_false_should_not_show_command
191
rake "inline_verbose_false"
193
refute_match(/#{Regexp.quote(RUBY)} -e/, @err)
196
def test_block_verbose_false_should_not_show_command
199
rake "block_verbose_false"
201
refute_match(/#{Regexp.quote(RUBY)} -e/, @err)
204
def test_block_verbose_true_should_show_command
207
rake "block_verbose_true"
209
assert_match(/#{Regexp.quote(RUBY)} -e/, @err)
212
def test_standalone_verbose_true_should_show_command
215
rake "standalone_verbose_true"
217
assert_match(/#{Regexp.quote(RUBY)} -e/, @err)
220
def test_standalone_verbose_false_should_not_show_command
223
rake "standalone_verbose_false"
225
refute_match(/#{Regexp.quote(RUBY)} -e/, @err)
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
239
# Test for the trace/dry_run bug found by Brian Chandler
245
FileUtils.rm_f 'temp_one'
249
refute_match(/No such file/, @out)
252
# Test for the trace/dry_run bug found by Brian Chandler
258
FileUtils.rm_f 'temp_one'
262
refute_match(/No such file/, @out)
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)
275
def test_rules_chaining_to_file_task
280
assert File.exist?(File.join(@tempdir, 'play.app')),
281
"'play.app' file should exist"
284
def test_file_creation_task
285
rakefile_file_creation
291
assert(@err !~ /^cp src/, "Should not recopy data")
294
def test_dash_f_with_no_arg_foils_rakefile_lookup
297
rake '-I', 'rakelib', '-rtest1', '-f'
299
assert_match(/^TEST1$/, @out)
302
def test_dot_rake_files_can_be_loaded_with_dash_r
305
rake '-I', 'rakelib', '-rtest2', '-f'
308
assert_match(/^TEST2$/, @out)
311
def test_can_invoke_task_in_toplevel_namespace
316
assert_match(/^COPY$/, @out)
319
def test_can_invoke_task_in_nested_namespace
324
assert_match(/^NEST COPY$/, @out)
327
def test_tasks_can_reference_task_in_same_namespace
332
assert_match(/^NEST COPY$/m, @out)
335
def test_tasks_can_reference_task_in_other_namespaces
340
assert_match(/^IN A\nIN B$/m, @out)
343
def test_anonymous_tasks_can_be_invoked_indirectly
348
assert_match(/^ANON COPY$/m, @out)
351
def test_rake_namespace_refers_to_toplevel
354
rake "very:nested:run"
356
assert_match(/^COPY$/m, @out)
359
def test_file_task_are_not_scoped_by_namespaces
364
assert_match(/^XYZ1\nXYZ2$/m, @out)
367
def test_file_task_dependencies_scoped_by_namespaces
372
assert_match(/^PREPARE\nSCOPEDEP$/m, @out)
375
def test_comment_before_task_acts_like_desc
380
refute_match(/comment for t1/, @out)
383
def test_comment_separated_from_task_by_blank_line_is_not_picked_up
388
refute_match("t2", @out)
391
def test_comment_after_desc_is_ignored
396
assert_match("override comment for t3", @out)
399
def test_comment_before_desc_is_ignored
404
assert_match("override comment for t4", @out)
407
def test_correct_number_of_tasks_reported
412
assert_equal(2, @out.split(/\n/).grep(/t\d/).size)
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
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)
428
# Run a command line rake with the give rake options. Default
429
# command line ruby options are included. Output is captured in
431
def rake(*rake_options)
432
run_ruby @ruby_options + [@rake_path] + rake_options
435
# Low level ruby command runner ...
436
def run_ruby(option_list)
437
puts "COMMAND: [#{RUBY} #{option_list.join ' '}]" if @verbose
439
inn, out, err = Open3.popen3(Gem.ruby, *option_list)
445
puts "OUTPUT: [#{@out}]" if @verbose
446
puts "ERROR: [#{@err}]" if @verbose
447
puts "PWD: [#{Dir.pwd}]" if @verbose