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.

@@ -13,16 +13,17 @@ class TestPathMap < Test::Unit::TestCase
13
13
  def test_s_returns_file_separator
14
14
  sep = File::ALT_SEPARATOR || File::SEPARATOR
15
15
  assert_equal sep, "abc.rb".pathmap("%s")
16
+ assert_equal sep, "".pathmap("%s")
16
17
  assert_equal "a#{sep}b", "a/b".pathmap("%d%s%f")
17
18
  end
18
19
 
19
- def test_b_returns_basename
20
+ def test_f_returns_basename
20
21
  assert_equal "abc.rb", "abc.rb".pathmap("%f")
21
22
  assert_equal "abc.rb", "this/is/a/dir/abc.rb".pathmap("%f")
22
23
  assert_equal "abc.rb", "/this/is/a/dir/abc.rb".pathmap("%f")
23
24
  end
24
25
 
25
- def test_B_returns_basename_without_extension
26
+ def test_n_returns_basename_without_extension
26
27
  assert_equal "abc", "abc.rb".pathmap("%n")
27
28
  assert_equal "abc", "abc".pathmap("%n")
28
29
  assert_equal "abc", "this/is/a/dir/abc.rb".pathmap("%n")
@@ -37,7 +38,7 @@ class TestPathMap < Test::Unit::TestCase
37
38
  assert_equal "/this/is/a/dir", "/this/is/a/dir/abc.rb".pathmap("%d")
38
39
  end
39
40
 
40
- def test_nnnd_returns_partial_dirname
41
+ def test_9d_returns_partial_dirname
41
42
  assert_equal "this/is", "this/is/a/dir/abc.rb".pathmap("%2d")
42
43
  assert_equal "this", "this/is/a/dir/abc.rb".pathmap("%1d")
43
44
  assert_equal ".", "this/is/a/dir/abc.rb".pathmap("%0d")
@@ -47,6 +48,44 @@ class TestPathMap < Test::Unit::TestCase
47
48
  assert_equal "this/is/a/dir", "this/is/a/dir/abc.rb".pathmap("%-100d")
48
49
  end
49
50
 
51
+ def test_x_returns_extension
52
+ assert_equal "", "abc".pathmap("%x")
53
+ assert_equal ".rb", "abc.rb".pathmap("%x")
54
+ assert_equal ".rb", "abc.xyz.rb".pathmap("%x")
55
+ assert_equal "", ".depends".pathmap("%x")
56
+ assert_equal "", "dir/.depends".pathmap("%x")
57
+ end
58
+
59
+ def test_X_returns_everything_but_extension
60
+ assert_equal "abc", "abc".pathmap("%X")
61
+ assert_equal "abc", "abc.rb".pathmap("%X")
62
+ assert_equal "abc.xyz", "abc.xyz.rb".pathmap("%X")
63
+ assert_equal ".depends", ".depends".pathmap("%X")
64
+ assert_equal "a/dir/.depends", "a/dir/.depends".pathmap("%X")
65
+ assert_equal "/.depends", "/.depends".pathmap("%X")
66
+ end
67
+
68
+ def test_p_returns_entire_pathname
69
+ assert_equal "abc.rb", "abc.rb".pathmap("%p")
70
+ assert_equal "this/is/a/dir/abc.rb", "this/is/a/dir/abc.rb".pathmap("%p")
71
+ assert_equal "/this/is/a/dir/abc.rb", "/this/is/a/dir/abc.rb".pathmap("%p")
72
+ end
73
+
74
+ def test_dash_returns_empty_string
75
+ assert_equal "", "abc.rb".pathmap("%-")
76
+ assert_equal "abc.rb", "abc.rb".pathmap("%X%-%x")
77
+ end
78
+
79
+ def test_percent_percent_returns_percent
80
+ assert_equal "a%b", "".pathmap("a%%b")
81
+ end
82
+
83
+ def test_undefined_percent_causes_error
84
+ ex = assert_raise(ArgumentError) {
85
+ "dir/abc.rb".pathmap("%z")
86
+ }
87
+ end
88
+
50
89
  def test_pattern_returns_substitutions
51
90
  assert_equal "bin/org/osb",
52
91
  "src/org/osb/Xyz.java".pathmap("%{src,bin}d")
