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
@@ -0,0 +1,714 @@
|
|
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 'rake'
|
11
|
+
require 'test/rake_test_setup'
|
12
|
+
require 'test/capture_stdout'
|
13
|
+
require 'test/in_environment'
|
14
|
+
|
15
|
+
TESTING_REQUIRE = [ ]
|
16
|
+
|
17
|
+
######################################################################
|
18
|
+
class TestApplication < Test::Unit::TestCase
|
19
|
+
include CaptureStdout
|
20
|
+
include InEnvironment
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@app = Rake::Application.new
|
24
|
+
@app.options.rakelib = []
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_constant_warning
|
28
|
+
err = capture_stderr do @app.instance_eval { const_warning("Task") } end
|
29
|
+
assert_match(/warning/i, err)
|
30
|
+
assert_match(/deprecated/i, err)
|
31
|
+
assert_match(/Task/i, err)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_display_tasks
|
35
|
+
@app.options.show_task_pattern = //
|
36
|
+
@app.last_description = "COMMENT"
|
37
|
+
@app.define_task(Rake::Task, "t")
|
38
|
+
out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
|
39
|
+
assert_match(/^rake t/, out)
|
40
|
+
assert_match(/# COMMENT/, out)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_display_tasks_with_long_comments
|
44
|
+
in_environment('RAKE_COLUMNS' => '80') do
|
45
|
+
@app.options.show_task_pattern = //
|
46
|
+
@app.last_description = "1234567890" * 8
|
47
|
+
@app.define_task(Rake::Task, "t")
|
48
|
+
out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
|
49
|
+
assert_match(/^rake t/, out)
|
50
|
+
assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_display_tasks_with_task_name_wider_than_tty_display
|
55
|
+
in_environment('RAKE_COLUMNS' => '80') do
|
56
|
+
@app.options.show_task_pattern = //
|
57
|
+
description = "something short"
|
58
|
+
task_name = "task name" * 80
|
59
|
+
@app.last_description = "something short"
|
60
|
+
@app.define_task(Rake::Task, task_name )
|
61
|
+
out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
|
62
|
+
# Ensure the entire task name is output and we end up showing no description
|
63
|
+
assert_match(/rake #{task_name} # .../, out)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_display_tasks_with_very_long_task_name_to_a_non_tty_shows_name_and_comment
|
68
|
+
@app.options.show_task_pattern = //
|
69
|
+
@app.tty_output = false
|
70
|
+
description = "something short"
|
71
|
+
task_name = "task name" * 80
|
72
|
+
@app.last_description = "something short"
|
73
|
+
@app.define_task(Rake::Task, task_name )
|
74
|
+
out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
|
75
|
+
# Ensure the entire task name is output and we end up showing no description
|
76
|
+
assert_match(/rake #{task_name} # #{description}/, out)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_display_tasks_with_long_comments_to_a_non_tty_shows_entire_comment
|
80
|
+
@app.options.show_task_pattern = //
|
81
|
+
@app.tty_output = false
|
82
|
+
@app.last_description = "1234567890" * 8
|
83
|
+
@app.define_task(Rake::Task, "t")
|
84
|
+
out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
|
85
|
+
assert_match(/^rake t/, out)
|
86
|
+
assert_match(/# #{@app.last_description}/, out)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_display_tasks_with_long_comments_to_a_non_tty_with_columns_set_truncates_comments
|
90
|
+
in_environment("RAKE_COLUMNS" => '80') do
|
91
|
+
@app.options.show_task_pattern = //
|
92
|
+
@app.tty_output = false
|
93
|
+
@app.last_description = "1234567890" * 8
|
94
|
+
@app.define_task(Rake::Task, "t")
|
95
|
+
out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
|
96
|
+
assert_match(/^rake t/, out)
|
97
|
+
assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_display_tasks_with_full_descriptions
|
102
|
+
@app.options.show_task_pattern = //
|
103
|
+
@app.options.full_description = true
|
104
|
+
@app.last_description = "COMMENT"
|
105
|
+
@app.define_task(Rake::Task, "t")
|
106
|
+
out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
|
107
|
+
assert_match(/^rake t$/, out)
|
108
|
+
assert_match(/^ {4}COMMENT$/, out)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_finding_rakefile
|
112
|
+
assert_equal "rakefile", @app.instance_eval { have_rakefile }.downcase
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_not_finding_rakefile
|
116
|
+
@app.instance_eval { @rakefiles = ['NEVER_FOUND'] }
|
117
|
+
assert( ! @app.instance_eval do have_rakefile end )
|
118
|
+
assert_nil @app.rakefile
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_load_rakefile
|
122
|
+
in_environment("PWD" => "test/data/unittest") do
|
123
|
+
@app.instance_eval do
|
124
|
+
handle_options
|
125
|
+
options.silent = true
|
126
|
+
load_rakefile
|
127
|
+
end
|
128
|
+
assert_equal "rakefile", @app.rakefile.downcase
|
129
|
+
assert_match(%r(unittest$), Dir.pwd)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_load_rakefile_from_subdir
|
134
|
+
in_environment("PWD" => "test/data/unittest/subdir") do
|
135
|
+
@app.instance_eval do
|
136
|
+
handle_options
|
137
|
+
options.silent = true
|
138
|
+
load_rakefile
|
139
|
+
end
|
140
|
+
assert_equal "rakefile", @app.rakefile.downcase
|
141
|
+
assert_match(%r(unittest$), Dir.pwd)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_load_rakefile_not_found
|
146
|
+
in_environment("PWD" => "/", "RAKE_SYSTEM" => 'not_exist') do
|
147
|
+
@app.instance_eval do
|
148
|
+
handle_options
|
149
|
+
options.silent = true
|
150
|
+
end
|
151
|
+
ex = assert_raise(RuntimeError) do
|
152
|
+
@app.instance_eval do raw_load_rakefile end
|
153
|
+
end
|
154
|
+
assert_match(/no rakefile found/i, ex.message)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_load_from_system_rakefile
|
159
|
+
in_environment('RAKE_SYSTEM' => 'test/data/sys') do
|
160
|
+
@app.options.rakelib = []
|
161
|
+
@app.instance_eval do
|
162
|
+
handle_options
|
163
|
+
options.silent = true
|
164
|
+
options.load_system = true
|
165
|
+
load_rakefile
|
166
|
+
end
|
167
|
+
assert_equal "test/data/sys", @app.system_dir
|
168
|
+
assert_nil @app.rakefile
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_load_from_system_rakefile_on_unix
|
173
|
+
flexmock(@app, :windows? => false,
|
174
|
+
:win32_system_dir => nil,
|
175
|
+
:load => nil)
|
176
|
+
flexmock(File).should_receive(:expand_path).with("~").and_return("/HOME")
|
177
|
+
flexmock(File).should_receive(:expand_path).and_return { |fn| fn }
|
178
|
+
|
179
|
+
in_environment('RAKE_SYSTEM' => nil) do
|
180
|
+
@app.options.rakelib = []
|
181
|
+
@app.instance_eval do
|
182
|
+
handle_options
|
183
|
+
options.silent = true
|
184
|
+
options.load_system = true
|
185
|
+
load_rakefile
|
186
|
+
end
|
187
|
+
assert_equal "/HOME/.rake", @app.system_dir
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_windows
|
192
|
+
assert ! (@app.windows? && @app.unix?)
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_load_from_system_rakefile_on_windows
|
196
|
+
flexmock(@app, :windows? => true,
|
197
|
+
:standard_system_dir => "XX")
|
198
|
+
flexmock(@app).should_receive(:directory?).with("/AD/Rake").and_return(true)
|
199
|
+
flexmock(@app).should_receive(:load).and_return { |fn| puts "LOADING #{fn}" }
|
200
|
+
in_environment('RAKE_SYSTEM' => nil, 'APPDATA' => '/AD') do
|
201
|
+
@app.options.rakelib = []
|
202
|
+
@app.instance_eval do
|
203
|
+
handle_options
|
204
|
+
options.silent = true
|
205
|
+
options.load_system = true
|
206
|
+
load_rakefile
|
207
|
+
end
|
208
|
+
assert_equal "/AD/Rake", @app.system_dir
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_load_from_system_rakefile_on_windows_with_no_appdata
|
213
|
+
flexmock(@app, :windows? => true,
|
214
|
+
:standard_system_dir => "XX"
|
215
|
+
)
|
216
|
+
flexmock(File).should_receive(:exists?).with("/AD/Rake").and_return(false)
|
217
|
+
out = capture_stderr do
|
218
|
+
assert_raise(SystemExit) do
|
219
|
+
in_environment('RAKE_SYSTEM' => nil, 'APPDATA' => "/AD") do
|
220
|
+
@app.options.rakelib = []
|
221
|
+
@app.instance_eval do
|
222
|
+
handle_options
|
223
|
+
options.silent = true
|
224
|
+
options.load_system = true
|
225
|
+
load_rakefile
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_loading_imports
|
233
|
+
mock = flexmock("loader")
|
234
|
+
mock.should_receive(:load).with("x.dummy").once
|
235
|
+
@app.instance_eval do
|
236
|
+
add_loader("dummy", mock)
|
237
|
+
add_import("x.dummy")
|
238
|
+
load_imports
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_building_imported_files_on_demand
|
243
|
+
mock = flexmock("loader")
|
244
|
+
mock.should_receive(:load).with("x.dummy").once
|
245
|
+
mock.should_receive(:make_dummy).with_no_args.once
|
246
|
+
@app.instance_eval do
|
247
|
+
intern(Rake::Task, "x.dummy").enhance do mock.make_dummy end
|
248
|
+
add_loader("dummy", mock)
|
249
|
+
add_import("x.dummy")
|
250
|
+
load_imports
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_good_run
|
255
|
+
ran = false
|
256
|
+
ARGV.clear
|
257
|
+
ARGV << '--rakelib=""'
|
258
|
+
@app.options.silent = true
|
259
|
+
@app.instance_eval do
|
260
|
+
intern(Rake::Task, "default").enhance { ran = true }
|
261
|
+
end
|
262
|
+
in_environment("PWD" => "test/data/default") do
|
263
|
+
@app.run
|
264
|
+
end
|
265
|
+
assert ran
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_display_task_run
|
269
|
+
ran = false
|
270
|
+
ARGV.clear
|
271
|
+
ARGV << '-f' << '-s' << '--tasks' << '--rakelib=""'
|
272
|
+
@app.last_description = "COMMENT"
|
273
|
+
@app.define_task(Rake::Task, "default")
|
274
|
+
out = capture_stdout { @app.run }
|
275
|
+
assert @app.options.show_tasks
|
276
|
+
assert ! ran
|
277
|
+
assert_match(/rake default/, out)
|
278
|
+
assert_match(/# COMMENT/, out)
|
279
|
+
end
|
280
|
+
|
281
|
+
def test_display_prereqs
|
282
|
+
ran = false
|
283
|
+
ARGV.clear
|
284
|
+
ARGV << '-f' << '-s' << '--prereqs' << '--rakelib=""'
|
285
|
+
@app.last_description = "COMMENT"
|
286
|
+
t = @app.define_task(Rake::Task, "default")
|
287
|
+
t.enhance([:a, :b])
|
288
|
+
@app.define_task(Rake::Task, "a")
|
289
|
+
@app.define_task(Rake::Task, "b")
|
290
|
+
out = capture_stdout { @app.run }
|
291
|
+
assert @app.options.show_prereqs
|
292
|
+
assert ! ran
|
293
|
+
assert_match(/rake a$/, out)
|
294
|
+
assert_match(/rake b$/, out)
|
295
|
+
assert_match(/rake default\n( *(a|b)\n){2}/m, out)
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_bad_run
|
299
|
+
@app.intern(Rake::Task, "default").enhance { fail }
|
300
|
+
ARGV.clear
|
301
|
+
ARGV << '-f' << '-s' << '--rakelib=""'
|
302
|
+
assert_raise(SystemExit) {
|
303
|
+
err = capture_stderr { @app.run }
|
304
|
+
assert_match(/see full trace/, err)
|
305
|
+
}
|
306
|
+
ensure
|
307
|
+
ARGV.clear
|
308
|
+
end
|
309
|
+
|
310
|
+
def test_bad_run_with_trace
|
311
|
+
@app.intern(Rake::Task, "default").enhance { fail }
|
312
|
+
ARGV.clear
|
313
|
+
ARGV << '-f' << '-s' << '-t'
|
314
|
+
assert_raise(SystemExit) {
|
315
|
+
err = capture_stderr { capture_stdout { @app.run } }
|
316
|
+
assert_no_match(/see full trace/, err)
|
317
|
+
}
|
318
|
+
ensure
|
319
|
+
ARGV.clear
|
320
|
+
end
|
321
|
+
|
322
|
+
def test_run_with_bad_options
|
323
|
+
@app.intern(Rake::Task, "default").enhance { fail }
|
324
|
+
ARGV.clear
|
325
|
+
ARGV << '-f' << '-s' << '--xyzzy'
|
326
|
+
assert_raise(SystemExit) {
|
327
|
+
err = capture_stderr { capture_stdout { @app.run } }
|
328
|
+
}
|
329
|
+
ensure
|
330
|
+
ARGV.clear
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
|
335
|
+
######################################################################
|
336
|
+
class TestApplicationOptions < Test::Unit::TestCase
|
337
|
+
include CaptureStdout
|
338
|
+
|
339
|
+
def setup
|
340
|
+
clear_argv
|
341
|
+
RakeFileUtils.verbose_flag = false
|
342
|
+
RakeFileUtils.nowrite_flag = false
|
343
|
+
TESTING_REQUIRE.clear
|
344
|
+
end
|
345
|
+
|
346
|
+
def teardown
|
347
|
+
clear_argv
|
348
|
+
RakeFileUtils.verbose_flag = false
|
349
|
+
RakeFileUtils.nowrite_flag = false
|
350
|
+
end
|
351
|
+
|
352
|
+
def clear_argv
|
353
|
+
while ! ARGV.empty?
|
354
|
+
ARGV.pop
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
def test_default_options
|
359
|
+
opts = command_line
|
360
|
+
assert_nil opts.classic_namespace
|
361
|
+
assert_nil opts.dryrun
|
362
|
+
assert_nil opts.full_description
|
363
|
+
assert_nil opts.ignore_system
|
364
|
+
assert_nil opts.load_system
|
365
|
+
assert_nil opts.nosearch
|
366
|
+
assert_equal ['rakelib'], opts.rakelib
|
367
|
+
assert_nil opts.show_prereqs
|
368
|
+
assert_nil opts.show_task_pattern
|
369
|
+
assert_nil opts.show_tasks
|
370
|
+
assert_nil opts.silent
|
371
|
+
assert_nil opts.trace
|
372
|
+
assert_equal ['rakelib'], opts.rakelib
|
373
|
+
assert ! RakeFileUtils.verbose_flag
|
374
|
+
assert ! RakeFileUtils.nowrite_flag
|
375
|
+
end
|
376
|
+
|
377
|
+
def test_dry_run
|
378
|
+
flags('--dry-run', '-n') do |opts|
|
379
|
+
assert opts.dryrun
|
380
|
+
assert opts.trace
|
381
|
+
assert RakeFileUtils.verbose_flag
|
382
|
+
assert RakeFileUtils.nowrite_flag
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
def test_describe
|
387
|
+
flags('--describe') do |opts|
|
388
|
+
assert opts.full_description
|
389
|
+
assert opts.show_tasks
|
390
|
+
assert_equal(//.to_s, opts.show_task_pattern.to_s)
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
def test_describe_with_pattern
|
395
|
+
flags('--describe=X') do |opts|
|
396
|
+
assert opts.full_description
|
397
|
+
assert opts.show_tasks
|
398
|
+
assert_equal(/X/.to_s, opts.show_task_pattern.to_s)
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
def test_execute
|
403
|
+
$xyzzy = 0
|
404
|
+
flags('--execute=$xyzzy=1', '-e $xyzzy=1') do |opts|
|
405
|
+
assert_equal 1, $xyzzy
|
406
|
+
assert_equal :exit, @exit
|
407
|
+
$xyzzy = 0
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
def test_execute_and_continue
|
412
|
+
$xyzzy = 0
|
413
|
+
flags('--execute-continue=$xyzzy=1', '-E $xyzzy=1') do |opts|
|
414
|
+
assert_equal 1, $xyzzy
|
415
|
+
assert_not_equal :exit, @exit
|
416
|
+
$xyzzy = 0
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
def test_execute_and_print
|
421
|
+
$xyzzy = 0
|
422
|
+
flags('--execute-print=$xyzzy="pugh"', '-p $xyzzy="pugh"') do |opts|
|
423
|
+
assert_equal 'pugh', $xyzzy
|
424
|
+
assert_equal :exit, @exit
|
425
|
+
assert_match(/^pugh$/, @out)
|
426
|
+
$xyzzy = 0
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
def test_help
|
431
|
+
flags('--help', '-H', '-h') do |opts|
|
432
|
+
assert_match(/\Arake/, @out)
|
433
|
+
assert_match(/\boptions\b/, @out)
|
434
|
+
assert_match(/\btargets\b/, @out)
|
435
|
+
assert_equal :exit, @exit
|
436
|
+
assert_equal :exit, @exit
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
def test_libdir
|
441
|
+
flags(['--libdir', 'xx'], ['-I', 'xx'], ['-Ixx']) do |opts|
|
442
|
+
$:.include?('xx')
|
443
|
+
end
|
444
|
+
ensure
|
445
|
+
$:.delete('xx')
|
446
|
+
end
|
447
|
+
|
448
|
+
def test_rakefile
|
449
|
+
flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
|
450
|
+
assert_equal ['RF'], @app.instance_eval { @rakefiles }
|
451
|
+
end
|
452
|
+
end
|
453
|
+
|
454
|
+
def test_rakelib
|
455
|
+
flags(['--rakelibdir', 'A:B:C'], ['--rakelibdir=A:B:C'], ['-R', 'A:B:C'], ['-RA:B:C']) do |opts|
|
456
|
+
assert_equal ['A', 'B', 'C'], opts.rakelib
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
def test_require
|
461
|
+
flags(['--require', 'test/reqfile'], '-rtest/reqfile2', '-rtest/reqfile3') do |opts|
|
462
|
+
end
|
463
|
+
assert TESTING_REQUIRE.include?(1)
|
464
|
+
assert TESTING_REQUIRE.include?(2)
|
465
|
+
assert TESTING_REQUIRE.include?(3)
|
466
|
+
assert_equal 3, TESTING_REQUIRE.size
|
467
|
+
end
|
468
|
+
|
469
|
+
def test_missing_require
|
470
|
+
ex = assert_raises(LoadError) do
|
471
|
+
flags(['--require', 'test/missing']) do |opts|
|
472
|
+
end
|
473
|
+
end
|
474
|
+
assert_match(/no such file/, ex.message)
|
475
|
+
assert_match(/test\/missing/, ex.message)
|
476
|
+
end
|
477
|
+
|
478
|
+
def test_prereqs
|
479
|
+
flags('--prereqs', '-P') do |opts|
|
480
|
+
assert opts.show_prereqs
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
def test_quiet
|
485
|
+
flags('--quiet', '-q') do |opts|
|
486
|
+
assert ! RakeFileUtils.verbose_flag
|
487
|
+
assert ! opts.silent
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
def test_no_search
|
492
|
+
flags('--nosearch', '--no-search', '-N') do |opts|
|
493
|
+
assert opts.nosearch
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
def test_silent
|
498
|
+
flags('--silent', '-s') do |opts|
|
499
|
+
assert ! RakeFileUtils.verbose_flag
|
500
|
+
assert opts.silent
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
def test_system
|
505
|
+
flags('--system', '-g') do |opts|
|
506
|
+
assert opts.load_system
|
507
|
+
end
|
508
|
+
end
|
509
|
+
|
510
|
+
def test_no_system
|
511
|
+
flags('--no-system', '-G') do |opts|
|
512
|
+
assert opts.ignore_system
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
516
|
+
def test_trace
|
517
|
+
flags('--trace', '-t') do |opts|
|
518
|
+
assert opts.trace
|
519
|
+
assert RakeFileUtils.verbose_flag
|
520
|
+
assert ! RakeFileUtils.nowrite_flag
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
def test_trace_rules
|
525
|
+
flags('--rules') do |opts|
|
526
|
+
assert opts.trace_rules
|
527
|
+
end
|
528
|
+
end
|
529
|
+
|
530
|
+
def test_tasks
|
531
|
+
flags('--tasks', '-T') do |opts|
|
532
|
+
assert opts.show_tasks
|
533
|
+
assert_equal(//.to_s, opts.show_task_pattern.to_s)
|
534
|
+
end
|
535
|
+
flags(['--tasks', 'xyz'], ['-Txyz']) do |opts|
|
536
|
+
assert opts.show_tasks
|
537
|
+
assert_equal(/xyz/, opts.show_task_pattern)
|
538
|
+
end
|
539
|
+
end
|
540
|
+
|
541
|
+
def test_verbose
|
542
|
+
flags('--verbose', '-V') do |opts|
|
543
|
+
assert RakeFileUtils.verbose_flag
|
544
|
+
assert ! opts.silent
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
def test_version
|
549
|
+
flags('--version', '-V') do |opts|
|
550
|
+
assert_match(/\bversion\b/, @out)
|
551
|
+
assert_match(/\b#{RAKEVERSION}\b/, @out)
|
552
|
+
assert_equal :exit, @exit
|
553
|
+
end
|
554
|
+
end
|
555
|
+
|
556
|
+
def test_classic_namespace
|
557
|
+
flags(['--classic-namespace'], ['-C', '-T', '-P', '-n', '-s', '-t']) do |opts|
|
558
|
+
assert opts.classic_namespace
|
559
|
+
assert_equal opts.show_tasks, $show_tasks
|
560
|
+
assert_equal opts.show_prereqs, $show_prereqs
|
561
|
+
assert_equal opts.trace, $trace
|
562
|
+
assert_equal opts.dryrun, $dryrun
|
563
|
+
assert_equal opts.silent, $silent
|
564
|
+
end
|
565
|
+
end
|
566
|
+
|
567
|
+
def test_bad_option
|
568
|
+
capture_stderr do
|
569
|
+
ex = assert_raise(OptionParser::InvalidOption) do
|
570
|
+
flags('--bad-option')
|
571
|
+
end
|
572
|
+
if ex.message =~ /^While/ # Ruby 1.9 error message
|
573
|
+
assert_match(/while parsing/i, ex.message)
|
574
|
+
else # Ruby 1.8 error message
|
575
|
+
assert_match(/(invalid|unrecognized) option/i, ex.message)
|
576
|
+
assert_match(/--bad-option/, ex.message)
|
577
|
+
end
|
578
|
+
end
|
579
|
+
end
|
580
|
+
|
581
|
+
def test_task_collection
|
582
|
+
command_line("a", "b")
|
583
|
+
assert_equal ["a", "b"], @tasks.sort
|
584
|
+
end
|
585
|
+
|
586
|
+
def test_default_task_collection
|
587
|
+
command_line()
|
588
|
+
assert_equal ["default"], @tasks
|
589
|
+
end
|
590
|
+
|
591
|
+
def test_environment_definition
|
592
|
+
ENV.delete('TESTKEY')
|
593
|
+
command_line("a", "TESTKEY=12")
|
594
|
+
assert_equal ["a"], @tasks.sort
|
595
|
+
assert '12', ENV['TESTKEY']
|
596
|
+
end
|
597
|
+
|
598
|
+
private
|
599
|
+
|
600
|
+
def flags(*sets)
|
601
|
+
sets.each do |set|
|
602
|
+
ARGV.clear
|
603
|
+
@out = capture_stdout {
|
604
|
+
@exit = catch(:system_exit) { opts = command_line(*set) }
|
605
|
+
}
|
606
|
+
yield(@app.options) if block_given?
|
607
|
+
end
|
608
|
+
end
|
609
|
+
|
610
|
+
def command_line(*options)
|
611
|
+
options.each do |opt| ARGV << opt end
|
612
|
+
@app = Rake::Application.new
|
613
|
+
def @app.exit(*args)
|
614
|
+
throw :system_exit, :exit
|
615
|
+
end
|
616
|
+
@app.instance_eval do
|
617
|
+
collect_tasks handle_options
|
618
|
+
end
|
619
|
+
@tasks = @app.top_level_tasks
|
620
|
+
@app.options
|
621
|
+
end
|
622
|
+
end
|
623
|
+
|
624
|
+
class TestTaskArgumentParsing < Test::Unit::TestCase
|
625
|
+
def setup
|
626
|
+
@app = Rake::Application.new
|
627
|
+
end
|
628
|
+
|
629
|
+
def test_name_only
|
630
|
+
name, args = @app.parse_task_string("name")
|
631
|
+
assert_equal "name", name
|
632
|
+
assert_equal [], args
|
633
|
+
end
|
634
|
+
|
635
|
+
def test_empty_args
|
636
|
+
name, args = @app.parse_task_string("name[]")
|
637
|
+
assert_equal "name", name
|
638
|
+
assert_equal [], args
|
639
|
+
end
|
640
|
+
|
641
|
+
def test_one_argument
|
642
|
+
name, args = @app.parse_task_string("name[one]")
|
643
|
+
assert_equal "name", name
|
644
|
+
assert_equal ["one"], args
|
645
|
+
end
|
646
|
+
|
647
|
+
def test_two_arguments
|
648
|
+
name, args = @app.parse_task_string("name[one,two]")
|
649
|
+
assert_equal "name", name
|
650
|
+
assert_equal ["one", "two"], args
|
651
|
+
end
|
652
|
+
|
653
|
+
def test_can_handle_spaces_between_args
|
654
|
+
name, args = @app.parse_task_string("name[one, two,\tthree , \tfour]")
|
655
|
+
assert_equal "name", name
|
656
|
+
assert_equal ["one", "two", "three", "four"], args
|
657
|
+
end
|
658
|
+
|
659
|
+
def test_keeps_embedded_spaces
|
660
|
+
name, args = @app.parse_task_string("name[a one ana, two]")
|
661
|
+
assert_equal "name", name
|
662
|
+
assert_equal ["a one ana", "two"], args
|
663
|
+
end
|
664
|
+
|
665
|
+
end
|
666
|
+
|
667
|
+
class TestTaskArgumentParsing < Test::Unit::TestCase
|
668
|
+
include InEnvironment
|
669
|
+
|
670
|
+
def test_terminal_width_using_env
|
671
|
+
app = Rake::Application.new
|
672
|
+
in_environment('RAKE_COLUMNS' => '1234') do
|
673
|
+
assert_equal 1234, app.terminal_width
|
674
|
+
end
|
675
|
+
end
|
676
|
+
|
677
|
+
def test_terminal_width_using_stty
|
678
|
+
app = Rake::Application.new
|
679
|
+
flexmock(app,
|
680
|
+
:unix? => true,
|
681
|
+
:dynamic_width_stty => 1235,
|
682
|
+
:dynamic_width_tput => 0)
|
683
|
+
in_environment('RAKE_COLUMNS' => nil) do
|
684
|
+
assert_equal 1235, app.terminal_width
|
685
|
+
end
|
686
|
+
end
|
687
|
+
|
688
|
+
def test_terminal_width_using_tput
|
689
|
+
app = Rake::Application.new
|
690
|
+
flexmock(app,
|
691
|
+
:unix? => true,
|
692
|
+
:dynamic_width_stty => 0,
|
693
|
+
:dynamic_width_tput => 1236)
|
694
|
+
in_environment('RAKE_COLUMNS' => nil) do
|
695
|
+
assert_equal 1236, app.terminal_width
|
696
|
+
end
|
697
|
+
end
|
698
|
+
|
699
|
+
def test_terminal_width_using_hardcoded_80
|
700
|
+
app = Rake::Application.new
|
701
|
+
flexmock(app, :unix? => false)
|
702
|
+
in_environment('RAKE_COLUMNS' => nil) do
|
703
|
+
assert_equal 80, app.terminal_width
|
704
|
+
end
|
705
|
+
end
|
706
|
+
|
707
|
+
def test_terminal_width_with_failure
|
708
|
+
app = Rake::Application.new
|
709
|
+
flexmock(app).should_receive(:unix?).and_throw(RuntimeError)
|
710
|
+
in_environment('RAKE_COLUMNS' => nil) do
|
711
|
+
assert_equal 80, app.terminal_width
|
712
|
+
end
|
713
|
+
end
|
714
|
+
end
|