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.

@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake'
5
+
6
+ ######################################################################
7
+ class TestAnEmptyInvocationChain < Test::Unit::TestCase
8
+
9
+ def setup
10
+ @empty = Rake::InvocationChain::EMPTY
11
+ end
12
+
13
+ def test_should_be_able_to_add_members
14
+ assert_nothing_raised do
15
+ @empty.append("A")
16
+ end
17
+ end
18
+
19
+ def test_to_s
20
+ assert_equal "TOP", @empty.to_s
21
+ end
22
+ end
23
+
24
+ ######################################################################
25
+ class TestAnInvocationChainWithOneMember < Test::Unit::TestCase
26
+ def setup
27
+ @empty = Rake::InvocationChain::EMPTY
28
+ @first_member = "A"
29
+ @chain = @empty.append(@first_member)
30
+ end
31
+
32
+ def test_should_report_first_member_as_a_member
33
+ assert @chain.member?(@first_member)
34
+ end
35
+
36
+ def test_should_fail_when_adding_original_member
37
+ ex = assert_raise RuntimeError do
38
+ @chain.append(@first_member)
39
+ end
40
+ assert_match(/circular +dependency/i, ex.message)
41
+ assert_match(/A.*=>.*A/, ex.message)
42
+ end
43
+
44
+ def test_to_s
45
+ assert_equal "TOP => A", @chain.to_s
46
+ end
47
+
48
+ end
49
+
50
+ ######################################################################
51
+ class TestAnInvocationChainWithMultipleMember < Test::Unit::TestCase
52
+ def setup
53
+ @first_member = "A"
54
+ @second_member = "B"
55
+ ch = Rake::InvocationChain::EMPTY.append(@first_member)
56
+ @chain = ch.append(@second_member)
57
+ end
58
+
59
+ def test_should_report_first_member_as_a_member
60
+ assert @chain.member?(@first_member)
61
+ end
62
+
63
+ def test_should_report_second_member_as_a_member
64
+ assert @chain.member?(@second_member)
65
+ end
66
+
67
+ def test_should_fail_when_adding_original_member
68
+ ex = assert_raise RuntimeError do
69
+ @chain.append(@first_member)
70
+ end
71
+ assert_match(/A.*=>.*B.*=>.*A/, ex.message)
72
+ end
73
+ end
74
+
75
+
@@ -1,12 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rubygems'
3
+ begin
4
+ require 'rubygems'
5
+ rescue LoadError
6
+ # got no gems
7
+ end
8
+
4
9
  require 'test/unit'
5
- require 'flexmock'
10
+ require 'flexmock/test_unit'
6
11
  require 'rake'
7
12
 
8
13
  class TestNameSpace < Test::Unit::TestCase
9
- include FlexMock::TestCase
10
14
 
11
15
  def test_namespace_creation
12
16
  mgr = flexmock("TaskManager")
@@ -85,20 +85,6 @@ else
85
85
  assert_equal "pkgr-1.2.3.gem", pkg.gem_file
86
86
  end
87
87
 
88
- def test_gem_package_with_specific_platform
89
- gem = Gem::Specification.new do |g|
90
- g.name = "pkgr"
91
- g.version = "1.2.3"
92
- g.files = FileList["x"].resolve
93
- g.platform = Gem::Platform::WIN32
94
- end
95
- pkg = Rake::GemPackageTask.new(gem) do |p|
96
- p.package_files << "y"
97
- end
98
- assert_equal ["x", "y"], pkg.package_files
99
- assert_equal "pkgr-1.2.3-mswin32.gem", pkg.gem_file
100
- end
101
-
102
88
  def test_gem_package_with_current_platform
103
89
  gem = Gem::Specification.new do |g|
104
90
  g.name = "pkgr"
@@ -60,6 +60,11 @@ class TestPathMap < Test::Unit::TestCase
60
60
  assert_equal "abc", "abc".pathmap("%X")
61
61
  assert_equal "abc", "abc.rb".pathmap("%X")
62
62
  assert_equal "abc.xyz", "abc.xyz.rb".pathmap("%X")