@@ -92,39 +131,6 @@ class TestPathMap < Test::Unit::TestCase
92
131
  assert_match(/unknown.*pathmap.*spec.*z/i, ex.message)
93
132
  end
94
133
 
95
- def test_x_returns_extension
96
- assert_equal "", "abc".pathmap("%x")
97
- assert_equal ".rb", "abc.rb".pathmap("%x")
98
- assert_equal ".rb", "abc.xyz.rb".pathmap("%x")
99
- assert_equal "", ".depends".pathmap("%x")
100
- assert_equal "", "dir/.depends".pathmap("%x")
101
- end
102
-
103
- def test_X_returns_everything_but_extension
104
- assert_equal "abc", "abc".pathmap("%X")
105
- assert_equal "abc", "abc.rb".pathmap("%X")
106
- assert_equal "abc.xyz", "abc.xyz.rb".pathmap("%X")
107
- assert_equal ".depends", ".depends".pathmap("%X")
108
- assert_equal "a/dir/.depends", "a/dir/.depends".pathmap("%X")
109
- assert_equal "/.depends", "/.depends".pathmap("%X")
110
- end
111
-
112
- def test_p_returns_entire_pathname
113
- assert_equal "abc.rb", "abc.rb".pathmap("%p")
114
- assert_equal "this/is/a/dir/abc.rb", "this/is/a/dir/abc.rb".pathmap("%p")
115
- assert_equal "/this/is/a/dir/abc.rb", "/this/is/a/dir/abc.rb".pathmap("%p")
116
- end
117
-
118
- def test_percent_percent_returns_percent
119
- assert_equal "a%b", "".pathmap("a%%b")
120
- end
121
-
122
- def test_undefined_percent_causes_error
123
- ex = assert_raise(ArgumentError) {
124
- "dir/abc.rb".pathmap("%z")
125
- }
126
- end
127
-
128
134
  def test_works_with_windows_separators
129
135
  if File::ALT_SEPARATOR
130
136
  assert_equal "abc", 'dir\abc.rb'.pathmap("%n")
@@ -17,5 +17,18 @@ class TestRake < Test::Unit::TestCase
17
17
  Rake.each_dir_parent(fn) { |d| result << d }
18
18
  result
19
19
  end
20
+
21
+ def test_can_override_application
22
+ old_app = Rake.application
23
+ fake_app = Object.new
24
+ Rake.application = fake_app
25
+ assert_equal fake_app, Rake.application
26
+ ensure
27
+ Rake.application = old_app
28
+ end
29
+
30
+ def test_original_dir_reports_current_dir
31
+ assert_equal Dir.pwd, Rake.original_dir
32
+ end
20
33
 
21
34
  end
@@ -14,6 +14,8 @@ class TestRules < Test::Unit::TestCase
14
14
  SRCFILE2 = "testdata/xyz.c"
15
15
  FTNFILE = "testdata/abc.f"
16
16
  OBJFILE = "testdata/abc.o"
17
+ FOOFILE = "testdata/foo"
18
+ DOTFOOFILE = "testdata/.foo"
17
19
 
18
20
  def setup
19
21
  Task.clear
@@ -66,7 +68,7 @@ class TestRules < Test::Unit::TestCase
66
68
  assert_equal [OBJFILE], @runs
67
69
  end
68
70
 
69
- def test_create_by_string
71
+ def test_rule_can_be_created_by_string
70
72
  create_file(SRCFILE)
71
73
  rule '.o' => ['.c'] do |t|
72
74
  @runs << t.name
@@ -75,7 +77,77 @@ class TestRules < Test::Unit::TestCase
75
77
  assert_equal [OBJFILE], @runs
76
78
  end
77
79
 
