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.

@@ -4,10 +4,12 @@ require 'test/unit'
4
4
  require 'rake'
5
5
 
6
6
  require 'test/capture_stdout'
7
+ require 'test/rake_test_setup'
7
8
 
8
9
  class TestFileList < Test::Unit::TestCase
9
10
  FileList = Rake::FileList
10
11
  include CaptureStdout
12
+ include TestMethods
11
13
 
12
14
  def setup
13
15
  create_test_data
@@ -442,7 +444,7 @@ class TestFileList < Test::Unit::TestCase
442
444
  a = FileList['a', 'b', 'c']
443
445
  a.freeze
444
446
  c = a.clone
445
- assert_raise(TypeError, RuntimeError) do
447
+ assert_exception(TypeError, RuntimeError) do
446
448
  c << 'more'
447
449
  end
448
450
  end
@@ -5,9 +5,11 @@ require 'test/unit'
5
5
  require 'test/filecreation'
6
6
  require 'fileutils'
7
7
  require 'stringio'
8
+ require 'test/rake_test_setup'
8
9
 
9
10
  class TestFileUtils < Test::Unit::TestCase
10
11
  include FileCreation
12
+ include TestMethods
11
13
 
12
14
  def setup
13
15
  File.chmod(0750,"test/shellcommand.rb")
@@ -81,7 +83,7 @@ class TestFileUtils < Test::Unit::TestCase
81
83
  def test_safe_ln_fails_on_script_error
82
84
  FileUtils::LN_SUPPORTED[0] = true
83
85
  c = BadLink.new(ScriptError)
84
- assert_raise(ScriptError) do c.safe_ln "a", "b" end
86
+ assert_exception(ScriptError) do c.safe_ln "a", "b" end
85
87
  end
86
88
 
87
89
  def test_verbose
@@ -114,8 +116,8 @@ class TestFileUtils < Test::Unit::TestCase
114
116
 
115
117
  def test_fileutils_methods_dont_leak
116
118
  obj = Object.new
117
- assert_raise(NoMethodError) { obj.copy } # from FileUtils
118
- assert_raise(NoMethodError) { obj.ruby } # from RubyFileUtils
119
+ assert_exception(NoMethodError) { obj.copy } # from FileUtils
120
+ assert_exception(NoMethodError) { obj.ruby } # from RubyFileUtils
119
121
  end
120
122
 
121
123
  def test_sh
@@ -123,21 +125,35 @@ class TestFileUtils < Test::Unit::TestCase
123
125
  assert true, "should not fail"
124
126
  end
125
127
 
128
+ # If the :sh method is invoked directly from a test unit instance
129
+ # (under mini/test), the mini/test version of fail is invoked rather
130
+ # than the kernel version of fail. So we run :sh from within a
131
+ # non-test class to avoid the problem.
132
+ class Sh
133
+ include FileUtils
134
+ def run(*args)
135
+ sh(*args)
136
+ end
137
+ def self.run(*args)
138
+ new.run(*args)
139
+ end
140
+ end
141
+
126
142
  def test_sh_multiple_arguments
127
143
  ENV['RAKE_TEST_SH'] = 'someval'
128
144
  expanded = windows? ? '%RAKE_TEST_SH%' : '$RAKE_TEST_SH'
129
145
  # This one gets expanded by the shell