63
+ assert_equal "ab.xyz", "ab.xyz.rb".pathmap("%X")
64
+ assert_equal "a.xyz", "a.xyz.rb".pathmap("%X")
65
+ assert_equal "abc", "abc.rb".pathmap("%X")
66
+ assert_equal "ab", "ab.rb".pathmap("%X")
67
+ assert_equal "a", "a.rb".pathmap("%X")
63
68
  assert_equal ".depends", ".depends".pathmap("%X")
64
69
  assert_equal "a/dir/.depends", "a/dir/.depends".pathmap("%X")
65
70
  assert_equal "/.depends", "/.depends".pathmap("%X")
@@ -181,6 +186,22 @@ class TestPathMapExplode < Test::Unit::TestCase
181
186
  end
182
187
  end
183
188
 
189
+ class TestPathMapPartial < Test::Unit::TestCase
190
+ def test_pathmap_partial
191
+ @path = "1/2/file"
192
+ def @path.call(n)
193
+ pathmap_partial(n)
194
+ end
195
+ assert_equal("1", @path.call(1))
196
+ assert_equal("1/2", @path.call(2))
197
+ assert_equal("1/2", @path.call(3))
198
+ assert_equal(".", @path.call(0))
199
+ assert_equal("2", @path.call(-1))
200
+ assert_equal("1/2", @path.call(-2))
201
+ assert_equal("1/2", @path.call(-3))
202
+ end
203
+ end
204
+
184
205
  class TestFileListPathMap < Test::Unit::TestCase
185
206
  def test_file_list_supports_pathmap
186
207
  assert_equal ['a', 'b'], FileList['dir/a.rb', 'dir/b.rb'].pathmap("%n")
@@ -113,10 +113,23 @@ class TestRules < Test::Unit::TestCase
113
113
  chdir("testdata") do
114
114
  create_file(".foo")
115
115
  rule '.o' => lambda{".foo"} do |t|
116
- @runs << t.name
116
+ @runs << "#{t.name} - #{t.source}"
117
117
  end
118
118
  Task[OBJFILE].invoke
119
- assert_equal [OBJFILE], @runs
119
+ assert_equal ["#{OBJFILE} - .foo"], @runs
120
+ end
121
+ end
122
+ end
123
+
124
+ def test_file_names_containing_percent_can_be_wrapped_in_lambda
125
+ verbose(false) do
126
+ chdir("testdata") do
127
+ create_file("foo%x")
128
+ rule '.o' => lambda{"foo%x"} do |t|
129
+ @runs << "#{t.name} - #{t.source}"
130
+ end
131
+ Task[OBJFILE].invoke
132
+ assert_equal ["#{OBJFILE} - foo%x"], @runs
120
133
  end
121
134
  end
122
135
  end
@@ -137,12 +150,25 @@ class TestRules < Test::Unit::TestCase
137
150
  def test_pathmap_automatically_applies_to_name
138
151
  verbose(false) do
139
152
  chdir("testdata") do
140
- create_file("abc.c")
141
- rule ".o" => '%{x,a}n.c' do |t|
153
+ create_file("zzabc.c")
154
+ rule ".o" => 'zz%{x,a}n.c' do |t|
155
+ @runs << "#{t.name} - #{t.source}"
156
+ end
157
+ Task["xbc.o"].invoke
158
+ assert_equal ["xbc.o - zzabc.c"], @runs
159
+ end
160
+ end
161
+ end
162
+
163
+ def test_plain_strings_are_just_filenames
164
+ verbose(false) do
165
+ chdir("testdata") do
166
+ create_file("plainname")
167
+ rule ".o" => 'plainname' do |t|
142
168
  @runs << "#{t.name} - #{t.source}"
143
169
  end
144
170
  Task["xbc.o"].invoke
145
- assert_equal ["xbc.o - abc.c"], @runs
171
+ assert_equal ["xbc.o - plainname"], @runs
146
172
  end
147
173
  end
