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