rake 0.7.1 → 0.7.2

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.

@@ -98,24 +98,24 @@ module Rake
98
98
  lib_path = @libs.join(File::PATH_SEPARATOR)
99
99
  desc "Run tests" + (@name==:test ? "" : " for #{@name}")
100
100
  task @name do
101
- run_code = ''
102
- RakeFileUtils.verbose(@verbose) do
103
- run_code =
104
- case @loader
105
- when :direct
106
- "-e 'ARGV.each{|f| load f}'"
107
- when :testrb
108
- "-S testrb #{fix}"
109
- when :rake
110
- rake_loader
111
- end
101
+ run_code = ''
102
+ RakeFileUtils.verbose(@verbose) do
103
+ run_code =
104
+ case @loader
105
+ when :direct
106
+ "-e 'ARGV.each{|f| load f}'"
107
+ when :testrb
108
+ "-S testrb #{fix}"
109
+ when :rake
110
+ rake_loader
111
+ end
112
112
  @ruby_opts.unshift( "-I#{lib_path}" )
113
- @ruby_opts.unshift( "-w" ) if @warning
114
- ruby @ruby_opts.join(" ") +
113
+ @ruby_opts.unshift( "-w" ) if @warning
114
+ ruby @ruby_opts.join(" ") +
115
115
  " \"#{run_code}\" " +
116
- file_list.collect { |fn| "\"#{fn}\"" }.join(' ') +
117
- " #{option_list}"
118
- end
116
+ file_list.collect { |fn| "\"#{fn}\"" }.join(' ') +
117
+ " #{option_list}"
118
+ end
119
119
  end
120
120
  self
121
121
  end
@@ -126,37 +126,36 @@ module Rake
126
126
 
127
127
  def file_list # :nodoc:
128
128
  if ENV['TEST']
129
- FileList[ ENV['TEST'] ]
129
+ FileList[ ENV['TEST'] ]
130
130
  else
131
- result = []
132
- result += @test_files.to_a if @test_files
133
- result += FileList[ @pattern ].to_a if @pattern
134
- FileList[result]
131
+ result = []
132
+ result += @test_files.to_a if @test_files
133
+ result += FileList[ @pattern ].to_a if @pattern
134
+ FileList[result]
135
135
  end
136
136
  end
137
137
 
138
138
  def fix # :nodoc:
139
139
  case RUBY_VERSION
140
140
  when '1.8.2'
141
- find_file 'rake/ruby182_test_unit_fix'
141
+ find_file 'rake/ruby182_test_unit_fix'
142
142
  else
143
- nil
143
+ nil
144
144
  end || ''
145
145
  end
146
146
 
147
147
  def rake_loader # :nodoc:
148
148
  find_file('rake/rake_test_loader') or
149
- fail "unable to find rake test loader"
149
+ fail "unable to find rake test loader"
150
150
  end
151
151
 
152
152
  def find_file(fn) # :nodoc:
153
153
  $LOAD_PATH.each do |path|
154
- file_path = File.join(path, "#{fn}.rb")
155
- return file_path if File.exist? file_path
154
+ file_path = File.join(path, "#{fn}.rb")
155
+ return file_path if File.exist? file_path
156
156
  end
157
157
  nil
158
158
  end
159
159
 
160
160
  end
161
161
  end
162
-
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'stringio'
4
+
5
+ # Mix-in for capturing standard output.
6
+ module CaptureStdout
7
+ def capture_stdout
8
+ s = StringIO.new
9
+ oldstdout = $stdout
10
+ $stdout = s
11
+ yield
12
+ s.string
13
+ ensure
14
+ $stdout = oldstdout
15
+ end
16
+
17
+ def capture_stderr
18
+ s = StringIO.new
19
+ oldstderr = $stderr
20
+ $stderr = s
21
+ yield
22
+ s.string
23
+ ensure
24
+ $stderr = oldstderr
25
+ end
26
+ end
@@ -0,0 +1 @@
1
+ # Empty Rakefile for Unit Test
@@ -11,8 +11,8 @@ module FileCreation
11
11
  old_time = create_file(oldfile)