148
174
  end
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake'
5
+
6
+ ######################################################################
7
+ class TestTaskArguments < Test::Unit::TestCase
8
+ def teardown
9
+ ENV.delete('rev')
10
+ ENV.delete('VER')
11
+ end
12
+
13
+ def test_empty_arg_list_is_empty
14
+ ta = Rake::TaskArguments.new([], [])
15
+ assert_equal({}, ta.to_hash)
16
+ end
17
+
18
+ def test_multiple_values_in_args
19
+ ta = Rake::TaskArguments.new([:a, :b, :c], [:one, :two, :three])
20
+ assert_equal({:a => :one, :b => :two, :c => :three}, ta.to_hash)
21
+ end
22
+
23
+ def test_to_s
24
+ ta = Rake::TaskArguments.new([:a, :b, :c], [1, 2, 3])
25
+ assert_equal ta.to_hash.inspect, ta.to_s
26
+ assert_equal ta.to_hash.inspect, ta.inspect
27
+ end
28
+
29
+ def test_enumerable_behavior
30
+ ta = Rake::TaskArguments.new([:a, :b, :c], [1, 2 ,3])
31
+ assert_equal [10, 20, 30], ta.collect { |k,v| v * 10 }.sort
32
+ end
33
+
34
+ def test_named_args
35
+ ta = Rake::TaskArguments.new(["aa", "bb"], [1, 2])
36
+ assert_equal 1, ta.aa
37
+ assert_equal 1, ta[:aa]
38
+ assert_equal 1, ta["aa"]
39
+ assert_equal 2, ta.bb
40
+ assert_nil ta.cc
41
+ end
42
+
43
+ def test_args_knows_its_names
44
+ ta = Rake::TaskArguments.new(["aa", "bb"], [1, 2])
45
+ assert_equal ["aa", "bb"], ta.names
46
+ end
47
+
48
+ def test_extra_names_are_nil
49
+ ta = Rake::TaskArguments.new(["aa", "bb", "cc"], [1, 2])
50
+ assert_nil ta.cc
51
+ end
52
+
53
+ def test_args_can_reference_env_values
54
+ ta = Rake::TaskArguments.new(["aa"], [1])
55
+ ENV['rev'] = "1.2"
56
+ ENV['VER'] = "2.3"
57
+ assert_equal "1.2", ta.rev
58
+ assert_equal "2.3", ta.ver
59
+ end
60
+
61
+ def test_creating_new_argument_scopes
62
+ parent = Rake::TaskArguments.new(['p'], [1])
63
+ child = parent.new_scope(['c', 'p'])
64
+ assert_equal({:c => nil, :p=>1}, child.to_hash)
65
+ assert_equal 1, child.p
66
+ assert_equal 1, child["p"]
67
+ assert_equal 1, child[:p]
68
+ assert_nil child.c
69
+ end
70
+
71
+ def test_child_hides_parent_arg_names
72
+ parent = Rake::TaskArguments.new(['aa'], [1])
73
+ child = Rake::TaskArguments.new(['aa'], [2], parent)
74
+ assert_equal 2, child.aa
75
+ end
76
+ end
@@ -6,10 +6,20 @@ require 'rake'
6
6
  require 'test/filecreation'
7
7
  require 'test/capture_stdout'
8
8
 
9
+
10
+ module Interning
11
+ private
12
+
13
+ def intern(name, *args)
14
+ Rake.application.define_task(Rake::Task, name, *args)
15
+ end
16
+ end
17
+
9
18
  ######################################################################
10
19
  class TestTask < Test::Unit::TestCase
11
20
  include CaptureStdout
12
21
  include Rake
22
+ include Interning
13
23
 
14
24
  def setup
15
25
  Task.clear
@@ -22,12 +32,17 @@ class TestTask < Test::Unit::TestCase
22
32
  assert_equal [], t.prerequisites
23
33
  assert t.prerequisites.is_a?(FileList)
24
34
  assert t.needed?
25
- t.execute
35
+ t.execute(0)
26
36
  assert_equal t, arg
27
37
  assert_nil t.source
28
38
  assert_equal [], t.sources
29
39
  end
30
40
 
41
+ def test_inspect
42
+ t = intern(:foo).enhance([:bar, :baz])
43
+ assert_equal "<Rake::Task foo => [bar, baz]>", t.inspect
44
+ end
45
+
31
46
  def test_invoke
