craigmarksmith-rake 0.8.3.100
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +427 -0
- data/MIT-LICENSE +21 -0
- data/README +196 -0
- data/Rakefile +416 -0
- data/TODO +20 -0
- data/bin/rake +31 -0
- data/doc/command_line_usage.rdoc +102 -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 +165 -0
- data/doc/release_notes/rake-0.8.3.rdoc +112 -0
- data/doc/release_notes/rake-0.8.4.rdoc +147 -0
- data/install.rb +88 -0
- data/lib/rake/classic_namespace.rb +8 -0
- data/lib/rake/clean.rb +33 -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 +97 -0
- data/lib/rake/loaders/makefile.rb +42 -0
- data/lib/rake/packagetask.rb +184 -0
- data/lib/rake/rake_test_loader.rb +5 -0
- data/lib/rake/rdoctask.rb +209 -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/lib/rake/win32.rb +55 -0
- data/lib/rake.rb +2519 -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 +14 -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/rake_test_setup.rb +24 -0
- data/test/reqfile.rb +3 -0
- data/test/reqfile2.rb +3 -0
- data/test/session_functional.rb +339 -0
- data/test/shellcommand.rb +3 -0
- data/test/test_application.rb +690 -0
- data/test/test_clean.rb +14 -0
- data/test/test_definitions.rb +85 -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 +143 -0
- data/test/test_filelist.rb +623 -0
- data/test/test_fileutils.rb +251 -0
- data/test/test_ftp.rb +59 -0
- data/test/test_invocation_chain.rb +81 -0
- data/test/test_makefile_loader.rb +26 -0
- data/test/test_multitask.rb +45 -0
- data/test/test_namespace.rb +55 -0
- data/test/test_package_task.rb +118 -0
- data/test/test_pathmap.rb +210 -0
- data/test/test_rake.rb +41 -0
- data/test/test_rdoc_task.rb +88 -0
- data/test/test_require.rb +35 -0
- data/test/test_rules.rb +349 -0
- data/test/test_task_arguments.rb +89 -0
- data/test/test_task_manager.rb +173 -0
- data/test/test_tasklib.rb +12 -0
- data/test/test_tasks.rb +374 -0
- data/test/test_test_task.rb +77 -0
- data/test/test_top_level_functions.rb +86 -0
- data/test/test_win32.rb +72 -0
- metadata +186 -0
@@ -0,0 +1,173 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rake'
|
5
|
+
require 'test/rake_test_setup'
|
6
|
+
|
7
|
+
class TaskManager
|
8
|
+
include Rake::TaskManager
|
9
|
+
end
|
10
|
+
|
11
|
+
class TestTaskManager < Test::Unit::TestCase
|
12
|
+
include TestMethods
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@tm = TaskManager.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_create_task_manager
|
19
|
+
assert_not_nil @tm
|
20
|
+
assert_equal [], @tm.tasks
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_define_task
|
24
|
+
t = @tm.define_task(Rake::Task, :t)
|
25
|
+
assert_equal "t", t.name
|
26
|
+
assert_equal @tm, t.application
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_name_lookup
|
30
|
+
t = @tm.define_task(Rake::Task, :t)
|
31
|
+
assert_equal t, @tm[:t]
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_namespace_task_create
|
35
|
+
@tm.in_namespace("x") do
|
36
|
+
t = @tm.define_task(Rake::Task, :t)
|
37
|
+
assert_equal "x:t", t.name
|
38
|
+
end
|
39
|
+
assert_equal ["x:t"], @tm.tasks.collect { |t| t.name }
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_anonymous_namespace
|
43
|
+
anon_ns = @tm.in_namespace(nil) do
|
44
|
+
t = @tm.define_task(Rake::Task, :t)
|
45
|
+
assert_equal "_anon_1:t", t.name
|
46
|
+
end
|
47
|
+
task = anon_ns[:t]
|
48
|
+
assert_equal "_anon_1:t", task.name
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_create_filetask_in_namespace
|
52
|
+
@tm.in_namespace("x") do
|
53
|
+
t = @tm.define_task(Rake::FileTask, "fn")
|
54
|
+
assert_equal "fn", t.name
|
55
|
+
end
|
56
|
+
assert_equal ["fn"], @tm.tasks.collect { |t| t.name }
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_namespace_yields_same_namespace_as_returned
|
60
|
+
yielded_namespace = nil
|
61
|
+
returned_namespace = @tm.in_namespace("x") do |ns|
|
62
|
+
yielded_namespace = ns
|
63
|
+
end
|
64
|
+
assert_equal returned_namespace, yielded_namespace
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_name_lookup_with_implicit_file_tasks
|
68
|
+
t = @tm["README"]
|
69
|
+
assert_equal "README", t.name
|
70
|
+
assert Rake::FileTask === t
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_name_lookup_with_nonexistent_task
|
74
|
+
assert_exception(RuntimeError) {
|
75
|
+
t = @tm["DOES NOT EXIST"]
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_name_lookup_in_multiple_scopes
|
80
|
+
aa = nil
|
81
|
+
bb = nil
|
82
|
+
xx = @tm.define_task(Rake::Task, :xx)
|
83
|
+
top_z = @tm.define_task(Rake::Task, :z)
|
84
|
+
@tm.in_namespace("a") do
|
85
|
+
aa = @tm.define_task(Rake::Task, :aa)
|
86
|
+
mid_z = @tm.define_task(Rake::Task, :z)
|
87
|
+
@tm.in_namespace("b") do
|
88
|
+
bb = @tm.define_task(Rake::Task, :bb)
|
89
|
+
bot_z = @tm.define_task(Rake::Task, :z)
|
90
|
+
|
91
|
+
assert_equal ["a", "b"], @tm.current_scope
|
92
|
+
|
93
|
+
assert_equal bb, @tm["a:b:bb"]
|
94
|
+
assert_equal aa, @tm["a:aa"]
|
95
|
+
assert_equal xx, @tm["xx"]
|
96
|
+
assert_equal bot_z, @tm["z"]
|
97
|
+
assert_equal mid_z, @tm["^z"]
|
98
|
+
assert_equal top_z, @tm["^^z"]
|
99
|
+
assert_equal top_z, @tm["rake:z"]
|
100
|
+
end
|
101
|
+
|
102
|
+
assert_equal ["a"], @tm.current_scope
|
103
|
+
|
104
|
+
assert_equal bb, @tm["a:b:bb"]
|
105
|
+
assert_equal aa, @tm["a:aa"]
|
106
|
+
assert_equal xx, @tm["xx"]
|
107
|
+
assert_equal bb, @tm["b:bb"]
|
108
|
+
assert_equal aa, @tm["aa"]
|
109
|
+
assert_equal mid_z, @tm["z"]
|
110
|
+
assert_equal top_z, @tm["^z"]
|
111
|
+
assert_equal top_z, @tm["rake:z"]
|
112
|
+
end
|
113
|
+
|
114
|
+
assert_equal [], @tm.current_scope
|
115
|
+
|
116
|
+
assert_equal [], xx.scope
|
117
|
+
assert_equal ['a'], aa.scope
|
118
|
+
assert_equal ['a', 'b'], bb.scope
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_lookup_with_explicit_scopes
|
122
|
+
t1, t2, t3, s = (0...4).collect { nil }
|
123
|
+
t1 = @tm.define_task(Rake::Task, :t)
|
124
|
+
@tm.in_namespace("a") do
|
125
|
+
t2 = @tm.define_task(Rake::Task, :t)
|
126
|
+
s = @tm.define_task(Rake::Task, :s)
|
127
|
+
@tm.in_namespace("b") do
|
128
|
+
t3 = @tm.define_task(Rake::Task, :t)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
assert_equal t1, @tm[:t, []]
|
132
|
+
assert_equal t2, @tm[:t, ["a"]]
|
133
|
+
assert_equal t3, @tm[:t, ["a", "b"]]
|
134
|
+
assert_equal s, @tm[:s, ["a", "b"]]
|
135
|
+
assert_equal s, @tm[:s, ["a"]]
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_correctly_scoped_prerequisites_are_invoked
|
139
|
+
values = []
|
140
|
+
@tm = Rake::Application.new
|
141
|
+
@tm.define_task(Rake::Task, :z) do values << "top z" end
|
142
|
+
@tm.in_namespace("a") do
|
143
|
+
@tm.define_task(Rake::Task, :z) do values << "next z" end
|
144
|
+
@tm.define_task(Rake::Task, :x => :z)
|
145
|
+
end
|
146
|
+
|
147
|
+
@tm["a:x"].invoke
|
148
|
+
assert_equal ["next z"], values
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
class TestTaskManagerArgumentResolution < Test::Unit::TestCase
|
154
|
+
def test_good_arg_patterns
|
155
|
+
assert_equal [:t, [], []], task(:t)
|
156
|
+
assert_equal [:t, [], [:x]], task(:t => :x)
|
157
|
+
assert_equal [:t, [], [:x, :y]], task(:t => [:x, :y])
|
158
|
+
|
159
|
+
assert_equal [:t, [:a, :b], []], task(:t, :a, :b)
|
160
|
+
assert_equal [:t, [], [:x]], task(:t, :needs => :x)
|
161
|
+
assert_equal [:t, [:a, :b], [:x]], task(:t, :a, :b, :needs => :x)
|
162
|
+
assert_equal [:t, [:a, :b], [:x, :y]], task(:t, :a, :b, :needs => [:x, :y])
|
163
|
+
|
164
|
+
assert_equal [:t, [:a, :b], []], task(:t, [:a, :b])
|
165
|
+
assert_equal [:t, [:a, :b], [:x]], task(:t, [:a, :b] => :x)
|
166
|
+
assert_equal [:t, [:a, :b], [:x, :y]], task(:t, [:a, :b] => [:x, :y])
|
167
|
+
end
|
168
|
+
|
169
|
+
def task(*args)
|
170
|
+
tm = TaskManager.new
|
171
|
+
tm.resolve_args(args)
|
172
|
+
end
|
173
|
+
end
|
data/test/test_tasks.rb
ADDED
@@ -0,0 +1,374 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'rake'
|
6
|
+
require 'test/filecreation'
|
7
|
+
require 'test/capture_stdout'
|
8
|
+
require 'test/rake_test_setup'
|
9
|
+
|
10
|
+
######################################################################
|
11
|
+
class TestTask < Test::Unit::TestCase
|
12
|
+
include CaptureStdout
|
13
|
+
include Rake
|
14
|
+
include TestMethods
|
15
|
+
|
16
|
+
def setup
|
17
|
+
Task.clear
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_create
|
21
|
+
arg = nil
|
22
|
+
t = task(:name) { |task| arg = task; 1234 }
|
23
|
+
assert_equal "name", t.name
|
24
|
+
assert_equal [], t.prerequisites
|
25
|
+
assert t.needed?
|
26
|
+
t.execute(0)
|
27
|
+
assert_equal t, arg
|
28
|
+
assert_nil t.source
|
29
|
+
assert_equal [], t.sources
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_inspect
|
33
|
+
t = task(:foo, :needs => [:bar, :baz])
|
34
|
+
assert_equal "<Rake::Task foo => [bar, baz]>", t.inspect
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_invoke
|
38
|
+
runlist = []
|
39
|
+
t1 = task(:t1 => [:t2, :t3]) { |t| runlist << t.name; 3321 }
|
40
|
+
t2 = task(:t2) { |t| runlist << t.name }
|
41
|
+
t3 = task(:t3) { |t| runlist << t.name }
|
42
|
+
assert_equal ["t2", "t3"], t1.prerequisites
|
43
|
+
t1.invoke
|
44
|
+
assert_equal ["t2", "t3", "t1"], runlist
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_invoke_with_circular_dependencies
|
48
|
+
runlist = []
|
49
|
+
t1 = task(:t1 => [:t2]) { |t| runlist << t.name; 3321 }
|
50
|
+
t2 = task(:t2 => [:t1]) { |t| runlist << t.name }
|
51
|
+
assert_equal ["t2"], t1.prerequisites
|
52
|
+
assert_equal ["t1"], t2.prerequisites
|
53
|
+
ex = assert_exception RuntimeError do
|
54
|
+
t1.invoke
|
55
|
+
end
|
56
|
+
assert_match(/circular dependency/i, ex.message)
|
57
|
+
assert_match(/t1 => t2 => t1/, ex.message)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_dry_run_prevents_actions
|
61
|
+
Rake.application.options.dryrun = true
|
62
|
+
runlist = []
|
63
|
+
t1 = task(:t1) { |t| runlist << t.name; 3321 }
|
64
|
+
out = capture_stdout { t1.invoke }
|
65
|
+
assert_match(/execute .*t1/i, out)
|
66
|
+
assert_match(/dry run/i, out)
|
67
|
+
assert_no_match(/invoke/i, out)
|
68
|
+
assert_equal [], runlist
|
69
|
+
ensure
|
70
|
+
Rake.application.options.dryrun = false
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_tasks_can_be_traced
|
74
|
+
Rake.application.options.trace = true
|
75
|
+
t1 = task(:t1)
|
76
|
+
out = capture_stdout {
|
77
|
+
t1.invoke
|
78
|
+
}
|
79
|
+
assert_match(/invoke t1/i, out)
|
80
|
+
assert_match(/execute t1/i, out)
|
81
|
+
ensure
|
82
|
+
Rake.application.options.trace = false
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_no_double_invoke
|
86
|
+
runlist = []
|
87
|
+
t1 = task(:t1 => [:t2, :t3]) { |t| runlist << t.name; 3321 }
|
88
|
+
t2 = task(:t2 => [:t3]) { |t| runlist << t.name }
|
89
|
+
t3 = task(:t3) { |t| runlist << t.name }
|
90
|
+
t1.invoke
|
91
|
+
assert_equal ["t3", "t2", "t1"], runlist
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_can_double_invoke_with_reenable
|
95
|
+
runlist = []
|
96
|
+
t1 = task(:t1) { |t| runlist << t.name }
|
97
|
+
t1.invoke
|
98
|
+
t1.reenable
|
99
|
+
t1.invoke
|
100
|
+
assert_equal ["t1", "t1"], runlist
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_clear
|
104
|
+
t = task("t" => "a") { }
|
105
|
+
t.clear
|
106
|
+
assert t.prerequisites.empty?, "prerequisites should be empty"
|
107
|
+
assert t.actions.empty?, "actions should be empty"
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_clear_prerequisites
|
111
|
+
t = task("t" => ["a", "b"])
|
112
|
+
assert_equal ['a', 'b'], t.prerequisites
|
113
|
+
t.clear_prerequisites
|
114
|
+
assert_equal [], t.prerequisites
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_clear_actions
|
118
|
+
t = task("t") { }
|
119
|
+
t.clear_actions
|
120
|
+
assert t.actions.empty?, "actions should be empty"
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_find
|
124
|
+
task :tfind
|
125
|
+
assert_equal "tfind", Task[:tfind].name
|
126
|
+
ex = assert_exception(RuntimeError) { Task[:leaves] }
|
127
|
+
assert_equal "Don't know how to build task 'leaves'", ex.message
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_defined
|
131
|
+
assert ! Task.task_defined?(:a)
|
132
|
+
task :a
|
133
|
+
assert Task.task_defined?(:a)
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_multi_invocations
|
137
|
+
runs = []
|
138
|
+
p = proc do |t| runs << t.name end
|
139
|
+
task({:t1=>[:t2,:t3]}, &p)
|
140
|
+
task({:t2=>[:t3]}, &p)
|
141
|
+
task(:t3, &p)
|
142
|
+
Task[:t1].invoke
|
143
|
+
assert_equal ["t1", "t2", "t3"], runs.sort
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_task_list
|
147
|
+
task :t2
|
148
|
+
task :t1 => [:t2]
|
149
|
+
assert_equal ["t1", "t2"], Task.tasks.collect {|t| t.name}
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_task_gives_name_on_to_s
|
153
|
+
task :abc
|
154
|
+
assert_equal "abc", Task[:abc].to_s
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_symbols_can_be_prerequisites
|
158
|
+
task :a => :b
|
159
|
+
assert_equal ["b"], Task[:a].prerequisites
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_strings_can_be_prerequisites
|
163
|
+
task :a => "b"
|
164
|
+
assert_equal ["b"], Task[:a].prerequisites
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_arrays_can_be_prerequisites
|
168
|
+
task :a => ["b", "c"]
|
169
|
+
assert_equal ["b", "c"], Task[:a].prerequisites
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_filelists_can_be_prerequisites
|
173
|
+
task :a => FileList.new.include("b", "c")
|
174
|
+
assert_equal ["b", "c"], Task[:a].prerequisites
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_investigation_output
|
178
|
+
t1 = task(:t1 => [:t2, :t3]) { |t| runlist << t.name; 3321 }
|
179
|
+
task(:t2)
|
180
|
+
task(:t3)
|
181
|
+
out = t1.investigation
|
182
|
+
assert_match(/class:\s*Rake::Task/, out)
|
183
|
+
assert_match(/needed:\s*true/, out)
|
184
|
+
assert_match(/pre-requisites:\s*--t[23]/, out)
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
def test_extended_comments
|
189
|
+
desc %{
|
190
|
+
This is a comment.
|
191
|
+
|
192
|
+
And this is the extended comment.
|
193
|
+
name -- Name of task to execute.
|
194
|
+
rev -- Software revision to use.
|
195
|
+
}
|
196
|
+
t = task(:t, :name, :rev)
|
197
|
+
assert_equal "[name,rev]", t.arg_description
|
198
|
+
assert_equal "This is a comment.", t.comment
|
199
|
+
assert_match(/^\s*name -- Name/, t.full_comment)
|
200
|
+
assert_match(/^\s*rev -- Software/, t.full_comment)
|
201
|
+
assert_match(/\A\s*This is a comment\.$/, t.full_comment)
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_multiple_comments
|
205
|
+
desc "line one"
|
206
|
+
t = task(:t)
|
207
|
+
desc "line two"
|
208
|
+
task(:t)
|
209
|
+
assert_equal "line one / line two", t.comment
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_settable_comments
|
213
|
+
t = task(:t)
|
214
|
+
t.comment = "HI"
|
215
|
+
assert_equal "HI", t.comment
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
######################################################################
|
220
|
+
class TestTaskWithArguments < Test::Unit::TestCase
|
221
|
+
include CaptureStdout
|
222
|
+
include Rake
|
223
|
+
include TestMethods
|
224
|
+
|
225
|
+
def setup
|
226
|
+
Task.clear
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_no_args_given
|
230
|
+
t = task :t
|
231
|
+
assert_equal [], t.arg_names
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_args_given
|
235
|
+
t = task :t, :a, :b
|
236
|
+
assert_equal [:a, :b], t.arg_names
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_name_and_needs
|
240
|
+
t = task(:t => [:pre])
|
241
|
+
assert_equal "t", t.name
|
242
|
+
assert_equal [], t.arg_names
|
243
|
+
assert_equal ["pre"], t.prerequisites
|
244
|
+
end
|
245
|
+
|
246
|
+
def test_name_and_explicit_needs
|
247
|
+
t = task(:t, :needs => [:pre])
|
248
|
+
assert_equal "t", t.name
|
249
|
+
assert_equal [], t.arg_names
|
250
|
+
assert_equal ["pre"], t.prerequisites
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_name_args_and_explicit_needs
|
254
|
+
t = task(:t, :x, :y, :needs => [:pre])
|
255
|
+
assert_equal "t", t.name
|
256
|
+
assert_equal [:x, :y], t.arg_names
|
257
|
+
assert_equal ["pre"], t.prerequisites
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_illegal_keys_in_task_name_hash
|
261
|
+
assert_exception RuntimeError do
|
262
|
+
t = task(:t, :x, :y => 1, :needs => [:pre])
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_arg_list_is_empty_if_no_args_given
|
267
|
+
t = task(:t) { |tt, args| assert_equal({}, args.to_hash) }
|
268
|
+
t.invoke(1, 2, 3)
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_tasks_can_access_arguments_as_hash
|
272
|
+
t = task :t, :a, :b, :c do |tt, args|
|
273
|
+
assert_equal({:a => 1, :b => 2, :c => 3}, args.to_hash)
|
274
|
+
assert_equal 1, args[:a]
|
275
|
+
assert_equal 2, args[:b]
|
276
|
+
assert_equal 3, args[:c]
|
277
|
+
assert_equal 1, args.a
|
278
|
+
assert_equal 2, args.b
|
279
|
+
assert_equal 3, args.c
|
280
|
+
end
|
281
|
+
t.invoke(1, 2, 3)
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_actions_of_various_arity_are_ok_with_args
|
285
|
+
notes = []
|
286
|
+
t = task(:t, :x) do
|
287
|
+
notes << :a
|
288
|
+
end
|
289
|
+
t.enhance do | |
|
290
|
+
notes << :b
|
291
|
+
end
|
292
|
+
t.enhance do |task|
|
293
|
+
notes << :c
|
294
|
+
assert_kind_of Task, task
|
295
|
+
end
|
296
|
+
t.enhance do |t2, args|
|
297
|
+
notes << :d
|
298
|
+
assert_equal t, t2
|
299
|
+
assert_equal({:x => 1}, args.to_hash)
|
300
|
+
end
|
301
|
+
assert_nothing_raised do t.invoke(1) end
|
302
|
+
assert_equal [:a, :b, :c, :d], notes
|
303
|
+
end
|
304
|
+
|
305
|
+
def test_arguments_are_passed_to_block
|
306
|
+
t = task(:t, :a, :b) { |tt, args|
|
307
|
+
assert_equal( { :a => 1, :b => 2 }, args.to_hash )
|
308
|
+
}
|
309
|
+
t.invoke(1, 2)
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_extra_parameters_are_ignored
|
313
|
+
t = task(:t, :a) { |tt, args|
|
314
|
+
assert_equal 1, args.a
|
315
|
+
assert_nil args.b
|
316
|
+
}
|
317
|
+
t.invoke(1, 2)
|
318
|
+
end
|
319
|
+
|
320
|
+
def test_arguments_are_passed_to_all_blocks
|
321
|
+
counter = 0
|
322
|
+
t = task :t, :a
|
323
|
+
task :t do |tt, args|
|
324
|
+
assert_equal 1, args.a
|
325
|
+
counter += 1
|
326
|
+
end
|
327
|
+
task :t do |tt, args|
|
328
|
+
assert_equal 1, args.a
|
329
|
+
counter += 1
|
330
|
+
end
|
331
|
+
t.invoke(1)
|
332
|
+
assert_equal 2, counter
|
333
|
+
end
|
334
|
+
|
335
|
+
def test_block_with_no_parameters_is_ok
|
336
|
+
t = task(:t) { }
|
337
|
+
t.invoke(1, 2)
|
338
|
+
end
|
339
|
+
|
340
|
+
def test_name_with_args
|
341
|
+
desc "T"
|
342
|
+
t = task(:tt, :a, :b)
|
343
|
+
assert_equal "tt", t.name
|
344
|
+
assert_equal "T", t.comment
|
345
|
+
assert_equal "[a,b]", t.arg_description
|
346
|
+
assert_equal "tt[a,b]", t.name_with_args
|
347
|
+
assert_equal [:a, :b],t.arg_names
|
348
|
+
end
|
349
|
+
|
350
|
+
def test_named_args_are_passed_to_prereqs
|
351
|
+
value = nil
|
352
|
+
pre = task(:pre, :rev) { |t, args| value = args.rev }
|
353
|
+
t = task(:t, :name, :rev, :needs => [:pre])
|
354
|
+
t.invoke("bill", "1.2")
|
355
|
+
assert_equal "1.2", value
|
356
|
+
end
|
357
|
+
|
358
|
+
def test_args_not_passed_if_no_prereq_names
|
359
|
+
pre = task(:pre) { |t, args|
|
360
|
+
assert_equal({}, args.to_hash)
|
361
|
+
assert_equal "bill", args.name
|
362
|
+
}
|
363
|
+
t = task(:t, :name, :rev, :needs => [:pre])
|
364
|
+
t.invoke("bill", "1.2")
|
365
|
+
end
|
366
|
+
|
367
|
+
def test_args_not_passed_if_no_arg_names
|
368
|
+
pre = task(:pre, :rev) { |t, args|
|
369
|
+
assert_equal({}, args.to_hash)
|
370
|
+
}
|
371
|
+
t = task(:t, :needs => [:pre])
|
372
|
+
t.invoke("bill", "1.2")
|
373
|
+
end
|
374
|
+
end
|