78
- def test_rule_and_no_action_task
80
+ def test_rule_prereqs_can_be_created_by_string
81
+ create_file(SRCFILE)
82
+ rule '.o' => '.c' do |t|
83
+ @runs << t.name
84
+ end
85
+ Task[OBJFILE].invoke
86
+ assert_equal [OBJFILE], @runs
87
+ end
88
+
89
+ def test_plain_strings_as_dependents_refer_to_files
90
+ create_file(SRCFILE)
91
+ rule '.o' => SRCFILE do |t|
92
+ @runs << t.name
93
+ end
94
+ Task[OBJFILE].invoke
95
+ assert_equal [OBJFILE], @runs
96
+ end
97
+
98
+ def test_file_names_beginning_with_dot_can_be_tricked_into_refering_to_file
99
+ verbose(false) do
100
+ chdir("testdata") do
101
+ create_file('.foo')
102
+ rule '.o' => "./.foo" do |t|
103
+ @runs << t.name
104
+ end
105
+ Task[OBJFILE].invoke
106
+ assert_equal [OBJFILE], @runs
107
+ end
108
+ end
109
+ end
110
+
111
+ def test_file_names_beginning_with_dot_can_be_wrapped_in_lambda
112
+ verbose(false) do
113
+ chdir("testdata") do
114
+ create_file(".foo")
115
+ rule '.o' => lambda{".foo"} do |t|
116
+ @runs << t.name
117
+ end
118
+ Task[OBJFILE].invoke
119
+ assert_equal [OBJFILE], @runs
120
+ end
121
+ end
122
+ end
123
+
124
+ def test_non_extension_rule_name_refers_to_file
125
+ verbose(false) do
126
+ chdir("testdata") do
127
+ create_file("abc.c")
128
+ rule "abc" => '.c' do |t|
129
+ @runs << t.name
130
+ end
131
+ Task["abc"].invoke
132
+ assert_equal ["abc"], @runs
133
+ end
134
+ end
135
+ end
136
+
137
+ def test_pathmap_automatically_applies_to_name
138
+ verbose(false) do
139
+ chdir("testdata") do
140
+ create_file("abc.c")
141
+ rule ".o" => '%{x,a}n.c' do |t|
142
+ @runs << "#{t.name} - #{t.source}"
143
+ end
144
+ Task["xbc.o"].invoke
145
+ assert_equal ["xbc.o - abc.c"], @runs
146
+ end
147
+ end
148
+ end
149
+
150
+ def test_rule_runs_when_explicit_task_has_no_actions
79
151
  create_file(SRCFILE)
80
152
  create_file(SRCFILE2)
81
153
  delete_file(OBJFILE)
@@ -87,7 +159,7 @@ class TestRules < Test::Unit::TestCase
87
159
  assert_equal [SRCFILE], @runs
88
160
  end
89
161
 
90
- def test_string_close_matches
162
+ def test_close_matches_on_name_do_not_trigger_rule
91
163
  create_file("testdata/x.c")
92
164
  rule '.o' => ['.c'] do |t|
93
165
  @runs << t.name
@@ -96,7 +168,7 @@ class TestRules < Test::Unit::TestCase
96
168
  assert_raises(RuntimeError) { Task['testdata/x.xyo'].invoke }
97
169
  end
98
170
 
99
- def test_precedence_rule_vs_implicit
171
+ def test_rule_rebuilds_obj_when_source_is_newer
100
172
  create_timed_files(OBJFILE, SRCFILE)
101
173
  rule(/\.o$/ => ['.c']) do
102
174
  @runs << :RULE
@@ -105,7 +177,7 @@ class TestRules < Test::Unit::TestCase
105
177
  assert_equal [:RULE], @runs
106
178
  end
107
179
 
108
- def test_rule_with_two_sources
180
+ def test_rule_with_two_sources_runs_if_both_sources_are_present
109
181
  create_timed_files(OBJFILE, SRCFILE, SRCFILE2)
110
182
  rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
111
183
  @runs << :RULE
@@ -114,7 +186,7 @@ class TestRules < Test::Unit::TestCase
114
186
  assert_equal [:RULE], @runs
115
187
  end
116
188
 
117
- def test_rule_with_two_sources_but_one_missing
189
+ def test_rule_with_two_sources_but_one_missing_does_not_run
118
190
  create_timed_files(OBJFILE, SRCFILE)
119
191
  delete_file(SRCFILE2)
120
192
  rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
@@ -124,7 +196,7 @@ class TestRules < Test::Unit::TestCase
124
196
  assert_equal [], @runs
125
197
  end
126
198
 
127
- def test_rule_ordering_finding_second_rule
199
+ def test_second_rule_runs_when_first_rule_doesnt
128
200
  create_timed_files(OBJFILE, SRCFILE)