130
146
  verbose(false) { sh %{ruby test/check_expansion.rb #{expanded} someval} }
131
147
  assert true, "should not fail"
132
- assert_raises(RuntimeError) {
148
+ assert_exception(RuntimeError) {
133
149
  # This one does not get expanded
134
- verbose(false) { sh 'ruby', 'test/check_expansion.rb', expanded, 'someval' }
150
+ verbose(false) { Sh.run 'ruby', 'test/check_expansion.rb', expanded, 'someval' }
135
151
  }
136
152
  end
137
153
 
138
154
  def test_sh_failure
139
- assert_raises(RuntimeError) {
140
- verbose(false) { sh %{ruby test/shellcommand.rb 1} }
155
+ assert_exception(RuntimeError) {
156
+ verbose(false) { Sh.run %{ruby test/shellcommand.rb 1} }
141
157
  }
142
158
  end
143
159
 
@@ -164,7 +180,7 @@ class TestFileUtils < Test::Unit::TestCase
164
180
  end
165
181
 
166
182
  def test_sh_bad_option
167
- ex = assert_raise(ArgumentError) {
183
+ ex = assert_exception(ArgumentError) {
168
184
  verbose(false) { sh %{test/shellcommand.rb}, :bad_option=>true }
169
185
  }
170
186
  assert_match(/bad_option/, ex.message)
@@ -208,18 +224,14 @@ class TestFileUtils < Test::Unit::TestCase
208
224
  end
209
225
  assert block_run, "The block must be run"
210
226
 
211
- if windows?
212
- puts "SKIPPING test_ruby/part 2 when in windows"
213
- else
214
- # This one does not get expanded
215
- block_run = false
216
- ruby '-e', %{exit "#{env_var}".length} do |ok, status| # " (emacs wart)
217
- assert(!ok)
218
- assert_equal 15, status.exitstatus
219
- block_run = true
220
- end
221
- assert block_run, "The block must be run"
227
+ # This one does not get expanded
228
+ block_run = false
229
+ ruby '-e', %{exit %{#{env_var}}.length} do |ok, status| # " (emacs wart)
230
+ assert(!ok)
231
+ assert_equal env_var.length, status.exitstatus
232
+ block_run = true
222
233
  end
234
+ assert block_run, "The block must be run"
223
235
  end
224
236
  end
225
237
 
@@ -2,9 +2,11 @@
2
2
 
3
3
  require 'test/unit'
4
4
  require 'rake'
5
+ require 'test/rake_test_setup'
5
6
 
6
7
  ######################################################################
7
8
  class TestAnEmptyInvocationChain < Test::Unit::TestCase
9
+ include TestMethods
8
10
 
9
11
  def setup
10
12
  @empty = Rake::InvocationChain::EMPTY
@@ -23,6 +25,8 @@ end
23
25
 
24
26
  ######################################################################
25
27
  class TestAnInvocationChainWithOneMember < Test::Unit::TestCase
28
+ include TestMethods
29
+
26
30
  def setup
27
31
  @empty = Rake::InvocationChain::EMPTY
28
32
  @first_member = "A"
@@ -34,7 +38,7 @@ class TestAnInvocationChainWithOneMember < Test::Unit::TestCase
34
38
  end
35
39
 
36
40
  def test_should_fail_when_adding_original_member
37
- ex = assert_raise RuntimeError do
41
+ ex = assert_exception RuntimeError do
38
42
  @chain.append(@first_member)
39
43
  end
40
44
  assert_match(/circular +dependency/i, ex.message)
@@ -49,6 +53,8 @@ end
49
53
 
50
54
  ######################################################################
51
55
  class TestAnInvocationChainWithMultipleMember < Test::Unit::TestCase
56
+ include TestMethods
57
+
52
58
  def setup
53
59
  @first_member = "A"
54
60
  @second_member = "B"
@@ -65,7 +71,7 @@ class TestAnInvocationChainWithMultipleMember < Test::Unit::TestCase
65
71
  end
66
72
 
67
73
  def test_should_fail_when_adding_original_member
68
- ex = assert_raise RuntimeError do
74
+ ex = assert_exception RuntimeError do
69
75
  @chain.append(@first_member)
70
76
  end
71
77
  assert_match(/A.*=>.*B.*=>.*A/, ex.message)
@@ -20,6 +20,7 @@ class TestMakefileLoader < Test::Unit::TestCase
20
20
  assert_equal %w(d1 d2).sort, Task['d'].prerequisites.sort
21
21
  assert_equal %w(e1 f1).sort, Task['e'].prerequisites.sort
22
22
  assert_equal %w(e1 f1).sort, Task['f'].prerequisites.sort
23
- assert_equal 6, Task.tasks.size
23
+ assert_equal ["g1", "g 2", "g 3", "g4"].sort, Task['g 0'].prerequisites.sort
24
+ assert_equal 7, Task.tasks.size
24
25
  end
25
26
  end
@@ -9,28 +9,47 @@ end
9
9
  require 'test/unit'
10
10
  require 'flexmock/test_unit'
11
11
  require 'rake'
12
+ require 'test/rake_test_setup'
12
13
 
13
14
  class TestNameSpace < Test::Unit::TestCase
15
+ include TestMethods
16
+
17
+ class TM
18
+ include Rake::TaskManager
19
+ end
14
20
 
15
21
  def test_namespace_creation
16
- mgr = flexmock("TaskManager")
22
+ mgr = TM.new
17
23
  ns = Rake::NameSpace.new(mgr, [])
18
24
  assert_not_nil ns
19
25
  end
20
26
 
21
27
  def test_namespace_lookup
22
- mgr = flexmock("TaskManager")
23
- mgr.should_receive(:lookup).with(:t, ["a"]).
24
- and_return(:dummy).once
25
- ns = Rake::NameSpace.new(mgr, ["a"])
26
- assert_equal :dummy, ns[:t]
28
+ mgr = TM.new
29
+ ns = mgr.in_namespace("n") do
30
+ mgr.define_task(Rake::Task, "t")
31
+ end
32
+
33
+ assert_not_nil ns["t"]
34
+ assert_equal mgr["n:t"], ns["t"]
27
35
  end
28
36
 
29
37
  def test_namespace_reports_tasks_it_owns
30
- mgr = flexmock("TaskManager")
31
- mgr.should_receive(:tasks).with().
32
- and_return([:x, :y, :z]).once
33
- ns = Rake::NameSpace.new(mgr, ["a"])
34
- assert_equal [:x, :y, :z], ns.tasks
38
+ mgr = TM.new
39
+ nns = nil
40
+ ns = mgr.in_namespace("n") do
41
+ mgr.define_task(Rake::Task, :x)
42
+ mgr.define_task(Rake::Task, :y)
43
+ nns = mgr.in_namespace("nn") do
44
+ mgr.define_task(Rake::Task, :z)
45
+ end
46
+ end
47
+ mgr.in_namespace("m") do
48
+ mgr.define_task(Rake::Task, :x)
49
+ end
50
+
51
+ assert_equal ["n:nn:z", "n:x", "n:y"],
52
+ ns.tasks.map { |tsk| tsk.name }
53
+ assert_equal ["n:nn:z"], nns.tasks.map {|t| t.name}
35
54
  end
36
55
  end
@@ -2,9 +2,11 @@
2
2
 
3
3
  require 'test/unit'
4
4
  require 'rake/packagetask'
5
+ require 'test/rake_test_setup'
5
6
 
6
7
  class TestPackageTask < Test::Unit::TestCase
7
8
  include Rake
9
+ include TestMethods
8
10
 
9
11
  def test_create
10
12
  pkg = Rake::PackageTask.new("pkgr", "1.2.3") { |p|
@@ -40,7 +42,7 @@ class TestPackageTask < Test::Unit::TestCase
40
42
  end
41
43
 
42
44
  def test_missing_version
43
- assert_raises(RuntimeError) {
45
+ assert_exception(RuntimeError) {
44
46
  pkg = Rake::PackageTask.new("pkgr") { |p| }
45
47
  }
46
48
  end
@@ -5,6 +5,7 @@ require 'rake'
5
5
 
6
6
  # ====================================================================
7
7
  class TestPathMap < Test::Unit::TestCase
8
+ include TestMethods
8
9
 
9
10
  def test_returns_self_with_no_args
10
11
  assert_equal "abc.rb", "abc.rb".pathmap
@@ -86,7 +87,7 @@ class TestPathMap < Test::Unit::TestCase
86
87
  end
87
88
 
88
89
  def test_undefined_percent_causes_error
89
- ex = assert_raise(ArgumentError) {
90
+ ex = assert_exception(ArgumentError) {
90
91
  "dir/abc.rb".pathmap("%z")
91
92
  }
92
93
  end
@@ -130,7 +131,7 @@ class TestPathMap < Test::Unit::TestCase
130
131
  end
131
132
 
132
133
  def test_pattern_with_invalid_operator
133
- ex = assert_raise(ArgumentError) do
134
+ ex = assert_exception(ArgumentError) do
134
135
  "abc.xyz".pathmap("%{src,bin}z")
135
136
  end
136
137
  assert_match(/unknown.*pathmap.*spec.*z/i, ex.message)
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake/rdoctask'
5
+ require 'test/rake_test_setup'
6
+
7
+ class TestRDocTask < Test::Unit::TestCase
8
+ include Rake
9
+ include TestMethods
10
+
11
+ def setup
12
+ Task.clear
13
+ end
14
+
15
+ def test_tasks_creation
16
+ Rake::RDocTask.new
17
+ assert Task[:rdoc]
18
+ assert Task[:clobber_rdoc]
19
+ assert Task[:rerdoc]
20
+ end
21
+
22
+ def test_tasks_creation_with_custom_name_symbol
23
+ rd = Rake::RDocTask.new(:rdoc_dev)
24
+ assert Task[:rdoc_dev]
25
+ assert Task[:clobber_rdoc_dev]
26
+ assert Task[:rerdoc_dev]
27
+ assert_equal :rdoc_dev, rd.name
28
+ end
29
+
30
+ def test_tasks_creation_with_custom_name_string
31
+ rd = Rake::RDocTask.new("rdoc_dev")
32
+ assert Task[:rdoc_dev]
33
+ assert Task[:clobber_rdoc_dev]
34
+ assert Task[:rerdoc_dev]
35
+ assert_equal "rdoc_dev", rd.name
36
+ end
37
+
38
+ def test_tasks_creation_with_custom_name_hash
39
+ options = { :rdoc => "rdoc", :clobber_rdoc => "rdoc:clean", :rerdoc => "rdoc:force" }
40
+ rd = Rake::RDocTask.new(options)
41
+ assert Task[:"rdoc"]
42
+ assert Task[:"rdoc:clean"]
43
+ assert Task[:"rdoc:force"]
44
+ assert_raises(RuntimeError) { Task[:clobber_rdoc] }
45
+ assert_equal options, rd.name
46
+ end
47
+
48
+ def test_tasks_creation_with_custom_name_hash_will_use_default_if_an_option_isnt_given
49
+ rd = Rake::RDocTask.new(:clobber_rdoc => "rdoc:clean")
50
+ assert Task[:rdoc]
51
+ assert Task[:"rdoc:clean"]
52
+ assert Task[:rerdoc]
53
+ end
54
+
55
+ def test_tasks_creation_with_custom_name_hash_raises_exception_if_invalid_option_given
56
+ assert_raises(ArgumentError) do
57
+ Rake::RDocTask.new(:foo => "bar")
58
+ end
59
+
60
+ begin
61
+ Rake::RDocTask.new(:foo => "bar")
62
+ rescue ArgumentError => e
63
+ assert_match(/foo/, e.message)
64
+ end
65
+ end
66
+
67
+ def test_inline_source_is_enabled_by_default
68
+ rd = Rake::RDocTask.new
69
+ assert rd.option_list.include?('--inline-source')
70
+ end
71
+
72
+ def test_inline_source_option_is_only_appended_if_option_not_already_given
73
+ rd = Rake::RDocTask.new
74
+ rd.options << '--inline-source'
75
+ assert_equal 1, rd.option_list.grep('--inline-source').size
76
+
77
+ rd = Rake::RDocTask.new
78
+ rd.options << '-S'
79
+ assert_equal 1, rd.option_list.grep('-S').size
80
+ assert_equal 0, rd.option_list.grep('--inline-source').size
81
+ end
82
+
83
+ def test_inline_source_option_can_be_disabled
84
+ rd = Rake::RDocTask.new
85
+ rd.inline_source = false
86
+ assert !rd.option_list.include?('--inline-source')
87
+ end
88
+ end
@@ -2,9 +2,11 @@
2
2
 
3
3
  require 'test/unit'
4
4
  require 'rake'
5
+ require 'test/rake_test_setup'
5
6
 
6
7
  # ====================================================================
7
8
  class TestRequire < Test::Unit::TestCase
9
+ include TestMethods
8
10
 
9
11
  def test_can_load_rake_library
10
12
  app = Rake::Application.new
@@ -22,7 +24,7 @@ class TestRequire < Test::Unit::TestCase
22
24
 
23
25
  def test_throws_error_if_library_not_found
24
26
  app = Rake::Application.new
25
- ex = assert_raise(LoadError) {
27
+ ex = assert_exception(LoadError) {
26
28
  assert app.instance_eval {
27
29
  rake_require("testx", ['test/data/rakelib'], [])
28
30
  }
@@ -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 TestRules < Test::Unit::TestCase
10
11
  include Rake
11
12
  include FileCreation
13
+ include TestMethods
12
14
 
13
15
  SRCFILE = "testdata/abc.c"
14
16
  SRCFILE2 = "testdata/xyz.c"
@@ -23,7 +25,7 @@ class TestRules < Test::Unit::TestCase
23
25
  end
24
26
 
25
27
  def teardown
26
- FileList['testdata/*'].each do |f| rm_r(f, :verbose=>false) end
28
+ FileList['testdata/*'].uniq.each do |f| rm_r(f, :verbose=>false) end
27
29
  end
28
30
 
29
31
  def test_multiple_rules1
@@ -190,8 +192,8 @@ class TestRules < Test::Unit::TestCase
190
192
  rule '.o' => ['.c'] do |t|
191
193
  @runs << t.name
192
194
  end
193
- assert_raises(RuntimeError) { Task['testdata/x.obj'].invoke }
194
- assert_raises(RuntimeError) { Task['testdata/x.xyo'].invoke }
195
+ assert_exception(RuntimeError) { Task['testdata/x.obj'].invoke }
196
+ assert_exception(RuntimeError) { Task['testdata/x.xyo'].invoke }
195
197
  end
196
198
 
197
199
  def test_rule_rebuilds_obj_when_source_is_newer
@@ -332,7 +334,7 @@ class TestRules < Test::Unit::TestCase
332
334
  rule ".#{letter}" => ".#{prev}" do |t| puts "#{t.name}" end
333
335
  prev = letter
334
336
  end
335
- ex = assert_raises(Rake::RuleRecursionOverflowError) {
337
+ ex = assert_exception(Rake::RuleRecursionOverflowError) {
336
338
  Task["testdata/a.z"].invoke
337
339
  }
338
340
  assert_match(/a\.z => testdata\/a.y/, ex.message)
@@ -340,7 +342,7 @@ class TestRules < Test::Unit::TestCase
340
342
 
341
343
  def test_rules_with_bad_dependents_will_fail
342
344
  rule "a" => [ 1 ] do |t| puts t.name end
343
- assert_raise(RuntimeError) do Task['a'].invoke end
345
+ assert_exception(RuntimeError) do Task['a'].invoke end
344
346
  end
345
347
 
346
348
  end