rake 0.7.3 → 0.8.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.

@@ -6,6 +6,8 @@
6
6
  require 'rubygems'
7
7
  require 'rake'
8
8
  require 'rake/packagetask'
9
+ require 'rubygems/user_interaction'
10
+ require 'rubygems/builder'
9
11
 
10
12
  begin
11
13
  Gem.manage_gems
@@ -12,3 +12,6 @@ desc "A2"
12
12
  task :a
13
13
 
14
14
  task :c
15
+
16
+ desc "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
17
+ task :d
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ task :exit5 do
4
+ exit(5)
5
+ end
6
+
7
+ task :normal do
8
+ end
@@ -3,11 +3,13 @@
3
3
  begin
4
4
  require 'rubygems'
5
5
  gem 'session'
6
+ require 'session'
6
7
  rescue LoadError
7
8
  puts "UNABLE TO RUN FUNCTIONAL TESTS"
8
9
  puts "No Session Found"
9
10
  end
10
11
 
11
12
  if defined?(Session)
13
+ puts "RUNNING WITH SESSIONS"
12
14
  require 'test/session_functional'
13
15
  end
@@ -0,0 +1,5 @@
1
+ # Common setup for all test files.
2
+
3
+ require 'rubygems'
4
+ gem 'flexmock'
5
+ require 'flexmock/test_unit'
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'test/unit'
4
4
  require 'fileutils'
5
+ require 'session'
5
6
 
6
7
  # Version 2.1.9 of session has a bug where the @debug instance
7
8
  # variable is not initialized, causing warning messages. This snippet
@@ -17,8 +18,13 @@ module Session
17
18
  end
18
19
 
19
20
  class FunctionalTest < Test::Unit::TestCase
21
+
22
+ RUBY_COMMAND = 'ruby'
23
+
20
24
  def setup
21
25
  @rake_path = File.expand_path("bin/rake")
26
+ @coverage_aggregate_file = File.expand_path("rcov_aggregate")
27
+ @rcov_dir = File.expand_path("coverage")
22
28
  lib_path = File.expand_path("lib")
23
29
  @ruby_options = "-I#{lib_path} -I."
24
30
  @verbose = ! ENV['VERBOSE'].nil?