32
47
  runlist = []
33
48
  t1 = intern(:t1).enhance([:t2, :t3]) { |t| runlist << t.name; 3321 }
@@ -38,6 +53,19 @@ class TestTask < Test::Unit::TestCase
38
53
  assert_equal ["t2", "t3", "t1"], runlist
39
54
  end
40
55
 
56
+ def test_invoke_with_circular_dependencies
57
+ runlist = []
58
+ t1 = intern(:t1).enhance([:t2]) { |t| runlist << t.name; 3321 }
59
+ t2 = intern(:t2).enhance([:t1]) { |t| runlist << t.name }
60
+ assert_equal [:t2], t1.prerequisites
61
+ assert_equal [:t1], t2.prerequisites
62
+ ex = assert_raise RuntimeError do
63
+ t1.invoke
64
+ end
65
+ assert_match(/circular dependency/i, ex.message)
66
+ assert_match(/t1 => t2 => t1/, ex.message)
67
+ end
68
+
41
69
  def test_dry_run_prevents_actions
42
70
  Rake.application.options.dryrun = true
43
71
  runlist = []
@@ -136,11 +164,193 @@ class TestTask < Test::Unit::TestCase
136
164
  assert_match(/pre-requisites:\s*--t2/, out)
137
165
  end
138
166
 
139
- private
140
167
 
141
- def intern(name)
142
- Rake.application.define_task(Rake::Task,name)
168
+ def test_extended_comments
169
+ desc %{
170
+ This is a comment.
171
+
172
+ And this is the extended comment.
173
+ name -- Name of task to execute.
174
+ rev -- Software revision to use.
175
+ }
176
+ t = intern(:t, :name, :rev)
177
+ assert_equal "[name,rev]", t.arg_description
178
+ assert_equal "This is a comment.", t.comment
179
+ assert_match(/^\s*name -- Name/, t.full_comment)
180
+ assert_match(/^\s*rev -- Software/, t.full_comment)
181
+ assert_match(/\A\s*This is a comment\.$/, t.full_comment)
182
+ end
183
+
184
+ def test_multiple_comments
185
+ desc "line one"
186
+ t = intern(:t)
187
+ desc "line two"
188
+ intern(:t)
189
+ assert_equal "line one / line two", t.comment
143
190
  end
144
191
 
192
+ def test_settable_comments
193
+ t = intern(:t)
194
+ t.comment = "HI"
195
+ assert_equal "HI", t.comment
196
+ end
145
197
  end
146
198
 
