drake 0.8.1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +386 -0
- data/MIT-LICENSE +21 -0
- data/README +396 -0
- data/Rakefile +505 -0
- data/TODO +20 -0
- data/bin/drake +31 -0
- data/bin/rake +31 -0
- data/doc/example/Rakefile1 +38 -0
- data/doc/example/Rakefile2 +35 -0
- data/doc/example/a.c +6 -0
- data/doc/example/b.c +6 -0
- data/doc/example/main.c +11 -0
- data/doc/glossary.rdoc +51 -0
- data/doc/jamis.rb +591 -0
- data/doc/proto_rake.rdoc +127 -0
- data/doc/rake.1.gz +0 -0
- data/doc/rakefile.rdoc +534 -0
- data/doc/rational.rdoc +151 -0
- data/doc/release_notes/rake-0.4.14.rdoc +23 -0
- data/doc/release_notes/rake-0.4.15.rdoc +35 -0
- data/doc/release_notes/rake-0.5.0.rdoc +53 -0
- data/doc/release_notes/rake-0.5.3.rdoc +78 -0
- data/doc/release_notes/rake-0.5.4.rdoc +46 -0
- data/doc/release_notes/rake-0.6.0.rdoc +141 -0
- data/doc/release_notes/rake-0.7.0.rdoc +119 -0
- data/doc/release_notes/rake-0.7.1.rdoc +59 -0
- data/doc/release_notes/rake-0.7.2.rdoc +121 -0
- data/doc/release_notes/rake-0.7.3.rdoc +47 -0
- data/doc/release_notes/rake-0.8.0.rdoc +114 -0
- data/doc/release_notes/rake-0.8.2.rdoc +163 -0
- data/install.rb +88 -0
- data/lib/rake.rb +2538 -0
- data/lib/rake/classic_namespace.rb +8 -0
- data/lib/rake/clean.rb +33 -0
- data/lib/rake/comp_tree/algorithm.rb +234 -0
- data/lib/rake/comp_tree/bucket_ipc.rb +175 -0
- data/lib/rake/comp_tree/driver.rb +291 -0
- data/lib/rake/comp_tree/error.rb +51 -0
- data/lib/rake/comp_tree/node.rb +189 -0
- data/lib/rake/comp_tree/quix/builtin/kernel/tap.rb +57 -0
- data/lib/rake/comp_tree/quix/diagnostic.rb +92 -0
- data/lib/rake/comp_tree/quix/kernel.rb +109 -0
- data/lib/rake/comp_tree/retriable_fork.rb +66 -0
- data/lib/rake/comp_tree/task_node.rb +46 -0
- data/lib/rake/contrib/compositepublisher.rb +24 -0
- data/lib/rake/contrib/ftptools.rb +153 -0
- data/lib/rake/contrib/publisher.rb +75 -0
- data/lib/rake/contrib/rubyforgepublisher.rb +18 -0
- data/lib/rake/contrib/sshpublisher.rb +47 -0
- data/lib/rake/contrib/sys.rb +209 -0
- data/lib/rake/gempackagetask.rb +103 -0
- data/lib/rake/loaders/makefile.rb +35 -0
- data/lib/rake/packagetask.rb +185 -0
- data/lib/rake/parallel.rb +54 -0
- data/lib/rake/rake_test_loader.rb +5 -0
- data/lib/rake/rdoctask.rb +147 -0
- data/lib/rake/ruby182_test_unit_fix.rb +23 -0
- data/lib/rake/runtest.rb +23 -0
- data/lib/rake/tasklib.rb +23 -0
- data/lib/rake/testtask.rb +161 -0
- data/test/capture_stdout.rb +26 -0
- data/test/check_expansion.rb +5 -0
- data/test/contrib/test_sys.rb +47 -0
- data/test/data/chains/Rakefile +15 -0
- data/test/data/default/Rakefile +19 -0
- data/test/data/dryrun/Rakefile +22 -0
- data/test/data/file_creation_task/Rakefile +33 -0
- data/test/data/imports/Rakefile +19 -0
- data/test/data/imports/deps.mf +1 -0
- data/test/data/multidesc/Rakefile +17 -0
- data/test/data/namespace/Rakefile +57 -0
- data/test/data/rakelib/test1.rb +3 -0
- data/test/data/rbext/rakefile.rb +3 -0
- data/test/data/sample.mf +12 -0
- data/test/data/statusreturn/Rakefile +8 -0
- data/test/data/unittest/Rakefile +1 -0
- data/test/filecreation.rb +32 -0
- data/test/functional.rb +15 -0
- data/test/in_environment.rb +30 -0
- data/test/parallel.rb +3 -0
- data/test/rake_test_setup.rb +5 -0
- data/test/reqfile.rb +3 -0
- data/test/reqfile2.rb +3 -0
- data/test/session_functional.rb +324 -0
- data/test/shellcommand.rb +3 -0
- data/test/single_threaded.rb +2 -0
- data/test/test_application.rb +714 -0
- data/test/test_clean.rb +14 -0
- data/test/test_definitions.rb +82 -0
- data/test/test_earlytime.rb +35 -0
- data/test/test_extension.rb +63 -0
- data/test/test_file_creation_task.rb +62 -0
- data/test/test_file_task.rb +139 -0
- data/test/test_filelist.rb +618 -0
- data/test/test_fileutils.rb +250 -0
- data/test/test_ftp.rb +59 -0
- data/test/test_invocation_chain.rb +75 -0
- data/test/test_makefile_loader.rb +25 -0
- data/test/test_namespace.rb +36 -0
- data/test/test_package_task.rb +116 -0
- data/test/test_parallel.rb +47 -0
- data/test/test_pathmap.rb +209 -0
- data/test/test_rake.rb +41 -0
- data/test/test_require.rb +33 -0
- data/test/test_rules.rb +348 -0
- data/test/test_task_arguments.rb +89 -0
- data/test/test_task_manager.rb +172 -0
- data/test/test_tasklib.rb +12 -0
- data/test/test_tasks.rb +373 -0
- data/test/test_test_task.rb +75 -0
- data/test/test_top_level_functions.rb +84 -0
- metadata +190 -0
data/test/test_rules.rb
ADDED
@@ -0,0 +1,348 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'rake'
|
6
|
+
require 'test/filecreation'
|
7
|
+
|
8
|
+
######################################################################
|
9
|
+
class TestRules < Test::Unit::TestCase
|
10
|
+
include Rake
|
11
|
+
include FileCreation
|
12
|
+
|
13
|
+
SRCFILE = "testdata/abc.c"
|
14
|
+
SRCFILE2 = "testdata/xyz.c"
|
15
|
+
FTNFILE = "testdata/abc.f"
|
16
|
+
OBJFILE = "testdata/abc.o"
|
17
|
+
FOOFILE = "testdata/foo"
|
18
|
+
DOTFOOFILE = "testdata/.foo"
|
19
|
+
|
20
|
+
def setup
|
21
|
+
Task.clear
|
22
|
+
@runs = []
|
23
|
+
end
|
24
|
+
|
25
|
+
def teardown
|
26
|
+
FileList['testdata/*'].each do |f| rm_r(f, :verbose=>false) end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_multiple_rules1
|
30
|
+
create_file(FTNFILE)
|
31
|
+
delete_file(SRCFILE)
|
32
|
+
delete_file(OBJFILE)
|
33
|
+
rule(/\.o$/ => ['.c']) do @runs << :C end
|
34
|
+
rule(/\.o$/ => ['.f']) do @runs << :F end
|
35
|
+
t = Task[OBJFILE]
|
36
|
+
t.invoke
|
37
|
+
Task[OBJFILE].invoke
|
38
|
+
assert_equal [:F], @runs
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_multiple_rules2
|
42
|
+
mutex = Mutex.new
|
43
|
+
create_file(FTNFILE)
|
44
|
+
delete_file(SRCFILE)
|
45
|
+
delete_file(OBJFILE)
|
46
|
+
rule(/\.o$/ => ['.f']) do mutex.synchronize { @runs << :F } end
|
47
|
+
rule(/\.o$/ => ['.c']) do mutex.synchronize { @runs << :C } end
|
48
|
+
Task[OBJFILE].invoke
|
49
|
+
assert_equal [:F], @runs
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_create_with_source
|
53
|
+
create_file(SRCFILE)
|
54
|
+
rule(/\.o$/ => ['.c']) do |t|
|
55
|
+
@runs << t.name
|
56
|
+
assert_equal OBJFILE, t.name
|
57
|
+
assert_equal SRCFILE, t.source
|
58
|
+
end
|
59
|
+
Task[OBJFILE].invoke
|
60
|
+
assert_equal [OBJFILE], @runs
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_single_dependent
|
64
|
+
create_file(SRCFILE)
|
65
|
+
rule(/\.o$/ => '.c') do |t|
|
66
|
+
@runs << t.name
|
67
|
+
end
|
68
|
+
Task[OBJFILE].invoke
|
69
|
+
assert_equal [OBJFILE], @runs
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_rule_can_be_created_by_string
|
73
|
+
create_file(SRCFILE)
|
74
|
+
rule '.o' => ['.c'] do |t|
|
75
|
+
@runs << t.name
|
76
|
+
end
|
77
|
+
Task[OBJFILE].invoke
|
78
|
+
assert_equal [OBJFILE], @runs
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_rule_prereqs_can_be_created_by_string
|
82
|
+
create_file(SRCFILE)
|
83
|
+
rule '.o' => '.c' do |t|
|
84
|
+
@runs << t.name
|
85
|
+
end
|
86
|
+
Task[OBJFILE].invoke
|
87
|
+
assert_equal [OBJFILE], @runs
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_plain_strings_as_dependents_refer_to_files
|
91
|
+
create_file(SRCFILE)
|
92
|
+
rule '.o' => SRCFILE do |t|
|
93
|
+
@runs << t.name
|
94
|
+
end
|
95
|
+
Task[OBJFILE].invoke
|
96
|
+
assert_equal [OBJFILE], @runs
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_file_names_beginning_with_dot_can_be_tricked_into_refering_to_file
|
100
|
+
verbose(false) do
|
101
|
+
chdir("testdata") do
|
102
|
+
create_file('.foo')
|
103
|
+
rule '.o' => "./.foo" do |t|
|
104
|
+
@runs << t.name
|
105
|
+
end
|
106
|
+
Task[OBJFILE].invoke
|
107
|
+
assert_equal [OBJFILE], @runs
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_file_names_beginning_with_dot_can_be_wrapped_in_lambda
|
113
|
+
verbose(false) do
|
114
|
+
chdir("testdata") do
|
115
|
+
create_file(".foo")
|
116
|
+
rule '.o' => lambda{".foo"} do |t|
|
117
|
+
@runs << "#{t.name} - #{t.source}"
|
118
|
+
end
|
119
|
+
Task[OBJFILE].invoke
|
120
|
+
assert_equal ["#{OBJFILE} - .foo"], @runs
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_file_names_containing_percent_can_be_wrapped_in_lambda
|
126
|
+
verbose(false) do
|
127
|
+
chdir("testdata") do
|
128
|
+
create_file("foo%x")
|
129
|
+
rule '.o' => lambda{"foo%x"} do |t|
|
130
|
+
@runs << "#{t.name} - #{t.source}"
|
131
|
+
end
|
132
|
+
Task[OBJFILE].invoke
|
133
|
+
assert_equal ["#{OBJFILE} - foo%x"], @runs
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_non_extension_rule_name_refers_to_file
|
139
|
+
verbose(false) do
|
140
|
+
chdir("testdata") do
|
141
|
+
create_file("abc.c")
|
142
|
+
rule "abc" => '.c' do |t|
|
143
|
+
@runs << t.name
|
144
|
+
end
|
145
|
+
Task["abc"].invoke
|
146
|
+
assert_equal ["abc"], @runs
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_pathmap_automatically_applies_to_name
|
152
|
+
verbose(false) do
|
153
|
+
chdir("testdata") do
|
154
|
+
create_file("zzabc.c")
|
155
|
+
rule ".o" => 'zz%{x,a}n.c' do |t|
|
156
|
+
@runs << "#{t.name} - #{t.source}"
|
157
|
+
end
|
158
|
+
Task["xbc.o"].invoke
|
159
|
+
assert_equal ["xbc.o - zzabc.c"], @runs
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_plain_strings_are_just_filenames
|
165
|
+
verbose(false) do
|
166
|
+
chdir("testdata") do
|
167
|
+
create_file("plainname")
|
168
|
+
rule ".o" => 'plainname' do |t|
|
169
|
+
@runs << "#{t.name} - #{t.source}"
|
170
|
+
end
|
171
|
+
Task["xbc.o"].invoke
|
172
|
+
assert_equal ["xbc.o - plainname"], @runs
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_rule_runs_when_explicit_task_has_no_actions
|
178
|
+
create_file(SRCFILE)
|
179
|
+
create_file(SRCFILE2)
|
180
|
+
delete_file(OBJFILE)
|
181
|
+
rule '.o' => '.c' do |t|
|
182
|
+
@runs << t.source
|
183
|
+
end
|
184
|
+
file OBJFILE => [SRCFILE2]
|
185
|
+
Task[OBJFILE].invoke
|
186
|
+
assert_equal [SRCFILE], @runs
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_close_matches_on_name_do_not_trigger_rule
|
190
|
+
create_file("testdata/x.c")
|
191
|
+
rule '.o' => ['.c'] do |t|
|
192
|
+
@runs << t.name
|
193
|
+
end
|
194
|
+
assert_raises(RuntimeError) { Task['testdata/x.obj'].invoke }
|
195
|
+
assert_raises(RuntimeError) { Task['testdata/x.xyo'].invoke }
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_rule_rebuilds_obj_when_source_is_newer
|
199
|
+
create_timed_files(OBJFILE, SRCFILE)
|
200
|
+
rule(/\.o$/ => ['.c']) do
|
201
|
+
@runs << :RULE
|
202
|
+
end
|
203
|
+
Task[OBJFILE].invoke
|
204
|
+
assert_equal [:RULE], @runs
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_rule_with_two_sources_runs_if_both_sources_are_present
|
208
|
+
create_timed_files(OBJFILE, SRCFILE, SRCFILE2)
|
209
|
+
rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
|
210
|
+
@runs << :RULE
|
211
|
+
end
|
212
|
+
Task[OBJFILE].invoke
|
213
|
+
assert_equal [:RULE], @runs
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_rule_with_two_sources_but_one_missing_does_not_run
|
217
|
+
create_timed_files(OBJFILE, SRCFILE)
|
218
|
+
delete_file(SRCFILE2)
|
219
|
+
rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
|
220
|
+
@runs << :RULE
|
221
|
+
end
|
222
|
+
Task[OBJFILE].invoke
|
223
|
+
assert_equal [], @runs
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_rule_with_two_sources_builds_both_sources
|
227
|
+
task 'x.aa'
|
228
|
+
task 'x.bb'
|
229
|
+
rule '.a' => '.aa' do
|
230
|
+
@runs << "A"
|
231
|
+
end
|
232
|
+
rule '.b' => '.bb' do
|
233
|
+
@runs << "B"
|
234
|
+
end
|
235
|
+
rule ".c" => ['.a', '.b'] do
|
236
|
+
@runs << "C"
|
237
|
+
end
|
238
|
+
Task["x.c"].invoke
|
239
|
+
assert_equal ["A", "B", "C"], @runs.sort
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_second_rule_runs_when_first_rule_doesnt
|
243
|
+
create_timed_files(OBJFILE, SRCFILE)
|
244
|
+
delete_file(SRCFILE2)
|
245
|
+
rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
|
246
|
+
@runs << :RULE1
|
247
|
+
end
|
248
|
+
rule OBJFILE => [lambda{SRCFILE}] do
|
249
|
+
@runs << :RULE2
|
250
|
+
end
|
251
|
+
Task[OBJFILE].invoke
|
252
|
+
assert_equal [:RULE2], @runs
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_second_rule_doest_run_if_first_triggers
|
256
|
+
create_timed_files(OBJFILE, SRCFILE, SRCFILE2)
|
257
|
+
rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
|
258
|
+
@runs << :RULE1
|
259
|
+
end
|
260
|
+
rule OBJFILE => [lambda{SRCFILE}] do
|
261
|
+
@runs << :RULE2
|
262
|
+
end
|
263
|
+
Task[OBJFILE].invoke
|
264
|
+
assert_equal [:RULE1], @runs
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_second_rule_doest_run_if_first_triggers_with_reversed_rules
|
268
|
+
create_timed_files(OBJFILE, SRCFILE, SRCFILE2)
|
269
|
+
rule OBJFILE => [lambda{SRCFILE}] do
|
270
|
+
@runs << :RULE1
|
271
|
+
end
|
272
|
+
rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
|
273
|
+
@runs << :RULE2
|
274
|
+
end
|
275
|
+
Task[OBJFILE].invoke
|
276
|
+
assert_equal [:RULE1], @runs
|
277
|
+
end
|
278
|
+
|
279
|
+
def test_rule_with_proc_dependent_will_trigger
|
280
|
+
ran = false
|
281
|
+
mkdir_p("testdata/src/jw")
|
282
|
+
create_file("testdata/src/jw/X.java")
|
283
|
+
rule %r(classes/.*\.class) => [
|
284
|
+
proc { |fn| fn.pathmap("%{classes,testdata/src}d/%n.java") }
|
285
|
+
] do |task|
|
286
|
+
assert_equal task.name, 'classes/jw/X.class'
|
287
|
+
assert_equal task.source, 'testdata/src/jw/X.java'
|
288
|
+
@runs << :RULE
|
289
|
+
end
|
290
|
+
Task['classes/jw/X.class'].invoke
|
291
|
+
assert_equal [:RULE], @runs
|
292
|
+
ensure
|
293
|
+
rm_r("testdata/src", :verbose=>false) rescue nil
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_proc_returning_lists_are_flattened_into_prereqs
|
297
|
+
ran = false
|
298
|
+
mkdir_p("testdata/flatten")
|
299
|
+
create_file("testdata/flatten/a.txt")
|
300
|
+
task 'testdata/flatten/b.data' do |t|
|
301
|
+
ran = true
|
302
|
+
touch t.name, :verbose => false
|
303
|
+
end
|
304
|
+
rule '.html' =>
|
305
|
+
proc { |fn|
|
306
|
+
[
|
307
|
+
fn.ext("txt"),
|
308
|
+
"testdata/flatten/b.data"
|
309
|
+
]
|
310
|
+
} do |task|
|
311
|
+
end
|
312
|
+
Task['testdata/flatten/a.html'].invoke
|
313
|
+
assert ran, "Should have triggered flattened dependency"
|
314
|
+
ensure
|
315
|
+
rm_r("testdata/flatten", :verbose=>false) rescue nil
|
316
|
+
end
|
317
|
+
|
318
|
+
def test_recursive_rules_will_work_as_long_as_they_terminate
|
319
|
+
actions = []
|
320
|
+
create_file("testdata/abc.xml")
|
321
|
+
rule '.y' => '.xml' do actions << 'y' end
|
322
|
+
rule '.c' => '.y' do actions << 'c'end
|
323
|
+
rule '.o' => '.c' do actions << 'o'end
|
324
|
+
rule '.exe' => '.o' do actions << 'exe'end
|
325
|
+
Task["testdata/abc.exe"].invoke
|
326
|
+
assert_equal ['y', 'c', 'o', 'exe'], actions
|
327
|
+
end
|
328
|
+
|
329
|
+
def test_recursive_rules_that_dont_terminate_will_overflow
|
330
|
+
create_file("testdata/a.a")
|
331
|
+
prev = 'a'
|
332
|
+
('b'..'z').each do |letter|
|
333
|
+
rule ".#{letter}" => ".#{prev}" do |t| puts "#{t.name}" end
|
334
|
+
prev = letter
|
335
|
+
end
|
336
|
+
ex = assert_raises(Rake::RuleRecursionOverflowError) {
|
337
|
+
Task["testdata/a.z"].invoke
|
338
|
+
}
|
339
|
+
assert_match(/a\.z => testdata\/a.y/, ex.message)
|
340
|
+
end
|
341
|
+
|
342
|
+
def test_rules_with_bad_dependents_will_fail
|
343
|
+
rule "a" => [ 1 ] do |t| puts t.name end
|
344
|
+
assert_raise(RuntimeError) do Task['a'].invoke end
|
345
|
+
end
|
346
|
+
|
347
|
+
end
|
348
|
+
|
@@ -0,0 +1,89 @@
|
|
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({: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
|
+
|
77
|
+
def test_default_arguments_values_can_be_merged
|
78
|
+
ta = Rake::TaskArguments.new(["aa", "bb"], [nil, "original_val"])
|
79
|
+
ta.with_defaults({ :aa => 'default_val' })
|
80
|
+
assert_equal 'default_val', ta[:aa]
|
81
|
+
assert_equal 'original_val', ta[:bb]
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_default_arguements_that_dont_match_names_are_ignored
|
85
|
+
ta = Rake::TaskArguments.new(["aa", "bb"], [nil, "original_val"])
|
86
|
+
ta.with_defaults({ "cc" => "default_val" })
|
87
|
+
assert_nil ta[:cc]
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rake'
|
5
|
+
|
6
|
+
class TaskManager
|
7
|
+
include Rake::TaskManager
|
8
|
+
end
|
9
|
+
|
10
|
+
class TestTaskManager < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
@tm = TaskManager.new
|
13
|
+
@tm.num_threads = Rake.application.num_threads
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_create_task_manager
|
17
|
+
assert_not_nil @tm
|
18
|
+
assert_equal [], @tm.tasks
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_define_task
|
22
|
+
t = @tm.define_task(Rake::Task, :t)
|
23
|
+
assert_equal "t", t.name
|
24
|
+
assert_equal @tm, t.application
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_name_lookup
|
28
|
+
t = @tm.define_task(Rake::Task, :t)
|
29
|
+
assert_equal t, @tm[:t]
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_namespace_task_create
|
33
|
+
@tm.in_namespace("x") do
|
34
|
+
t = @tm.define_task(Rake::Task, :t)
|
35
|
+
assert_equal "x:t", t.name
|
36
|
+
end
|
37
|
+
assert_equal ["x:t"], @tm.tasks.collect { |t| t.name }
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_anonymous_namespace
|
41
|
+
anon_ns = @tm.in_namespace(nil) do
|
42
|
+
t = @tm.define_task(Rake::Task, :t)
|
43
|
+
assert_equal "_anon_1:t", t.name
|
44
|
+
end
|
45
|
+
task = anon_ns[:t]
|
46
|
+
assert_equal "_anon_1:t", task.name
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_create_filetask_in_namespace
|
50
|
+
@tm.in_namespace("x") do
|
51
|
+
t = @tm.define_task(Rake::FileTask, "fn")
|
52
|
+
assert_equal "fn", t.name
|
53
|
+
end
|
54
|
+
assert_equal ["fn"], @tm.tasks.collect { |t| t.name }
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_namespace_yields_same_namespace_as_returned
|
58
|
+
yielded_namespace = nil
|
59
|
+
returned_namespace = @tm.in_namespace("x") do |ns|
|
60
|
+
yielded_namespace = ns
|
61
|
+
end
|
62
|
+
assert_equal returned_namespace, yielded_namespace
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_name_lookup_with_implicit_file_tasks
|
66
|
+
t = @tm["README"]
|
67
|
+
assert_equal "README", t.name
|
68
|
+
assert Rake::FileTask === t
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_name_lookup_with_nonexistent_task
|
72
|
+
assert_raise(RuntimeError) {
|
73
|
+
t = @tm["DOES NOT EXIST"]
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_name_lookup_in_multiple_scopes
|
78
|
+
aa = nil
|
79
|
+
bb = nil
|
80
|
+
xx = @tm.define_task(Rake::Task, :xx)
|
81
|
+
top_z = @tm.define_task(Rake::Task, :z)
|
82
|
+
@tm.in_namespace("a") do
|
83
|
+
aa = @tm.define_task(Rake::Task, :aa)
|
84
|
+
mid_z = @tm.define_task(Rake::Task, :z)
|
85
|
+
@tm.in_namespace("b") do
|
86
|
+
bb = @tm.define_task(Rake::Task, :bb)
|
87
|
+
bot_z = @tm.define_task(Rake::Task, :z)
|
88
|
+
|
89
|
+
assert_equal ["a", "b"], @tm.current_scope
|
90
|
+
|
91
|
+
assert_equal bb, @tm["a:b:bb"]
|
92
|
+
assert_equal aa, @tm["a:aa"]
|
93
|
+
assert_equal xx, @tm["xx"]
|
94
|
+
assert_equal bot_z, @tm["z"]
|
95
|
+
assert_equal mid_z, @tm["^z"]
|
96
|
+
assert_equal top_z, @tm["^^z"]
|
97
|
+
assert_equal top_z, @tm["rake:z"]
|
98
|
+
end
|
99
|
+
|
100
|
+
assert_equal ["a"], @tm.current_scope
|
101
|
+
|
102
|
+
assert_equal bb, @tm["a:b:bb"]
|
103
|
+
assert_equal aa, @tm["a:aa"]
|
104
|
+
assert_equal xx, @tm["xx"]
|
105
|
+
assert_equal bb, @tm["b:bb"]
|
106
|
+
assert_equal aa, @tm["aa"]
|
107
|
+
assert_equal mid_z, @tm["z"]
|
108
|
+
assert_equal top_z, @tm["^z"]
|
109
|
+
assert_equal top_z, @tm["rake:z"]
|
110
|
+
end
|
111
|
+
|
112
|
+
assert_equal [], @tm.current_scope
|
113
|
+
|
114
|
+
assert_equal [], xx.scope
|
115
|
+
assert_equal ['a'], aa.scope
|
116
|
+
assert_equal ['a', 'b'], bb.scope
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_lookup_with_explicit_scopes
|
120
|
+
t1, t2, t3, s = (0...4).collect { nil }
|
121
|
+
t1 = @tm.define_task(Rake::Task, :t)
|
122
|
+
@tm.in_namespace("a") do
|
123
|
+
t2 = @tm.define_task(Rake::Task, :t)
|
124
|
+
s = @tm.define_task(Rake::Task, :s)
|
125
|
+
@tm.in_namespace("b") do
|
126
|
+
t3 = @tm.define_task(Rake::Task, :t)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
assert_equal t1, @tm[:t, []]
|
130
|
+
assert_equal t2, @tm[:t, ["a"]]
|
131
|
+
assert_equal t3, @tm[:t, ["a", "b"]]
|
132
|
+
assert_equal s, @tm[:s, ["a", "b"]]
|
133
|
+
assert_equal s, @tm[:s, ["a"]]
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_correctly_scoped_prerequisites_are_invoked
|
137
|
+
values = []
|
138
|
+
@tm = Rake::Application.new
|
139
|
+
@tm.num_threads = Rake.application.num_threads
|
140
|
+
@tm.define_task(Rake::Task, :z) do values << "top z" end
|
141
|
+
@tm.in_namespace("a") do
|
142
|
+
@tm.define_task(Rake::Task, :z) do values << "next z" end
|
143
|
+
@tm.define_task(Rake::Task, :x => :z)
|
144
|
+
end
|
145
|
+
|
146
|
+
@tm["a:x"].invoke
|
147
|
+
assert_equal ["next z"], values
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
class TestTaskManagerArgumentResolution < Test::Unit::TestCase
|
153
|
+
def test_good_arg_patterns
|
154
|
+
assert_equal [:t, [], []], task(:t)
|
155
|
+
assert_equal [:t, [], [:x]], task(:t => :x)
|
156
|
+
assert_equal [:t, [], [:x, :y]], task(:t => [:x, :y])
|
157
|
+
|
158
|
+
assert_equal [:t, [:a, :b], []], task(:t, :a, :b)
|
159
|
+
assert_equal [:t, [], [:x]], task(:t, :needs => :x)
|
160
|
+
assert_equal [:t, [:a, :b], [:x]], task(:t, :a, :b, :needs => :x)
|
161
|
+
assert_equal [:t, [:a, :b], [:x, :y]], task(:t, :a, :b, :needs => [:x, :y])
|
162
|
+
|
163
|
+
assert_equal [:t, [:a, :b], []], task(:t, [:a, :b])
|
164
|
+
assert_equal [:t, [:a, :b], [:x]], task(:t, [:a, :b] => :x)
|
165
|
+
assert_equal [:t, [:a, :b], [:x, :y]], task(:t, [:a, :b] => [:x, :y])
|
166
|
+
end
|
167
|
+
|
168
|
+
def task(*args)
|
169
|
+
tm = TaskManager.new
|
170
|
+
tm.resolve_args(args)
|
171
|
+
end
|
172
|
+
end
|