@@ -60,6 +66,15 @@ class FunctionalTest < Test::Unit::TestCase
60
66
  assert_match %r{^rake a *# A / A2 *$}, @out
61
67
  assert_match %r{^rake b *# B *$}, @out
62
68
  assert_no_match %r{^rake c}, @out
69
+ assert_match %r{^rake d *# x{65}\.\.\.$}, @out
70
+ end
71
+
72
+ def test_long_description
73
+ Dir.chdir("test/data/multidesc") do rake "--describe" end
74
+ assert_match %r{^rake a\n *A / A2 *$}m, @out
75
+ assert_match %r{^rake b\n *B *$}m, @out
76
+ assert_match %r{^rake d\n *x{80}}m, @out
77
+ assert_no_match %r{^rake c\n}m, @out
63
78
  end
64
79
 
65
80
  def test_rbext
@@ -188,6 +203,20 @@ class FunctionalTest < Test::Unit::TestCase
188
203
  assert_match(/^XYZ1\nXYZ2$/m, @out)
189
204
  end
190
205
  end
206
+
207
+ def test_rake_returns_status_error_values
208
+ Dir.chdir("test/data/statusreturn") do
209
+ rake "exit5"
210
+ assert_status(5)
211
+ end
212
+ end
213
+
214
+ def test_rake_returns_no_status_error_on_normal_exit
215
+ Dir.chdir("test/data/statusreturn") do
216
+ rake "normal"
217
+ assert_status(0)
218
+ end
219
+ end
191
220
 
192
221
  private
193
222
 
@@ -197,10 +226,26 @@ class FunctionalTest < Test::Unit::TestCase
197
226
  end
198
227
  end
199
228
 
229
+ class << self
230
+ def format_command
231
+ @format_command ||= lambda { |ruby_options, rake_path, options|
232
+ "ruby #{ruby_options} #{rake_path} #{options}"
233
+ }
234
+ end
235
+
236
+ def format_command=(fmt_command)
237
+ @format_command = fmt_command
238
+ end
239
+ end
240
+
200
241
  def rake(*option_list)
242
+ # self.class.format_command = lambda { |ruby_options, rake_path, options|
243
+ # "rcov --output=#{@rcov_dir} --aggregate=#{@coverage_aggregate_file} #{ruby_options} #{rake_path} -- #{options}"
244
+ # }
245
+
201
246
  options = option_list.join(' ')
202
247
  shell = Session::Shell.new
203
- command = "ruby #{@ruby_options} #{@rake_path} #{options}"
248
+ command = self.class.format_command[@ruby_options, @rake_path, options]
204
249
  puts "COMMAND: [#{command}]" if @verbose
205
250
  @out, @err = shell.execute command
206
251
  @status = shell.exit_status
@@ -8,18 +8,18 @@ end
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,13 +31,32 @@ class TestApplication < Test::Unit::TestCase
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,6 +141,8 @@ class TestApplication < Test::Unit::TestCase
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,8 +154,8 @@ class TestApplication < Test::Unit::TestCase
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,8 +167,8 @@ class TestApplication < Test::Unit::TestCase
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,7 +184,7 @@ class TestApplication < Test::Unit::TestCase
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,11 +251,20 @@ class TestApplicationOptions < Test::Unit::TestCase
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,19 +283,20 @@ class TestApplicationOptions < Test::Unit::TestCase
253
283
  end
254
284
 
255
285
  def test_help
256
- flags('--help', '-H') do |opts, output|
286
+ flags('--help', '-H', '-h') do |opts|
257
287
  assert_match(/\Arake/, @out)
258
- assert_match(/--help/, @out)
288
+ assert_match(/\boptions\b/, @out)
289
+ assert_match(/\btargets\b/, @out)
290
+ assert_equal :exit, @exit
259
291
  assert_equal :exit, @exit
260
292
  end
261
293
  end
262
294
 
263
- def test_usage
264
- flags('--usage', '-h') do |opts, output|
265
- assert_match(/\Arake/, @out)
266
- assert_match(/\boptions\b/, @out)
267
- assert_match(/\btargets\b/, @out)
268
- assert_equal :exit, @exit
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,8 +406,12 @@ class TestApplicationOptions < Test::Unit::TestCase
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,12 +426,12 @@ class TestApplicationOptions < Test::Unit::TestCase
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,3 +458,45 @@ class TestApplicationOptions < Test::Unit::TestCase
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
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake'
5
+ require 'stringio'
6
+
7
+ ######################################################################
8
+ class TestExtension < Test::Unit::TestCase
9
+
10
+ module Redirect
11
+ def error_redirect
12
+ old_err = $stderr
13
+ result = StringIO.new
14
+ $stderr = result
15
+ yield
16
+ result
17
+ ensure
18
+ $stderr = old_err
19
+ end
20
+ end
21
+
22
+ class Sample
23
+ extend Redirect
24
+
25
+ def duplicate_method
26
+ :original
27
+ end
28
+
29
+ OK_ERRS = error_redirect do
30
+ rake_extension("a") do
31
+ def ok_method
32
+ end
33
+ end
34
+ end
35
+
36
+
37
+ DUP_ERRS = error_redirect do
38
+ rake_extension("duplicate_method") do
39
+ def duplicate_method
40
+ :override
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ def test_methods_actually_exist
47
+ sample = Sample.new
48
+ sample.ok_method
49
+ sample.duplicate_method
50
+ end
51
+
52
+ def test_no_warning_when_defining_ok_method
53
+ assert_equal "", Sample::OK_ERRS.string
54
+ end
55
+
56
+ def test_extension_complains_when_a_method_that_is_present
57
+ assert_match(/warning:/i, Sample::DUP_ERRS.string)
58
+ assert_match(/already exists/i, Sample::DUP_ERRS.string)
59
+ assert_match(/duplicate_method/i, Sample::DUP_ERRS.string)
60
+ assert_equal :original, Sample.new.duplicate_method
61
+ end
62
+
63
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'test/unit'
4
4
  require 'rake'
5
+
5
6
  require 'test/capture_stdout'
6
7
 
7
8
  class TestFileList < Test::Unit::TestCase
@@ -13,10 +14,17 @@ class TestFileList < Test::Unit::TestCase
13
14
  end
14
15
 
15
16
  def teardown
16
- FileList.select_default_ignore_patterns
17
+ # FileList.select_default_ignore_patterns
17
18
  FileUtils.rm_rf("testdata")
18
19
  end
19
20
 
21
+ def test_delgating_methods_do_not_include_to_a_or_to_ary
22
+ assert ! FileList::DELEGATING_METHODS.include?("to_a"), "should not include to_a"
23
+ assert ! FileList::DELEGATING_METHODS.include?(:to_a), "should not include to_a"
24
+ assert ! FileList::DELEGATING_METHODS.include?("to_ary"), "should not include to_ary"
25
+ assert ! FileList::DELEGATING_METHODS.include?(:to_ary), "should not include to_ary"
26
+ end
27
+
20
28
  def test_create
21
29
  fl = FileList.new
22
30
  assert_equal 0, fl.size
@@ -196,7 +204,7 @@ class TestFileList < Test::Unit::TestCase
196
204
 
197
205
  def test_to_s_pending
198
206
  fl = FileList['testdata/abc.*']
199
- assert_equal %{testdata/abc.c testdata/abc.h testdata/abc.x}.sort, fl.to_s.sort
207
+ assert_equal %{testdata/abc.c testdata/abc.h testdata/abc.x}, fl.to_s
200
208
  end
201
209
 
202
210
  def test_inspect_pending
@@ -467,7 +475,7 @@ class TestFileList < Test::Unit::TestCase
467
475
  assert_equal FileList, b[0].class
468
476
  assert_equal FileList, b[1].class
469
477
 
470
- b = a.zip(['x', 'y'])
478
+ b = a.zip(['x', 'y']).to_a
471
479
  assert_equal [['a', 'x'], ['b', 'y']], b
472
480
  assert_equal Array, b.class
473
481
  assert_equal Array, b[0].class
@@ -543,7 +551,7 @@ class TestFileList < Test::Unit::TestCase
543
551
  def test_file_utils_can_use_filelists
544
552
  cfiles = FileList['testdata/*.c']
545
553
 
546
- cp cfiles, @cdir
554
+ cp cfiles, @cdir, :verbose => false
547
555
 
548
556
  assert File.exist?(File.join(@cdir, 'abc.c'))
549
557
  assert File.exist?(File.join(@cdir, 'xyz.c'))