129
201
  delete_file(SRCFILE2)
130
202
  rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
@@ -137,7 +209,7 @@ class TestRules < Test::Unit::TestCase
137
209
  assert_equal [:RULE2], @runs
138
210
  end
139
211
 
140
- def test_rule_ordering_finding_first_rule
212
+ def test_second_rule_doest_run_if_first_triggers
141
213
  create_timed_files(OBJFILE, SRCFILE, SRCFILE2)
142
214
  rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
143
215
  @runs << :RULE1
@@ -149,7 +221,7 @@ class TestRules < Test::Unit::TestCase
149
221
  assert_equal [:RULE1], @runs
150
222
  end
151
223
 
152
- def test_rule_ordering_not_finding_second_rule
224
+ def test_second_rule_doest_run_if_first_triggers_with_reversed_rules
153
225
  create_timed_files(OBJFILE, SRCFILE, SRCFILE2)
154
226
  rule OBJFILE => [lambda{SRCFILE}] do
155
227
  @runs << :RULE1
@@ -161,19 +233,19 @@ class TestRules < Test::Unit::TestCase
161
233
  assert_equal [:RULE1], @runs
162
234
  end
163
235
 
164
- def test_proc_dependent
236
+ def test_rule_with_proc_dependent_will_trigger
165
237
  ran = false
166
238
  File.makedirs("testdata/src/jw")
167
239
  create_file("testdata/src/jw/X.java")
168
240
  rule %r(classes/.*\.class) => [
169
- proc { |fn| fn.sub(/^classes/, 'testdata/src').sub(/\.class$/, '.java') }
241
+ proc { |fn| fn.pathmap("%{classes,testdata/src}d/%n.java") }
170
242
  ] do |task|
171
243
  assert_equal task.name, 'classes/jw/X.class'
172
244
  assert_equal task.source, 'testdata/src/jw/X.java'
173
- ran = true
245
+ @runs << :RULE
174
246
  end
175
247
  Task['classes/jw/X.class'].invoke
176
- assert ran, "Should have triggered rule"
248
+ assert_equal [:RULE], @runs
177
249
  ensure
178
250
  rm_r("testdata/src", :verbose=>false) rescue nil
179
251
  end
@@ -200,7 +272,7 @@ class TestRules < Test::Unit::TestCase
200
272
  rm_r("testdata/flatten", :verbose=>false) rescue nil
201
273
  end
202
274
 
203
- def test_recursive_rules
275
+ def test_recursive_rules_will_work_as_long_as_they_terminate
204
276
  actions = []
205
277
  create_file("testdata/abc.xml")
206
278
  rule '.y' => '.xml' do actions << 'y' end
@@ -211,7 +283,7 @@ class TestRules < Test::Unit::TestCase
211
283
  assert_equal ['y', 'c', 'o', 'exe'], actions
212
284
  end
213
285
 
214
- def test_recursive_overflow
286
+ def test_recursive_rules_that_dont_terminate_will_overflow
215
287
  create_file("testdata/a.a")
216
288
  prev = 'a'
217
289
  ('b'..'z').each do |letter|
@@ -224,5 +296,10 @@ class TestRules < Test::Unit::TestCase
224
296
  assert_match(/a\.z => testdata\/a.y/, ex.message)
225
297
  end
226
298
 
299
+ def test_rules_with_bad_dependents_will_fail
300
+ rule "a" => [ 1 ] do |t| puts t.name end
301
+ assert_raise(RuntimeError) do Task['a'].invoke end
302
+ end
303
+
227
304
  end
228
305
 
@@ -82,18 +82,18 @@ class TestTaskManager < Test::Unit::TestCase
82
82
  aa = @tm.define_task(Rake::Task, :aa)
83
83
  mid_z = @tm.define_task(Rake::Task, :z)
84
84
  @tm.in_namespace("b") do
