~ubuntu-branches/ubuntu/precise/rake/precise

« back to all changes in this revision

Viewing changes to test/test_application.rb

  • Committer: Bazaar Package Importer
  • Author(s): Adam Majer
  • Date: 2008-01-28 11:42:11 UTC
  • mfrom: (1.1.5 upstream) (2.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080128114211-8l1wcx1k9s6oa8s6
Tags: 0.8.1-3
Apply upstream patch (SVN r632) correcting one of the unit
tests. The old unit test depends on the file system ordering
while the new ones just check for consistency. File order is
unimportant. (closes: #462817)

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
require 'test/unit'
10
10
require 'rake'
 
11
require 'test/rake_test_setup'
11
12
require 'test/capture_stdout'
12
 
require 'flexmock'
13
13
 
14
14
TESTING_REQUIRE = [ ]
15
15
 
16
16
######################################################################
17
17
class TestApplication < Test::Unit::TestCase
18
18
  include CaptureStdout
19
 
  include FlexMock::TestCase
20
19
 
21
20
  def setup
22
21
    @app = Rake::Application.new
 
22
    @app.options.rakelib = []
23
23
  end
24
24
 
25
25
  def test_constant_warning
31
31
 
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)
39
39
  end
40
40
 
 
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)
 
48
  end
 
49
 
 
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)
 
58
  end
 
59
 
41
60
  def test_finding_rakefile
42
61
    assert @app.instance_eval { have_rakefile }
43
62
    assert_equal "rakefile", @app.rakefile.downcase
122
141
 
123
142
  def test_good_run
124
143
    ran = false
 
144
    ARGV.clear
 
145
    ARGV << '--rakelib=""'
125
146
    @app.options.silent = true
126
147
    @app.instance_eval do
127
148
      intern(Rake::Task, "default").enhance { ran = true }
133
154
  def test_display_task_run
134
155
    ran = false
135
156
    ARGV.clear
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
147
168
    ran = false
148
169
    ARGV.clear
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")
163
184
  def test_bad_run
164
185
    @app.intern(Rake::Task, "default").enhance { fail }
165
186
    ARGV.clear
166
 
    ARGV << '-f' << '-s'
 
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
236
257
  end
237
258
 
 
259
  def test_bad_options
 
260
    assert_raise GetoptLong::InvalidOption do
 
261
      capture_stderr do
 
262
        flags('--bad', '-t') do |opts|
 
263
        end
 
264
      end
 
265
    end
 
266
  end
 
267
  
238
268
  def test_trace_option
239
269
    flags('--trace', '-t') do |opts|
240
270
      assert opts.trace
253
283
  end
254
284
 
255
285
  def test_help
256
 
    flags('--help', '-H') do |opts, output|
257
 
      assert_match(/\Arake/, @out)
258
 
      assert_match(/--help/, @out)
259
 
      assert_equal :exit, @exit
260
 
    end
261
 
  end
262
 
 
263
 
  def test_usage
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
 
292
    end
 
293
  end
 
294
 
 
295
  def test_describe
 
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)
269
300
    end
270
301
  end
271
302
 
375
406
      ex = assert_raise(GetoptLong::InvalidOption) do
376
407
        flags('--bad-option') 
377
408
      end
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)
 
414
      end
380
415
    end
381
416
  end
382
417
 
391
426
  end
392
427
  
393
428
  def test_environment_definition
394
 
    ENV['TESTKEY'] = nil
 
429
    ENV.delete('TESTKEY')
395
430
    command_line("a", "TESTKEY=12")
396
431
    assert_equal ["a"], @tasks.sort
397
432
    assert '12', ENV['TESTKEY']
398
433
  end
399
 
  
 
434
 
400
435
  private 
401
436
 
402
437
  def flags(*sets)
423
458
  end
424
459
end
425
460
 
 
461
class TestTaskArgumentParsing < Test::Unit::TestCase
 
462
  def setup
 
463
    @app = Rake::Application.new
 
464
  end
 
465
  
 
466
  def test_name_only
 
467
    name, args = @app.parse_task_string("name")
 
468
    assert_equal "name", name
 
469
    assert_equal [], args
 
470
  end
 
471
  
 
472
  def test_empty_args
 
473
    name, args = @app.parse_task_string("name[]")
 
474
    assert_equal "name", name
 
475
    assert_equal [], args
 
476
  end
 
477
  
 
478
  def test_one_argument
 
479
    name, args = @app.parse_task_string("name[one]")
 
480
    assert_equal "name", name
 
481
    assert_equal ["one"], args
 
482
  end
 
483
  
 
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
 
488
  end
 
489
  
 
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
 
494
  end
 
495
 
 
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
 
500
  end
 
501
 
 
502
end