12
12
  newfiles.each do |newfile|
13
13
  while create_file(newfile) <= old_time
14
- sleep(0.1)
15
- File.delete(newfile) rescue nil
14
+ sleep(0.1)
15
+ File.delete(newfile) rescue nil
16
16
  end
17
17
  end
18
18
  end
@@ -32,4 +32,3 @@ module FileCreation
32
32
  File.delete(name) rescue nil
33
33
  end
34
34
  end
35
-
@@ -2,7 +2,7 @@
2
2
 
3
3
  begin
4
4
  require 'rubygems'
5
- require_gem 'session'
5
+ gem 'session'
6
6
  rescue LoadError
7
7
  puts "UNABLE TO RUN FUNCTIONAL TESTS"
8
8
  puts "No Session Found"
@@ -0,0 +1,3 @@
1
+ # For --require testing
2
+
3
+ TESTING_REQUIRE << 1
@@ -0,0 +1,3 @@
1
+ # For --require testing
2
+
3
+ TESTING_REQUIRE << 2
@@ -39,7 +39,7 @@ class FunctionalTest < Test::Unit::TestCase
39
39
 
40
40
  def test_rake_error_on_bad_task
41
41
  Dir.chdir("test/data/default") do rake "xyz" end
42
- assert_match(/rake aborted/, @out)
42
+ assert_match(/rake aborted/, @err)
43
43
  assert_status(1)
44
44
  end
45
45
 
@@ -69,7 +69,7 @@ class FunctionalTest < Test::Unit::TestCase
69
69
 
70
70
  def test_nosearch
71
71
  Dir.chdir("test/data/nosearch") do rake "-N" end
72
- assert_match %r{^No Rakefile found}, @out
72
+ assert_match %r{^No Rakefile found}, @err
73
73
  end
74
74
 
75
75
  def test_dry_run