85
- bb = @tm.define_task(Rake::Task, :bb)
86
- bot_z = @tm.define_task(Rake::Task, :z)
87
-
88
- assert_equal ["a", "b"], @tm.current_scope
89
-
90
- assert_equal bb, @tm["a:b:bb"]
91
- assert_equal aa, @tm["a:aa"]
92
- assert_equal xx, @tm["xx"]
93
- assert_equal bot_z, @tm["z"]
94
- assert_equal mid_z, @tm["^z"]
95
- assert_equal top_z, @tm["^^z"]
96
- assert_equal top_z, @tm["rake:z"]
85
+ bb = @tm.define_task(Rake::Task, :bb)
86
+ bot_z = @tm.define_task(Rake::Task, :z)
87
+
88
+ assert_equal ["a", "b"], @tm.current_scope
89
+
90
+ assert_equal bb, @tm["a:b:bb"]
91
+ assert_equal aa, @tm["a:aa"]
92
+ assert_equal xx, @tm["xx"]
93
+ assert_equal bot_z, @tm["z"]
94
+ assert_equal mid_z, @tm["^z"]
95
+ assert_equal top_z, @tm["^^z"]
96
+ assert_equal top_z, @tm["rake:z"]
97
97
  end
98
98
 
99
99
  assert_equal ["a"], @tm.current_scope
@@ -122,7 +122,7 @@ class TestTaskManager < Test::Unit::TestCase
122
122
  t2 = @tm.define_task(Rake::Task, :t)
123
123
  s = @tm.define_task(Rake::Task, :s)
124
124
  @tm.in_namespace("b") do
125
- t3 = @tm.define_task(Rake::Task, :t)
125
+ t3 = @tm.define_task(Rake::Task, :t)
126
126
  end
127
127
  end
128
128
  assert_equal t1, @tm[:t, []]
@@ -4,9 +4,11 @@ require 'test/unit'
4
4
  require 'fileutils'
5
5
  require 'rake'
6
6
  require 'test/filecreation'
7
+ require 'test/capture_stdout'
7
8
 
8
9
  ######################################################################
9
10
  class TestTask < Test::Unit::TestCase
11
+ include CaptureStdout
10
12
  include Rake
11
13
 
12
14
  def setup
@@ -23,6 +25,7 @@ class TestTask < Test::Unit::TestCase
23
25
  t.execute
24
26
  assert_equal t, arg
25
27
  assert_nil t.source
28
+ assert_equal [], t.sources
26
29
  end
27
30
 
28
31
  def test_invoke
@@ -35,8 +38,29 @@ class TestTask < Test::Unit::TestCase
35
38
  assert_equal ["t2", "t3", "t1"], runlist
36
39
  end
37
40
 
38
- def intern(name)
39
- Rake.application.define_task(Rake::Task,name)
41
+ def test_dry_run_prevents_actions
42
+ Rake.application.options.dryrun = true
43
+ runlist = []
44
+ t1 = intern(:t1).enhance { |t| runlist << t.name; 3321 }
45
+ out = capture_stdout { t1.invoke }
46
+ assert_match(/execute .*t1/i, out)
47
+ assert_match(/dry run/i, out)
48
+ assert_no_match(/invoke/i, out)
49
+ assert_equal [], runlist
50
+ ensure
51
+ Rake.application.options.dryrun = false
52
+ end
53
+
54
+ def test_tasks_can_be_traced
55
+ Rake.application.options.trace = true
56
+ t1 = intern(:t1) { |t| runlist << t.name; 3321 }
57
+ out = capture_stdout {
58
+ t1.invoke
59
+ }
60
+ assert_match(/invoke t1/i, out)
61
+ assert_match(/execute t1/i, out)
62
+ ensure
63
+ Rake.application.options.trace = false
40
64
  end
41
65
 
42
66
  def test_no_double_invoke
@@ -102,5 +126,21 @@ class TestTask < Test::Unit::TestCase
102
126
  assert_equal ["b", "c"], Task[:a].prerequisites
103
127
  end
104
128
 
129
+ def test_investigation_output
130
+ t1 = intern(:t1).enhance([:t2, :t3]) { |t| runlist << t.name; 3321 }
131
+ intern(:t2)
132
+ intern(:t3)
133
+ out = t1.investigation
134
+ assert_match(/class:\s*Rake::Task/, out)
135
+ assert_match(/needed:\s*true/, out)
136
+ assert_match(/pre-requisites:\s*--t2/, out)
137
+ end
138
+
139
+ private
140
+
141
+ def intern(name)
142
+ Rake.application.define_task(Rake::Task,name)
143
+ end
144
+
105
145
  end
106
146