199
+ ######################################################################
200
+ class TestTaskWithArguments < Test::Unit::TestCase
201
+ include CaptureStdout
202
+ include Rake
203
+ include Interning
204
+
205
+ def setup
206
+ Task.clear
207
+ end
208
+
209
+ def test_no_args_given
210
+ t = task :t
211
+ assert_equal [], t.arg_names
212
+ end
213
+
214
+ def test_args_given
215
+ t = task :t, :a, :b
216
+ assert_equal [:a, :b], t.arg_names
217
+ end
218
+
219
+ def test_name_and_needs
220
+ t = task(:t => [:pre])
221
+ assert_equal "t", t.name
222
+ assert_equal [], t.arg_names
223
+ assert_equal ["pre"], t.prerequisites
224
+ end
225
+
226
+ def test_name_and_explicit_needs
227
+ t = task(:t, :needs => [:pre])
228
+ assert_equal "t", t.name
229
+ assert_equal [], t.arg_names
230
+ assert_equal ["pre"], t.prerequisites
231
+ end
232
+
233
+ def test_name_args_and_explicit_needs
234
+ t = task(:t, :x, :y, :needs => [:pre])
235
+ assert_equal "t", t.name
236
+ assert_equal [:x, :y], t.arg_names
237
+ assert_equal ["pre"], t.prerequisites
238
+ end
239
+
240
+ def test_illegal_keys_in_task_name_hash
241
+ assert_raise RuntimeError do
242
+ t = task(:t, :x, :y => 1, :needs => [:pre])
243
+ end
244
+ end
245
+
246
+ def test_arg_list_is_empty_if_no_args_given
247
+ t = intern(:t).enhance do |tt, args|
248
+ assert_equal({}, args.to_hash)
249
+ end
250
+ t.invoke(1, 2, 3)
251
+ end
252
+
253
+ def test_tasks_can_access_arguments_as_hash
254
+ t = task :t, :a, :b, :c do |tt, args|
255
+ assert_equal({:a => 1, :b => 2, :c => 3}, args.to_hash)
256
+ assert_equal 1, args[:a]
257
+ assert_equal 2, args[:b]
258
+ assert_equal 3, args[:c]
259
+ assert_equal 1, args.a
260
+ assert_equal 2, args.b
261
+ assert_equal 3, args.c
262
+ end
263
+ t.invoke(1, 2, 3)
264
+ end
265
+
266
+ def test_actions_of_various_arity_are_ok_with_args
267
+ notes = []
268
+ t = intern(:t, :x).enhance do
269
+ notes << :a
270
+ end
271
+ t.enhance do | |
272
+ notes << :b
273
+ end
274
+ t.enhance do |task|
275
+ notes << :c
276
+ assert_kind_of Task, task
277
+ end
278
+ t.enhance do |t2, args|
279
+ notes << :d
280
+ assert_equal t, t2
281
+ assert_equal({:x => 1}, args.to_hash)
282
+ end
283
+ assert_nothing_raised do t.invoke(1) end
284
+ assert_equal [:a, :b, :c, :d], notes
285
+ end
286
+
287
+ def test_arguments_are_passed_to_block
288
+ t = intern(:t, :a, :b).enhance { |tt, args|
289
+ assert_equal( { :a => 1, :b => 2 }, args.to_hash )
290
+ }
291
+ t.invoke(1, 2)
292
+ end
293
+
294
+ def test_extra_parameters_are_ignored
295
+ t = intern(:t, :a).enhance { |tt, args|
296
+ assert_equal 1, args.a
297
+ assert_nil args[2]
298
+ }
299
+ t.invoke(1, 2)
300
+ end
301
+
302
+ def test_arguments_are_passed_to_all_blocks
303
+ counter = 0
304
+ t = task :t, :a
305
+ task :t do |tt, args|
306
+ assert_equal 1, args.a
307
+ counter += 1
308
+ end
309
+ task :t do |tt, args|
310
+ assert_equal 1, args.a
311
+ counter += 1
312
+ end
313
+ t.invoke(1)
314
+ assert_equal 2, counter
315
+ end
316
+
317
+ def test_block_with_no_parameters_is_ok
318
+ t = intern(:t).enhance { }
319
+ t.invoke(1, 2)
320
+ end
321
+
322
+ def test_name_with_args
323
+ desc "T"
324
+ t = intern(:tt, :a, :b)
325
+ assert_equal "tt", t.name
326
+ assert_equal "T", t.comment
327
+ assert_equal "[a,b]", t.arg_description
328
+ assert_equal "tt[a,b]", t.name_with_args
329
+ assert_equal [:a, :b],t.arg_names
330
+ end
331
+
332
+ def test_named_args_are_passed_to_prereqs
333
+ value = nil
334
+ pre = intern(:pre, :rev).enhance { |t, args| value = args.rev }
335
+ t = intern(:t, :name, :rev).enhance([:pre])
336
+ t.invoke("bill", "1.2")
337
+ assert_equal "1.2", value
338
+ end
339
+
340
+ def test_args_not_passed_if_no_prereq_names
341
+ pre = intern(:pre).enhance { |t, args|
342
+ assert_equal({}, args.to_hash)
343
+ assert_equal "bill", args.name
344
+ }
345
+ t = intern(:t, :name, :rev).enhance([:pre])
346
+ t.invoke("bill", "1.2")
347
+ end
348
+
349
+ def test_args_not_passed_if_no_arg_names
350
+ pre = intern(:pre, :rev).enhance { |t, args|
351
+ assert_equal({ :rev => nil }, args.to_hash)
352
+ }
353
+ t = intern(:t).enhance([:pre])
354
+ t.invoke("bill", "1.2")
355
+ end
356
+ end