11
require 'test/rake_test_setup'
11
12
require 'test/capture_stdout'
14
14
TESTING_REQUIRE = [ ]
16
16
######################################################################
17
17
class TestApplication < Test::Unit::TestCase
18
18
include CaptureStdout
19
include FlexMock::TestCase
22
21
@app = Rake::Application.new
22
@app.options.rakelib = []
25
25
def test_constant_warning
32
32
def test_display_tasks
33
33
@app.options.show_task_pattern = //
34
@app.last_comment = "COMMENT"
34
@app.last_description = "COMMENT"
35
35
@app.define_task(Rake::Task, "t")
36
36
out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
37
37
assert_match(/^rake t/, out)
38
38
assert_match(/# COMMENT/, out)
41
def test_display_tasks_with_long_comments
42
@app.options.show_task_pattern = //
43
@app.last_description = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
44
@app.define_task(Rake::Task, "t")
45
out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
46
assert_match(/^rake t/, out)
47
assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
50
def test_display_tasks_with_full_descriptions
51
@app.options.show_task_pattern = //
52
@app.options.full_description = true
53
@app.last_description = "COMMENT"
54
@app.define_task(Rake::Task, "t")
55
out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
56
assert_match(/^rake t$/, out)
57
assert_match(/^ {4}COMMENT$/, out)
41
60
def test_finding_rakefile
42
61
assert @app.instance_eval { have_rakefile }
43
62
assert_equal "rakefile", @app.rakefile.downcase
133
154
def test_display_task_run
136
ARGV << '-f' << '-s' << '--tasks'
137
@app.last_comment = "COMMENT"
157
ARGV << '-f' << '-s' << '--tasks' << '--rakelib=""'
158
@app.last_description = "COMMENT"
138
159
@app.define_task(Rake::Task, "default")
139
160
out = capture_stdout { @app.run }
140
161
assert @app.options.show_tasks
146
167
def test_display_prereqs
149
ARGV << '-f' << '-s' << '--prereqs'
150
@app.last_comment = "COMMENT"
170
ARGV << '-f' << '-s' << '--prereqs' << '--rakelib=""'
171
@app.last_description = "COMMENT"
151
172
t = @app.define_task(Rake::Task, "default")
152
173
t.enhance([:a, :b])
153
174
@app.define_task(Rake::Task, "a")
164
185
@app.intern(Rake::Task, "default").enhance { fail }
187
ARGV << '-f' << '-s' << '--rakelib=""'
167
188
assert_raise(SystemExit) {
168
189
err = capture_stderr { @app.run }
169
190
assert_match(/see full trace/, err)
230
251
assert_nil opts.show_prereqs
231
252
assert_nil opts.show_tasks
232
253
assert_nil opts.classic_namespace
233
assert_equal 'rakelib', opts.rakelib
254
assert_equal ['rakelib'], opts.rakelib
234
255
assert ! RakeFileUtils.verbose_flag
235
256
assert ! RakeFileUtils.nowrite_flag
260
assert_raise GetoptLong::InvalidOption do
262
flags('--bad', '-t') do |opts|
238
268
def test_trace_option
239
269
flags('--trace', '-t') do |opts|
240
270
assert opts.trace
256
flags('--help', '-H') do |opts, output|
257
assert_match(/\Arake/, @out)
258
assert_match(/--help/, @out)
259
assert_equal :exit, @exit
264
flags('--usage', '-h') do |opts, output|
286
flags('--help', '-H', '-h') do |opts|
265
287
assert_match(/\Arake/, @out)
266
288
assert_match(/\boptions\b/, @out)
267
289
assert_match(/\btargets\b/, @out)
268
290
assert_equal :exit, @exit
291
assert_equal :exit, @exit
296
flags('--describe') do |opts|
297
assert opts.full_description
298
assert opts.show_tasks
299
assert_equal(//.to_s, opts.show_task_pattern.to_s)
375
406
ex = assert_raise(GetoptLong::InvalidOption) do
376
407
flags('--bad-option')
378
assert_match(/unrecognized option/, ex.message)
379
assert_match(/--bad-option/, ex.message)
409
if ex.message =~ /^While/ # Ruby 1.9 error message
410
assert_match(/while parsing/i, ex.message)
411
else # Ruby 1.8 error message
412
assert_match(/unrecognized option/i, ex.message)
413
assert_match(/--bad-option/, ex.message)
393
428
def test_environment_definition
429
ENV.delete('TESTKEY')
395
430
command_line("a", "TESTKEY=12")
396
431
assert_equal ["a"], @tasks.sort
397
432
assert '12', ENV['TESTKEY']
461
class TestTaskArgumentParsing < Test::Unit::TestCase
463
@app = Rake::Application.new
467
name, args = @app.parse_task_string("name")
468
assert_equal "name", name
469
assert_equal [], args
473
name, args = @app.parse_task_string("name[]")
474
assert_equal "name", name
475
assert_equal [], args
478
def test_one_argument
479
name, args = @app.parse_task_string("name[one]")
480
assert_equal "name", name
481
assert_equal ["one"], args
484
def test_two_arguments
485
name, args = @app.parse_task_string("name[one,two]")
486
assert_equal "name", name
487
assert_equal ["one", "two"], args
490
def test_can_handle_spaces_between_args
491
name, args = @app.parse_task_string("name[one, two,\tthree , \tfour]")
492
assert_equal "name", name
493
assert_equal ["one", "two", "three", "four"], args
496
def test_keeps_embedded_spaces
497
name, args = @app.parse_task_string("name[a one ana, two]")
498
assert_equal "name", name
499
assert_equal ["a one ana", "two"], args