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

@@ -7,31 +7,26 @@ module Rake
7
7
 
8
8
  # Load the makefile dependencies in +fn+.
9
9
  def load(fn)
10
- buffer = ''
11
10
  open(fn) do |mf|
12
- mf.each do |line|
13
- next if line =~ /^\s*#/
14
- buffer << line
15
- if buffer =~ /\\$/
16
- buffer.sub!(/\\\n/, ' ')
17
- state = :append
18
- else
19
- process_line(buffer)
20
- buffer = ''
21
- end
11
+ lines = mf.read
12
+ lines.gsub!(/#[^\n]*\n/m, "")
13
+ lines.gsub!(/\\\n/, ' ')
14
+ lines.split("\n").each do |line|
15
+ process_line(line)
22
16
  end
23
17
  end
24
- process_line(buffer) if buffer != ''
25
18
  end
26
19
 
27
20
  private
28
21
 
29
22
  # Process one logical line of makefile data.
30
23
  def process_line(line)
31
- file_task, args = line.split(':')
24
+ file_tasks, args = line.split(':')
32
25
  return if args.nil?
33
26
  dependents = args.split
34
- file file_task => dependents
27
+ file_tasks.strip.split.each do |file_task|
28
+ file file_task => dependents
29
+ end
35
30
  end
36
31
  end
37
32
 
@@ -122,6 +122,7 @@ module Rake
122
122
  task :package => ["#{package_dir}/#{file}"]
123
123
  file "#{package_dir}/#{file}" => [package_dir_path] + package_files do
124
124
  chdir(package_dir) do
125
+ sh %{env}
125
126
  sh %{#{@tar_command} #{flag}cvf #{file} #{package_name}}
126
127
  end
127
128
  end
@@ -55,7 +55,7 @@ module Rake
55
55
  # RDoc. (default is none)
56
56
  attr_accessor :main
57
57
 
58
- # Name of template to be used by rdoc. (default is 'html')
58
+ # Name of template to be used by rdoc. (defaults to rdoc's default)
59
59
  attr_accessor :template
60
60
 
61
61
  # List of files to be included in the rdoc generation. (default is [])
@@ -74,7 +74,7 @@ module Rake
74
74
  @rdoc_dir = 'html'
75
75
  @main = nil
76
76
  @title = nil
77
- @template = 'html'
77
+ @template = nil
78
78
  @external = false
79
79
  @options = []
80
80
  yield self if block_given?
@@ -91,18 +91,18 @@ module Rake
91
91
  task name
92
92
 
93
93
  desc "Force a rebuild of the RDOC files"
94
- task paste("re", name) => [paste("clobber_", name), name]
94
+ task "re#{name}" => ["clobber_#{name}", name]
95
95
 
96
96
  desc "Remove rdoc products"
97
- task paste("clobber_", name) do
97
+ task "clobber_#{name}" do
98
98
  rm_r rdoc_dir rescue nil
99
99
  end
100
-
101
- task :clobber => [paste("clobber_", name)]
100
+
101
+ task :clobber => ["clobber_#{name}"]
102
102
 
103
103
  directory @rdoc_dir
104
104
  task name => [rdoc_target]
105
- file rdoc_target => @rdoc_files + [$rakefile] do
105
+ file rdoc_target => @rdoc_files + [Rake.application.rakefile] do
106
106
  rm_r @rdoc_dir rescue nil
107
107
  args = option_list + @rdoc_files
108
108
  if @external
File without changes
@@ -6,11 +6,16 @@ module Rake
6
6
 
7
7
  # Base class for Task Libraries.
8
8
  class TaskLib
9
-
10
9
  include Cloneable
11
10
 
12
- # Make a symbol by pasting two strings together.
13
- def paste(a,b)
11
+ # Make a symbol by pasting two strings together.
12
+ #
13
+ # NOTE: DEPRECATED! This method is kinda stupid. I don't know why
14
+ # I didn't just use string interpolation. But now other task
15
+ # libraries depend on this so I can't remove it without breaking
16
+ # other people's code. So for now it stays for backwards
17
+ # compatibility. BUT DON'T USE IT.
18
+ def paste(a,b) # :nodoc:
14
19
  (a.to_s + b.to_s).intern
15
20
  end
16
21
  end
@@ -0,0 +1,5 @@
1
+ if ARGV[0] != ARGV[1]
2
+ exit 1
3
+ else
4
+ exit 0
5
+ end
File without changes
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
1
3
  N = 2
2
4
 
3
5
  task :default => :run
@@ -17,7 +19,7 @@ FileList['src/*'].each do |src|
17
19
  target = File.join TARGET_DIR, File.basename(src)
18
20
  file target => [src, TARGET_DIR] do
19
21
  cp src, target
20
- sleep 3 if src !~ /foo#{N-1}$/
22
+ # sleep 3 if src !~ /foo#{N-1}$/ # I'm commenting out this sleep, it doesn't seem to do anything.
21
23
  end
22
24
  task :run => target
23
25
  end
@@ -25,6 +27,7 @@ end
25
27
  task :prep => :clean do
26
28
  mkdir_p 'src'
27
29
  N.times do |n|
30
+ puts "DBG: Touching src/foo#{n}"
28
31
  touch "src/foo#{n}"
29
32
  end
30
33
  end
@@ -4,6 +4,9 @@ b: b1 b2 b3 \
4
4
  b4 b5 b6\
5
5
  # Mid: Comment
6
6
  b7
7
- a: a5 a6 a7
7
+
8
+ a : a5 a6 a7
8
9
  c: c1
9
10
  d: d1 d2 \
11
+
12
+ e f : e1 f1
@@ -6,7 +6,7 @@ begin
6
6
  require 'session'
7
7
  rescue LoadError
8
8
  puts "UNABLE TO RUN FUNCTIONAL TESTS"
9
- puts "No Session Found"
9
+ puts "No Session Found (gem install session)"
10
10
  end
11
11
 
12
12
  if defined?(Session)
@@ -0,0 +1,30 @@
1
+ module InEnvironment
2
+ private
3
+
4
+ # Create an environment for a test. At the completion of the yielded
5
+ # block, the environment is restored to its original conditions.
6
+ def in_environment(settings)
7
+ original_settings = set_env(settings)
8
+ yield
9
+ ensure
10
+ set_env(original_settings)
11
+ end
12
+
13
+ # Set the environment according to the settings hash.
14
+ def set_env(settings) # :nodoc:
15
+ result = {}
16
+ settings.each do |k, v|
17
+ result[k] = ENV[k]
18
+ if k == 'PWD'
19
+ result[k] = Dir.pwd
20
+ Dir.chdir(v)
21
+ elsif v.nil?
22
+ ENV.delete(k)
23
+ else
24
+ ENV[k] = v
25
+ end
26
+ end
27
+ result
28
+ end
29
+
30
+ end
@@ -1,8 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ begin
4
+ require 'rubygems'
5
+ rescue LoadError => ex
6
+ end
3
7
  require 'test/unit'
4
8
  require 'fileutils'
5
9
  require 'session'
10
+ require 'test/in_environment'
6
11
 
7
12
  # Version 2.1.9 of session has a bug where the @debug instance
8
13
  # variable is not initialized, causing warning messages. This snippet
@@ -18,13 +23,12 @@ module Session
18
23
  end
19
24
 
20
25
  class FunctionalTest < Test::Unit::TestCase
26
+ include InEnvironment
21
27
 
22
28
  RUBY_COMMAND = 'ruby'
23
29
 
24
30
  def setup
25
31
  @rake_path = File.expand_path("bin/rake")
26
- @coverage_aggregate_file = File.expand_path("rcov_aggregate")
27
- @rcov_dir = File.expand_path("coverage")
28
32
  lib_path = File.expand_path("lib")
29
33
  @ruby_options = "-I#{lib_path} -I."
30
34
  @verbose = ! ENV['VERBOSE'].nil?
@@ -62,15 +66,22 @@ class FunctionalTest < Test::Unit::TestCase
62
66
  end
63
67
 
64
68
  def test_multi_desc
65
- Dir.chdir("test/data/multidesc") do rake "-T" end
69
+ in_environment(
70
+ 'RAKE_COLUMNS' => "80",
71
+ "PWD" => "test/data/multidesc"
72
+ ) do
73
+ rake "-T"
74
+ end
66
75
  assert_match %r{^rake a *# A / A2 *$}, @out
67
76
  assert_match %r{^rake b *# B *$}, @out
68
77
  assert_no_match %r{^rake c}, @out
69
78
  assert_match %r{^rake d *# x{65}\.\.\.$}, @out
70
79
  end
71
-
80
+
72
81
  def test_long_description
73
- Dir.chdir("test/data/multidesc") do rake "--describe" end
82
+ in_environment("PWD" => "test/data/multidesc") do
83
+ rake "--describe"
84
+ end
74
85
  assert_match %r{^rake a\n *A / A2 *$}m, @out
75
86
  assert_match %r{^rake b\n *B *$}m, @out
76
87
  assert_match %r{^rake d\n *x{80}}m, @out
@@ -78,17 +89,73 @@ class FunctionalTest < Test::Unit::TestCase
78
89
  end
79
90
 
80
91
  def test_rbext
81
- Dir.chdir("test/data/rbext") do rake "-N" end
92
+ in_environment("PWD" => "test/data/rbext") do
93
+ rake "-N"
94
+ end
82
95
  assert_match %r{^OK$}, @out
83
96
  end
84
97
 
85
- def test_nosearch
86
- Dir.chdir("test/data/nosearch") do rake "-N" end
98
+ def test_system
99
+ in_environment('RAKE_SYSTEM' => 'test/data/sys') do
100
+ rake '-g', "sys1"
101
+ end
102
+ assert_match %r{^SYS1}, @out
103
+ end
104
+
105
+ def test_system_excludes_rakelib_files_too
106
+ in_environment('RAKE_SYSTEM' => 'test/data/sys') do
107
+ rake '-g', "sys1", '-T', 'extra'
108
+ end
109
+ assert_no_match %r{extra:extra}, @out
110
+ end
111
+
112
+ def test_by_default_rakelib_files_are_include
113
+ in_environment('RAKE_SYSTEM' => 'test/data/sys') do
114
+ rake '-T', 'extra'
115
+ end
116
+ assert_match %r{extra:extra}, @out
117
+ end
118
+
119
+ def test_implicit_system
120
+ in_environment('RAKE_SYSTEM' => File.expand_path('test/data/sys'), "PWD" => "/") do
121
+ rake "sys1", "--trace"
122
+ end
123
+ assert_match %r{^SYS1}, @out
124
+ end
125
+
126
+ def test_no_system
127
+ in_environment('RAKE_SYSTEM' => 'test/data/sys') do
128
+ rake '-G', "sys1"
129
+ end
130
+ assert_match %r{^Don't know how to build task}, @err # emacs wart: '
131
+ end
132
+
133
+ def test_nosearch_with_rakefile_uses_local_rakefile
134
+ in_environment("PWD" => "test/data/default") do
135
+ rake "--nosearch"
136
+ end
137
+ assert_match %r{^DEFAULT}, @out
138
+ end
139
+
140
+ def test_nosearch_without_rakefile_finds_system
141
+ in_environment(
142
+ "PWD" => "test/data/nosearch",
143
+ "RAKE_SYSTEM" => File.expand_path("test/data/sys")
144
+ ) do
145
+ rake "--nosearch", "sys1"
146
+ end
147
+ assert_match %r{^SYS1}, @out
148
+ end
149
+
150
+ def test_nosearch_without_rakefile_and_no_system_fails
151
+ in_environment("PWD" => "test/data/nosearch", "RAKE_SYSTEM" => "not_exist") do
152
+ rake "--nosearch"
153
+ end
87
154
  assert_match %r{^No Rakefile found}, @err
88
155
  end
89
156
 
90
157
  def test_dry_run
91
- Dir.chdir("test/data/default") do rake "-n", "other" end
158
+ in_environment("PWD" => "test/data/default") do rake "-n", "other" end
92
159
  assert_match %r{Execute \(dry run\) default}, @out
93
160
  assert_match %r{Execute \(dry run\) other}, @out
94
161
  assert_no_match %r{DEFAULT}, @out
@@ -97,18 +164,26 @@ class FunctionalTest < Test::Unit::TestCase
97
164
 
98
165
  # Test for the trace/dry_run bug found by Brian Chandler
99
166
  def test_dry_run_bug
100
- Dir.chdir("test/data/dryrun") do rake end
167
+ in_environment("PWD" => "test/data/dryrun") do
168
+ rake
169
+ end
101
170
  FileUtils.rm_f "test/data/dryrun/temp_one"
102
- Dir.chdir("test/data/dryrun") do rake "--dry-run" end
171
+ in_environment("PWD" => "test/data/dryrun") do
172
+ rake "--dry-run"
173
+ end
103
174
  assert_no_match(/No such file/, @out)
104
175
  assert_status
105
176
  end
106
177
 
107
178
  # Test for the trace/dry_run bug found by Brian Chandler
108
179
  def test_trace_bug
109
- Dir.chdir("test/data/dryrun") do rake end
180
+ in_environment("PWD" => "test/data/dryrun") do
181
+ rake
182
+ end
110
183
  FileUtils.rm_f "test/data/dryrun/temp_one"
111
- Dir.chdir("test/data/dryrun") do rake "--trace" end
184
+ in_environment("PWD" => "test/data/dryrun") do
185
+ rake "--trace"
186
+ end
112
187
  assert_no_match(/No such file/, @out)
113
188
  assert_status
114
189
  end
@@ -118,7 +193,9 @@ class FunctionalTest < Test::Unit::TestCase
118
193
  f.puts 'puts "STATIC"'
119
194
  end
120
195
  FileUtils.rm_f "test/data/imports/dynamic_deps"
121
- Dir.chdir("test/data/imports") do rake end
196
+ in_environment("PWD" => "test/data/imports") do
197
+ rake
198
+ end
122
199
  assert File.exist?("test/data/imports/dynamic_deps"),
123
200
  "'dynamic_deps' file should exist"
124
201
  assert_match(/^FIRST$\s+^DYNAMIC$\s+^STATIC$\s+^OTHER$/, @out)
@@ -129,7 +206,9 @@ class FunctionalTest < Test::Unit::TestCase
129
206
 
130
207
  def test_rules_chaining_to_file_task
131
208
  remove_chaining_files
132
- Dir.chdir("test/data/chains") do rake end
209
+ in_environment("PWD" => "test/data/chains") do
210
+ rake
211
+ end
133
212
  assert File.exist?("test/data/chains/play.app"),
134
213
  "'play.app' file should exist"
135
214
  assert_status
@@ -137,12 +216,12 @@ class FunctionalTest < Test::Unit::TestCase
137
216
  end
138
217
 
139
218
  def test_file_creation_task
140
- Dir.chdir("test/data/file_creation_task") do
219
+ in_environment("PWD" => "test/data/file_creation_task") do
141
220
  rake "prep"
142
221
  rake "run"
143
222
  rake "run"
144
- assert(@err !~ /^cp src/, "Should not recopy data")
145
223
  end
224
+ assert(@err !~ /^cp src/, "Should not recopy data")
146
225
  end
147
226
 
148
227
  def test_dash_f_with_no_arg_foils_rakefile_lookup
@@ -150,69 +229,69 @@ class FunctionalTest < Test::Unit::TestCase
150
229
  assert_match(/^TEST1$/, @out)
151
230
  end
152
231
 
153
- def test_dot_rake_files_can_be_laoded_with_dash_r
232
+ def test_dot_rake_files_can_be_loaded_with_dash_r
154
233
  rake "-I test/data/rakelib -rtest2 -f"
155
234
  assert_match(/^TEST2$/, @out)
156
235
  end
157
236
 
158
237
  def test_can_invoke_task_in_toplevel_namespace
159
- Dir.chdir("test/data/namespace") do
238
+ in_environment("PWD" => "test/data/namespace") do
160
239
  rake "copy"
161
- assert_match(/^COPY$/, @out)
162
240
  end
241
+ assert_match(/^COPY$/, @out)
163
242
  end
164
243
 
165
244
  def test_can_invoke_task_in_nested_namespace
166
- Dir.chdir("test/data/namespace") do
245
+ in_environment("PWD" => "test/data/namespace") do
167
246
  rake "nest:copy"
168
247
  assert_match(/^NEST COPY$/, @out)
169
248
  end
170
249
  end
171
250
 
172
251
  def test_tasks_can_reference_task_in_same_namespace
173
- Dir.chdir("test/data/namespace") do
252
+ in_environment("PWD" => "test/data/namespace") do
174
253
  rake "nest:xx"
175
254
  assert_match(/^NEST COPY$/m, @out)
176
255
  end
177
256
  end
178
257
 
179
258
  def test_tasks_can_reference_task_in_other_namespaces
180
- Dir.chdir("test/data/namespace") do
259
+ in_environment("PWD" => "test/data/namespace") do
181
260
  rake "b:run"
182
261
  assert_match(/^IN A\nIN B$/m, @out)
183
262
  end
184
263
  end
185
264
 
186
265
  def test_anonymous_tasks_can_be_invoked_indirectly
187
- Dir.chdir("test/data/namespace") do
266
+ in_environment("PWD" => "test/data/namespace") do
188
267
  rake "anon"
189
268
  assert_match(/^ANON COPY$/m, @out)
190
269
  end
191
270
  end
192
271
 
193
272
  def test_rake_namespace_refers_to_toplevel
194
- Dir.chdir("test/data/namespace") do
273
+ in_environment("PWD" => "test/data/namespace") do
195
274
  rake "very:nested:run"
196
275
  assert_match(/^COPY$/m, @out)
197
276
  end
198
277
  end
199
278
 
200
279
  def test_file_task_are_not_scoped_by_namespaces
201
- Dir.chdir("test/data/namespace") do
280
+ in_environment("PWD" => "test/data/namespace") do
202
281
  rake "xyz.rb"
203
282
  assert_match(/^XYZ1\nXYZ2$/m, @out)
204
283
  end
205
284
  end
206
285
 
207
286
  def test_rake_returns_status_error_values
208
- Dir.chdir("test/data/statusreturn") do
287
+ in_environment("PWD" => "test/data/statusreturn") do
209
288
  rake "exit5"
210
289
  assert_status(5)
211
290
  end
212
291
  end
213
292
 
214
293
  def test_rake_returns_no_status_error_on_normal_exit
215
- Dir.chdir("test/data/statusreturn") do
294
+ in_environment("PWD" => "test/data/statusreturn") do
216
295
  rake "normal"
217
296
  assert_status(0)
218
297
  end
@@ -239,10 +318,6 @@ class FunctionalTest < Test::Unit::TestCase
239
318
  end
240
319
 
241
320
  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
-
246
321
  options = option_list.join(' ')
247
322
  shell = Session::Shell.new
248
323
  command = self.class.format_command[@ruby_options, @rake_path, options]
@@ -259,5 +334,4 @@ class FunctionalTest < Test::Unit::TestCase
259
334
  def assert_status(expected_status=0)
260
335
  assert_equal expected_status, @status
261
336
  end
262
-
263
337
  end