rake 0.8.3 → 0.8.4

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.

@@ -0,0 +1,145 @@
1
+ #
2
+ # Copyright (c) 2008 James M. Lawrence
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person
5
+ # obtaining a copy of this software and associated documentation files
6
+ # (the "Software"), to deal in the Software without restriction,
7
+ # including without limitation the rights to use, copy, modify, merge,
8
+ # publish, distribute, sublicense, and/or sell copies of the Software,
9
+ # and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
+ # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
+ # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+ #
24
+
25
+ require 'rbconfig'
26
+
27
+ module Rake
28
+ end
29
+
30
+ #
31
+ # Alternate implementations of system() and backticks `` for Windows.
32
+ #
33
+ module Rake::RepairedSystem
34
+ class << self
35
+ def define_module_function(name, &block)
36
+ define_method(name, &block)
37
+ module_function(name)
38
+ end
39
+ end
40
+
41
+ if Config::CONFIG["host_os"] !~ %r!(msdos|mswin|djgpp|mingw)!
42
+ define_module_function :system, &Kernel.method(:system)
43
+ define_module_function :'`', &Kernel.method(:'`')
44
+ else
45
+ BINARY_EXTS = %w[com exe]
46
+
47
+ BATCHFILE_EXTS = %w[bat] +
48
+ if (t = ENV["COMSPEC"]) and t =~ %r!command\.exe\Z!i
49
+ []
50
+ else
51
+ %w[cmd]
52
+ end
53
+
54
+ RUNNABLE_EXTS = BINARY_EXTS + BATCHFILE_EXTS
55
+
56
+ RUNNABLE_PATTERN, BINARY_PATTERN, BATCHFILE_PATTERN =
57
+ [RUNNABLE_EXTS, BINARY_EXTS, BATCHFILE_EXTS].map { |exts|
58
+ if exts.size > 1
59
+ %r!\.(#{exts.join('|')})\Z!i
60
+ else
61
+ %r!\.#{exts.first}\Z!i
62
+ end
63
+ }
64
+
65
+ define_module_function :system_previous, &Kernel.method(:system)
66
+ define_module_function :backticks_previous, &Kernel.method(:'`')
67
+
68
+ module_function
69
+
70
+ def repair_command(cmd)
71
+ if (match = cmd.match(%r!\A\s*\"(.*?)\"!)) or
72
+ (match = cmd.match(%r!\A(\S+)!))
73
+ if runnable = find_runnable(match.captures.first)
74
+ quote(to_backslashes(runnable)) + match.post_match
75
+ else
76
+ cmd
77
+ end
78
+ else
79
+ cmd
80
+ end
81
+ end
82
+
83
+ def join_command(*args)
84
+ first =
85
+ if args.first =~ %r!\s!
86
+ quote(args.first)
87
+ else
88
+ args.first
89
+ end
90
+ [to_backslashes(first), *tail(args)].join(" ")
91
+ end
92
+
93
+ def to_backslashes(string)
94
+ string.gsub("/", "\\")
95
+ end
96
+
97
+ def quote(string)
98
+ %Q!"#{string}"!
99
+ end
100
+
101
+ def tail(array)
102
+ array[1..-1]
103
+ end
104
+
105
+ def find_runnable(file)
106
+ if file =~ RUNNABLE_PATTERN
107
+ file
108
+ else
109
+ [nil, ".", *ENV["PATH"].split(";")].each { |path|
110
+ RUNNABLE_EXTS.each { |ext|
111
+ test = (path ? "#{path}/" : "") + "#{file}.#{ext}"
112
+ if File.exist?(test)
113
+ return test
114
+ end
115
+ }
116
+ }
117
+ nil
118
+ end
119
+ end
120
+
121
+ def system(cmd, *args)
122
+ file = cmd.to_s
123
+ repaired_args =
124
+ if args.empty?
125
+ [repair_command(file)]
126
+ elsif file =~ BATCHFILE_PATTERN
127
+ [ENV["COMSPEC"], "/c", to_backslashes(File.expand_path(file)), *args]
128
+ elsif runnable = find_runnable(file)
129
+ [to_backslashes(File.expand_path(runnable)), *args]
130
+ else
131
+ # maybe a built-in shell command
132
+ [join_command(file, *args)]
133
+ end
134
+ if repaired_args.size == 1
135
+ system_previous("call #{repaired_args.first}")
136
+ else
137
+ system_previous(*repaired_args)
138
+ end
139
+ end
140
+
141
+ def `(cmd) #`
142
+ backticks_previous(repair_command(cmd))
143
+ end
144
+ end
145
+ end
@@ -95,7 +95,7 @@ module Rake
95
95
 
96
96
  # Create the tasks defined by this task lib.
97
97
  def define
98
- lib_path = @libs.join(File::PATH_SEPARATOR)
98
+ lib_path = @libs.collect {|path| "-I\"#{File.expand_path(path)}\""}.join(' ')
99
99
  desc "Run tests" + (@name==:test ? "" : " for #{@name}")
100
100
  task @name do
101
101
  run_code = ''
@@ -109,7 +109,7 @@ module Rake
109
109
  when :rake
110
110
  rake_loader
111
111
  end
112
- @ruby_opts.unshift( "-I#{lib_path}" )
112
+ @ruby_opts.unshift( lib_path )
113
113
  @ruby_opts.unshift( "-w" ) if @warning
114
114
  ruby @ruby_opts.join(" ") +
115
115
  " \"#{run_code}\" " +
@@ -1,3 +1,6 @@
1
+
2
+ require 'rake/repaired_system'
3
+
1
4
  module Rake
2
5
 
3
6
  # Win 32 interface methods for Rake. Windows specific functionality
@@ -12,38 +15,37 @@ module Rake
12
15
  class << self
13
16
  # True if running on a windows system.
14
17
  def windows?
15
- Config::CONFIG['host_os'] =~ /mswin/
18
+ Config::CONFIG['host_os'] =~ /mswin|mingw/
16
19
  end
17
20
 
18
21
  # Run a command line on windows.
19
22
  def rake_system(*cmd)
20
- if cmd.size == 1
21
- system("call #{cmd}")
22
- else
23
- system(*cmd)
24
- end
23
+ RepairedSystem.system(*cmd)
25
24
  end
26
25
 
27
26
  # The standard directory containing system wide rake files on
28
27
  # Win 32 systems. Try the following environment variables (in
29
28
  # order):
30
29
  #
31
- # * APPDATA
30
+ # * HOME
32
31
  # * HOMEDRIVE + HOMEPATH
32
+ # * APPDATA
33
33
  # * USERPROFILE
34
34
  #
35
35
  # If the above are not defined, the return nil.
36
36
  def win32_system_dir #:nodoc:
37
- win32_shared_path = ENV['APPDATA']
37
+ win32_shared_path = ENV['HOME']
38
38
  if win32_shared_path.nil? && ENV['HOMEDRIVE'] && ENV['HOMEPATH']
39
39
  win32_shared_path = ENV['HOMEDRIVE'] + ENV['HOMEPATH']
40
40
  end
41
+
42
+ win32_shared_path ||= ENV['APPDATA']
41
43
  win32_shared_path ||= ENV['USERPROFILE']
42
44
  raise Win32HomeError, "Unable to determine home path environment variable." if
43
45
  win32_shared_path.nil? or win32_shared_path.empty?
44
46
  normalize(File.join(win32_shared_path, 'Rake'))
45
47
  end
46
-
48
+
47
49
  # Normalize a win32 path so that the slashes are all forward slashes.
48
50
  def normalize(path)
49
51
  path.gsub(/\\/, '/')
@@ -10,3 +10,5 @@ c: c1
10
10
  d: d1 d2 \
11
11
 
12
12
  e f : e1 f1
13
+
14
+ g\ 0: g1 g\ 2 g\ 3 g4
@@ -8,3 +8,17 @@ rescue LoadError
8
8
  end
9
9
 
10
10
  require 'flexmock/test_unit'
11
+
12
+ if RUBY_VERSION >= "1.9.0"
13
+ class Test::Unit::TestCase
14
+ # def passed?
15
+ # true
16
+ # end
17
+ end
18
+ end
19
+
20
+ module TestMethods
21
+ def assert_exception(ex, msg=nil, &block)
22
+ assert_raise(ex, msg, &block)
23
+ end
24
+ end
@@ -8,6 +8,7 @@ require 'test/unit'
8
8
  require 'fileutils'
9
9
  require 'session'
10
10
  require 'test/in_environment'
11
+ require 'test/rake_test_setup'
11
12
 
12
13
  # Version 2.1.9 of session has a bug where the @debug instance
13
14
  # variable is not initialized, causing warning messages. This snippet
@@ -24,6 +25,7 @@ end
24
25
 
25
26
  class FunctionalTest < Test::Unit::TestCase
26
27
  include InEnvironment
28
+ include TestMethods
27
29
 
28
30
  RUBY_COMMAND = 'ruby'
29
31
 
@@ -18,6 +18,7 @@ TESTING_REQUIRE = [ ]
18
18
  class TestApplication < Test::Unit::TestCase
19
19
  include CaptureStdout
20
20
  include InEnvironment
21
+ include TestMethods
21
22
 
22
23
  def setup
23
24
  @app = Rake::Application.new
@@ -109,7 +110,7 @@ class TestApplication < Test::Unit::TestCase
109
110
  end
110
111
 
111
112
  def test_finding_rakefile
112
- assert_match(/[Rr]akefile/, @app.instance_eval { have_rakefile })
113
+ assert_match(/Rakefile/i, @app.instance_eval { have_rakefile })
113
114
  end
114
115
 
115
116
  def test_not_finding_rakefile
@@ -148,7 +149,7 @@ class TestApplication < Test::Unit::TestCase
148
149
  handle_options
149
150
  options.silent = true
150
151
  end
151
- ex = assert_raise(RuntimeError) do
152
+ ex = assert_exception(RuntimeError) do
152
153
  @app.instance_eval do raw_load_rakefile end
153
154
  end
154
155
  assert_match(/no rakefile found/i, ex.message)
@@ -162,6 +163,7 @@ class TestApplication < Test::Unit::TestCase
162
163
  handle_options
163
164
  options.silent = true
164
165
  options.load_system = true
166
+ options.rakelib = []
165
167
  load_rakefile
166
168
  end
167
169
  assert_equal "test/data/sys", @app.system_dir
@@ -170,9 +172,9 @@ class TestApplication < Test::Unit::TestCase
170
172
  end
171
173
 
172
174
  def test_load_from_system_rakefile_on_unix
173
- flexmock(@app, :windows? => false,
174
- :win32_system_dir => nil,
175
- :load => nil)
175
+ flexmock(Rake::Win32, :windows? => false,
176
+ :win32_system_dir => nil)
177
+ flexmock(@app, :load => nil)
176
178
  flexmock(File).should_receive(:expand_path).with("~").and_return("/HOME")
177
179
  flexmock(File).should_receive(:expand_path).and_return { |fn| fn }
178
180
 
@@ -182,6 +184,7 @@ class TestApplication < Test::Unit::TestCase
182
184
  handle_options
183
185
  options.silent = true
184
186
  options.load_system = true
187
+ options.rakelib = []
185
188
  load_rakefile
186
189
  end
187
190
  assert_equal "/HOME/.rake", @app.system_dir
@@ -195,17 +198,18 @@ class TestApplication < Test::Unit::TestCase
195
198
  def test_load_from_system_rakefile_on_windows
196
199
  flexmock(Rake::Win32, :windows? => true)
197
200
  flexmock(@app, :standard_system_dir => "XX")
198
- flexmock(@app).should_receive(:directory?).with("/AD/Rake").and_return(true)
199
201
  flexmock(@app).should_receive(:load).and_return(nil)
200
- in_environment('RAKE_SYSTEM' => nil, 'APPDATA' => '/AD') do
202
+ flexmock(File).should_receive(:directory?).with("C:/AD/Rake").and_return(true)
203
+ in_environment('RAKE_SYSTEM' => nil, 'HOME' => nil, 'HOMEDRIVE' => 'C:', 'HOMEPATH' => '\\AD') do
201
204
  @app.options.rakelib = []
202
205
  @app.instance_eval do
203
206
  handle_options
204
207
  options.silent = true
205
208
  options.load_system = true
209
+ options.rakelib = []
206
210
  load_rakefile
207
211
  end
208
- assert_equal "/AD/Rake", @app.system_dir
212
+ assert_equal "C:/AD/Rake", @app.system_dir
209
213
  end
210
214
  end
211
215
 
@@ -231,6 +235,19 @@ class TestApplication < Test::Unit::TestCase
231
235
  end
232
236
  end
233
237
 
238
+ def test_handle_options__should_strip_options_from_ARGV
239
+ assert !@app.options.trace
240
+
241
+ valid_option = '--trace'
242
+ ARGV.clear
243
+ ARGV << valid_option
244
+
245
+ @app.handle_options
246
+
247
+ assert !ARGV.include?(valid_option)
248
+ assert @app.options.trace
249
+ end
250
+
234
251
  def test_good_run
235
252
  ran = false
236
253
  ARGV.clear
@@ -279,7 +296,7 @@ class TestApplication < Test::Unit::TestCase
279
296
  @app.intern(Rake::Task, "default").enhance { fail }
280
297
  ARGV.clear
281
298
  ARGV << '-f' << '-s' << '--rakelib=""'
282
- assert_raise(SystemExit) {
299
+ assert_exception(SystemExit) {
283
300
  err = capture_stderr { @app.run }
284
301
  assert_match(/see full trace/, err)
285
302
  }
@@ -291,7 +308,7 @@ class TestApplication < Test::Unit::TestCase
291
308
  @app.intern(Rake::Task, "default").enhance { fail }
292
309
  ARGV.clear
293
310
  ARGV << '-f' << '-s' << '-t'
294
- assert_raise(SystemExit) {
311
+ assert_exception(SystemExit) {
295
312
  err = capture_stderr { capture_stdout { @app.run } }
296
313
  assert_no_match(/see full trace/, err)
297
314
  }
@@ -303,7 +320,7 @@ class TestApplication < Test::Unit::TestCase
303
320
  @app.intern(Rake::Task, "default").enhance { fail }
304
321
  ARGV.clear
305
322
  ARGV << '-f' << '-s' << '--xyzzy'
306
- assert_raise(SystemExit) {
323
+ assert_exception(SystemExit) {
307
324
  err = capture_stderr { capture_stdout { @app.run } }
308
325
  }
309
326
  ensure
@@ -315,6 +332,7 @@ end
315
332
  ######################################################################
316
333
  class TestApplicationOptions < Test::Unit::TestCase
317
334
  include CaptureStdout
335
+ include TestMethods
318
336
 
319
337
  def setup
320
338
  clear_argv
@@ -447,7 +465,7 @@ class TestApplicationOptions < Test::Unit::TestCase
447
465
  end
448
466
 
449
467
  def test_missing_require
450
- ex = assert_raises(LoadError) do
468
+ ex = assert_exception(LoadError) do
451
469
  flags(['--require', 'test/missing']) do |opts|
452
470
  end
453
471
  end
@@ -546,7 +564,7 @@ class TestApplicationOptions < Test::Unit::TestCase
546
564
 
547
565
  def test_bad_option
548
566
  capture_stderr do
549
- ex = assert_raise(OptionParser::InvalidOption) do
567
+ ex = assert_exception(OptionParser::InvalidOption) do
550
568
  flags('--bad-option')
551
569
  end
552
570
  if ex.message =~ /^While/ # Ruby 1.9 error message
@@ -594,7 +612,8 @@ class TestApplicationOptions < Test::Unit::TestCase
594
612
  throw :system_exit, :exit
595
613
  end
596
614
  @app.instance_eval do
597
- collect_tasks handle_options
615
+ handle_options
616
+ collect_tasks
598
617
  end
599
618
  @tasks = @app.top_level_tasks
600
619
  @app.options
@@ -4,10 +4,13 @@ require 'test/unit'
4
4
  require 'fileutils'
5
5
  require 'rake'
6
6
  require 'test/filecreation'
7
+ require 'test/rake_test_setup'
7
8
 
8
9
  ######################################################################
9
10
  class TestDefinitions < Test::Unit::TestCase
10
11
  include Rake
12
+ include TestMethods
13
+
11
14
  EXISTINGFILE = "testdata/existing"
12
15
 
13
16
  def setup
@@ -58,7 +61,7 @@ class TestDefinitions < Test::Unit::TestCase
58
61
 
59
62
  def test_missing_dependencies
60
63
  task :x => ["testdata/missing"]
61
- assert_raises(RuntimeError) { Task[:x].invoke }
64
+ assert_exception(RuntimeError) { Task[:x].invoke }
62
65
  end
63
66
 
64
67
  def test_implicit_file_dependencies
@@ -4,11 +4,13 @@ require 'test/unit'
4
4
  require 'fileutils'
5
5
  require 'rake'
6
6
  require 'test/filecreation'
7
+ require 'test/rake_test_setup'
7
8
 
8
9
  ######################################################################
9
10
  class TestFileTask < Test::Unit::TestCase
10
11
  include Rake
11
12
  include FileCreation
13
+ include TestMethods
12
14
 
13
15
  def setup
14
16
  Task.clear
@@ -118,22 +120,24 @@ class TestDirectoryTask < Test::Unit::TestCase
118
120
  assert ! File.exist?("testdata/a/b/c")
119
121
  end
120
122
 
121
- def test_directory_win32
122
- desc "WIN32 DESC"
123
- FileUtils.mkdir_p("testdata")
124
- Dir.chdir("testdata") do
125
- directory 'c:/testdata/a/b/c'
126
- assert_equal FileCreationTask, Task['c:/testdata'].class
127
- assert_equal FileCreationTask, Task['c:/testdata/a'].class
128
- assert_equal FileCreationTask, Task['c:/testdata/a/b/c'].class
129
- assert_nil Task['c:/testdata'].comment
130
- assert_equal "WIN32 DESC", Task['c:/testdata/a/b/c'].comment
131
- assert_nil Task['c:/testdata/a/b'].comment
132
- verbose(false) {
133
- Task['c:/testdata/a/b'].invoke
134
- }
135
- assert File.exist?('c:/testdata/a/b')
136
- assert ! File.exist?('c:/testdata/a/b/c')
123
+ if Rake::Win32.windows?
124
+ def test_directory_win32
125
+ desc "WIN32 DESC"
126
+ FileUtils.mkdir_p("testdata")
127
+ Dir.chdir("testdata") do
128
+ directory 'c:/testdata/a/b/c'
129
+ assert_equal FileCreationTask, Task['c:/testdata'].class
130
+ assert_equal FileCreationTask, Task['c:/testdata/a'].class
131
+ assert_equal FileCreationTask, Task['c:/testdata/a/b/c'].class
132
+ assert_nil Task['c:/testdata'].comment
133
+ assert_equal "WIN32 DESC", Task['c:/testdata/a/b/c'].comment
134
+ assert_nil Task['c:/testdata/a/b'].comment
135
+ verbose(false) {
136
+ Task['c:/testdata/a/b'].invoke
137
+ }
138
+ assert File.exist?('c:/testdata/a/b')
139
+ assert ! File.exist?('c:/testdata/a/b/c')
140
+ end
137
141
  end
138
142
  end
139
143
  end