@@ -0,0 +1,406 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'rubygems'
5
+ rescue LoadError
6
+ # got no gems
7
+ end
8
+
9
+ require 'test/unit'
10
+ require 'rake'
11
+ require 'test/capture_stdout'
12
+ require 'flexmock'
13
+
14
+ TESTING_REQUIRE = [ ]
15
+
16
+ ######################################################################
17
+ class TestApplication < Test::Unit::TestCase
18
+ include CaptureStdout
19
+ include FlexMock::TestCase
20
+
21
+ def setup
22
+ @app = Rake::Application.new
23
+ end
24
+
25
+ def test_constant_warning
26
+ err = capture_stderr do @app.const_warning("Task") end
27
+ assert_match(/warning/i, err)
28
+ assert_match(/deprecated/i, err)
29
+ assert_match(/Task/i, err)
30
+ end
31
+
32
+ def test_display_tasks
33
+ @app.options.show_task_pattern = //
34
+ @app.last_comment = "COMMENT"
35
+ @app.define_task(Rake::Task, "t")
36
+ out = capture_stdout do @app.display_tasks_and_comments end
37
+ assert_match(/^rake t/, out)
38
+ assert_match(/# COMMENT/, out)
39
+ end
40
+
41
+ def test_finding_rakefile
42
+ assert @app.have_rakefile
43
+ assert_equal "rakefile", @app.rakefile.downcase
44
+ end
45
+
46
+ def test_not_finding_rakefile
47
+ @app.instance_eval { @rakefiles = ['NEVER_FOUND'] }
48
+ assert ! @app.have_rakefile
49
+ assert_nil @app.rakefile
50
+ end
51
+
52
+ def test_load_rakefile
53
+ original_dir = Dir.pwd
54
+ Dir.chdir("test/data/unittest")
55
+ @app.handle_options
56
+ @app.options.silent = true
57
+ @app.load_rakefile
58
+ assert_equal "rakefile", @app.rakefile.downcase
59
+ assert_match(%r(unittest$), Dir.pwd)
60
+ ensure
61
+ Dir.chdir(original_dir)
62
+ end
63
+
64
+ def test_load_rakefile_from_subdir
65
+ original_dir = Dir.pwd
66
+ Dir.chdir("test/data/unittest/subdir")
67
+ @app.handle_options
68
+ @app.options.silent = true
69
+ @app.load_rakefile
70
+ assert_equal "rakefile", @app.rakefile.downcase
71
+ assert_match(%r(unittest$), Dir.pwd)
72
+ ensure
73
+ Dir.chdir(original_dir)
74
+ end
75
+
76
+ def test_load_rakefile_not_found
77
+ original_dir = Dir.pwd
78
+ Dir.chdir("/")
79
+ @app.handle_options
80
+ @app.options.silent = true
81
+ ex = assert_raise(RuntimeError) do @app.load_rakefile end
82
+ assert_match(/no rakefile found/i, ex.message)
83
+ ensure
84
+ Dir.chdir(original_dir)
85
+ end
86
+
87
+ def test_not_caring_about_finding_rakefile
88
+ @app.instance_eval { @rakefiles = [''] }
89
+ assert @app.have_rakefile
90
+ assert_equal '', @app.rakefile
91
+ end
92
+
93
+ def test_loading_imports
94
+ mock = flexmock("loader")
95
+ mock.should_receive(:load).with("x.dummy").once
96
+ @app.add_loader("dummy", mock)
97
+ @app.add_import("x.dummy")
98
+ @app.load_imports
99
+ end
100
+
101
+ def test_building_imported_files_on_demand
102
+ mock = flexmock("loader")
103
+ mock.should_receive(:load).with("x.dummy").once
104
+ mock.should_receive(:make_dummy).with_no_args.once
105
+ @app.intern(Rake::Task, "x.dummy").enhance do mock.make_dummy end
106
+ @app.add_loader("dummy", mock)
107
+ @app.add_import("x.dummy")
108
+ @app.load_imports
109
+ end
110
+
111
+ def test_good_run
112
+ ran = false
113
+ @app.options.silent = true
114
+ @app.intern(Rake::Task, "default").enhance { ran = true }
115
+ @app.run
116
+ assert ran
117
+ end
118
+
119
+ def test_display_task_run
120
+ ran = false
121
+ ARGV.clear
122
+ ARGV << '-f' << '-s' << '--tasks'
123
+ @app.last_comment = "COMMENT"
124
+ @app.define_task(Rake::Task, "default")
125
+ out = capture_stdout { @app.run }
126
+ assert @app.options.show_tasks
127
+ assert ! ran
128
+ assert_match(/rake default/, out)
129
+ assert_match(/# COMMENT/, out)
130
+ end
131
+
132
+ def test_display_prereqs
133
+ ran = false
134
+ ARGV.clear
135
+ ARGV << '-f' << '-s' << '--prereqs'
136
+ @app.last_comment = "COMMENT"
137
+ t = @app.define_task(Rake::Task, "default")
138
+ t.enhance([:a, :b])
139
+ @app.define_task(Rake::Task, "a")
140
+ @app.define_task(Rake::Task, "b")
141
+ out = capture_stdout { @app.run }
142
+ assert @app.options.show_prereqs
143
+ assert ! ran
144
+ assert_match(/rake a$/, out)
145
+ assert_match(/rake b$/, out)
146
+ assert_match(/rake default\n( *(a|b)\n){2}/m, out)
147
+ end
148
+
149
+ def test_bad_run
150
+ @app.intern(Rake::Task, "default").enhance { fail }
151
+ ARGV.clear
152
+ ARGV << '-f' << '-s'
153
+ assert_raise(SystemExit) {
154
+ err = capture_stderr { @app.run }
155
+ assert_match(/see full trace/, err)
156
+ }
157
+ ensure
158
+ ARGV.clear
159
+ end
160
+
161
+ def test_bad_run_with_trace
162
+ @app.intern(Rake::Task, "default").enhance { fail }
163
+ ARGV.clear
164
+ ARGV << '-f' << '-s' << '-t'
165
+ assert_raise(SystemExit) {
166
+ err = capture_stderr { capture_stdout { @app.run } }
167
+ assert_no_match(/see full trace/, err)
168
+ }
169
+ ensure
170
+ ARGV.clear
171
+ end
172
+
173
+ def test_run_with_bad_options
174
+ @app.intern(Rake::Task, "default").enhance { fail }
175
+ ARGV.clear
176
+ ARGV << '-f' << '-s' << '--xyzzy'
177
+ assert_raise(SystemExit) {
178
+ err = capture_stderr { capture_stdout { @app.run } }
179
+ }
180
+ ensure
181
+ ARGV.clear
182
+ end
183
+
184
+ end
185
+
186
+
187
+ ######################################################################
188
+ class TestApplicationOptions < Test::Unit::TestCase
189
+ include CaptureStdout
190
+
191
+ def setup
192
+ clear_argv
193
+ RakeFileUtils.verbose_flag = false
194
+ RakeFileUtils.nowrite_flag = false
195
+ end
196
+
197
+ def teardown
198
+ clear_argv
199
+ RakeFileUtils.verbose_flag = false
200
+ RakeFileUtils.nowrite_flag = false
201
+ end
202
+
203
+ def clear_argv
204
+ while ! ARGV.empty?
205
+ ARGV.pop
206
+ end
207
+ end
208
+
209
+ def test_default_options
210
+ opts = command_line
211
+ assert_nil opts.show_task_pattern
212
+ assert_nil opts.dryrun
213
+ assert_nil opts.trace
214
+ assert_nil opts.nosearch
215
+ assert_nil opts.silent
216
+ assert_nil opts.show_prereqs
217
+ assert_nil opts.show_tasks
218
+ assert_nil opts.classic_namespace
219
+ assert_equal 'rakelib', opts.rakelib
220
+ assert ! RakeFileUtils.verbose_flag
221
+ assert ! RakeFileUtils.nowrite_flag
222
+ end
223
+
224
+ def test_trace_option
225
+ flags('--trace', '-t') do |opts|
226
+ assert opts.trace
227
+ assert RakeFileUtils.verbose_flag
228
+ assert ! RakeFileUtils.nowrite_flag
229
+ end
230
+ end
231
+
232
+ def test_dry_run
233
+ flags('--dry-run', '-n') do |opts|
234
+ assert opts.dryrun
235
+ assert opts.trace
236
+ assert RakeFileUtils.verbose_flag
237
+ assert RakeFileUtils.nowrite_flag
238
+ end
239
+ end
240
+
241
+ def test_help
242
+ flags('--help', '-H') do |opts, output|
243
+ assert_match(/\Arake/, @out)
244
+ assert_match(/--help/, @out)
245
+ assert_equal :exit, @exit
246
+ end
247
+ end
248
+
249
+ def test_usage
250
+ flags('--usage', '-h') do |opts, output|
251
+ assert_match(/\Arake/, @out)
252
+ assert_match(/\boptions\b/, @out)
253
+ assert_match(/\btargets\b/, @out)
254
+ assert_equal :exit, @exit
255
+ end
256
+ end
257
+
258
+ def test_libdir
259
+ flags(['--libdir', 'xx'], ['-I', 'xx'], ['-Ixx']) do |opts|
260
+ $:.include?('xx')
261
+ end
262
+ ensure
263
+ $:.delete('xx')
264
+ end
265
+
266
+ def test_nosearch
267
+ flags('--nosearch', '-N') do |opts|
268
+ assert opts.nosearch
269
+ end
270
+ end
271
+
272
+ def test_show_prereqs
273
+ flags('--prereqs', '-P') do |opts|
274
+ assert opts.show_prereqs
275
+ end
276
+ end
277
+
278
+ def test_quiet
279
+ flags('--quiet', '-q') do |opts|
280
+ assert ! RakeFileUtils.verbose_flag
281
+ assert ! opts.silent
282
+ end
283
+ end
284
+
285
+ def test_silent
286
+ flags('--silent', '-s') do |opts|
287
+ assert ! RakeFileUtils.verbose_flag
288
+ assert opts.silent
289
+ end
290
+ end
291
+
292
+ def test_rakefile
293
+ flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
294
+ assert_equal ['RF'], @app.instance_eval { @rakefiles }
295
+ end
296
+ end
297
+
298
+ def test_rakelib
299
+ flags(['--rakelibdir', 'A:B:C'], ['--rakelibdir=A:B:C'], ['-R', 'A:B:C'], ['-RA:B:C']) do |opts|
300
+ assert_equal ['A', 'B', 'C'], opts.rakelib
301
+ end
302
+ end
303
+
304
+ def test_require
305
+ flags(['--require', 'test/reqfile'], '-rtest/reqfile2', '-rtest/reqfile3') do |opts|
306
+ end
307
+ assert TESTING_REQUIRE.include?(1)
308
+ assert TESTING_REQUIRE.include?(2)
309
+ assert TESTING_REQUIRE.include?(3)
310
+ assert_equal 3, TESTING_REQUIRE.size
311
+ end
312
+
313
+ def test_missing_require
314
+ ex = assert_raises(LoadError) do
315
+ flags(['--require', 'test/missing']) do |opts|
316
+ end
317
+ end
318
+ assert_match(/no such file/, ex.message)
319
+ assert_match(/test\/missing/, ex.message)
320
+ end
321
+
322
+ def test_tasks
323
+ flags('--tasks', '-T') do |opts|
324
+ assert opts.show_tasks
325
+ assert_equal(//.to_s, opts.show_task_pattern.to_s)
326
+ end
327
+ flags(['--tasks', 'xyz'], ['-Txyz']) do |opts|
328
+ assert opts.show_tasks
329
+ assert_equal(/xyz/, opts.show_task_pattern)
330
+ end
331
+ end
332
+
333
+ def test_verbose
334
+ flags('--verbose', '-V') do |opts|
335
+ assert RakeFileUtils.verbose_flag
336
+ assert ! opts.silent
337
+ end
338
+ end
339
+
340
+ def test_version
341
+ flags('--version', '-V') do |opts|
342
+ assert_match(/\bversion\b/, @out)
343
+ assert_match(/\b#{RAKEVERSION}\b/, @out)
344
+ assert_equal :exit, @exit
345
+ end
346
+ end
347
+
348
+ def test_classic_namespace
349
+ flags(['--classic-namespace'], ['-C', '-T', '-P', '-n', '-s', '-t']) do |opts|
350
+ assert opts.classic_namespace
351
+ assert_equal opts.show_tasks, $show_tasks
352
+ assert_equal opts.show_prereqs, $show_prereqs
353
+ assert_equal opts.trace, $trace
354
+ assert_equal opts.dryrun, $dryrun
355
+ assert_equal opts.silent, $silent
356
+ end
357
+ end
358
+
359
+ def test_bad_option
360
+ capture_stderr do
361
+ ex = assert_raise(GetoptLong::InvalidOption) { flags('--bad-option') }
362
+ assert_match(/unrecognized option/, ex.message)
363
+ assert_match(/--bad-option/, ex.message)
364
+ end
365
+ end
366
+
367
+ def test_task_collection
368
+ command_line("a", "b")
369
+ assert_equal ["a", "b"], @tasks.sort
370
+ end
371
+
372
+ def test_default_task_collection
373
+ command_line()
374
+ assert_equal ["default"], @tasks
375
+ end
376
+
377
+ def test_environment_definition
378
+ ENV['TESTKEY'] = nil
379
+ command_line("a", "TESTKEY=12")
380
+ assert_equal ["a"], @tasks.sort
381
+ assert '12', ENV['TESTKEY']
382
+ end
383
+
384
+ private
385
+
386
+ def flags(*sets)
387
+ sets.each do |set|
388
+ @out = capture_stdout {
389
+ @exit = catch(:system_exit) { opts = command_line(*set) }
390
+ }
391
+ yield(@app.options)
392
+ end
393
+ end
394
+
395
+ def command_line(*options)
396
+ options.each do |opt| ARGV << opt end
397
+ @app = Rake::Application.new
398
+ def @app.exit(*args)
399
+ throw :system_exit, :exit
400
+ end
401
+ @app.handle_options
402
+ @tasks = @app.collect_tasks
403
+ @app.options
404
+ end
405
+ end
406
+