Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 866 lines (760 sloc) 22.418 kb
cbce3c7 @drbrain Make test file requires directory independent
drbrain authored
1 require File.expand_path('../helper', __FILE__)
c8197eb added rcov and unit tests
jimweirich authored
2
3 TESTING_REQUIRE = [ ]
4
5 ######################################################################
0534fa5 @drbrain Tests now inherit from Rake::TestCase instead of Test::Unit::TestCase…
drbrain authored
6 class TestRakeApplication < Rake::TestCase
f29ae0a @jimweirich fixed finding global rakefiles when no project available. Fixed nose…
authored
7 include InEnvironment
c8197eb added rcov and unit tests
jimweirich authored
8
9 def setup
43f2ec6 @jimweirich Cleanup up tests. Added prereq and timestamp tests.
authored
10 super
cbce3c7 @drbrain Make test file requires directory independent
drbrain authored
11
c8197eb added rcov and unit tests
jimweirich authored
12 @app = Rake::Application.new
991f432 Ruby 1.9 commit
jimweirich authored
13 @app.options.rakelib = []
f191142 @jimweirich Optimized comment loading to only happen with -T, -D or -W options.
authored
14 Rake::TaskManager.record_task_metadata = true
c8197eb added rcov and unit tests
jimweirich authored
15 end
2365bd2 @drbrain Remove trailing whitespace from rake
drbrain authored
16
43f2ec6 @jimweirich Cleanup up tests. Added prereq and timestamp tests.
authored
17 def teardown
18 Rake::TaskManager.record_task_metadata = false
cbce3c7 @drbrain Make test file requires directory independent
drbrain authored
19
43f2ec6 @jimweirich Cleanup up tests. Added prereq and timestamp tests.
authored
20 super
21 end
c8197eb added rcov and unit tests
jimweirich authored
22
23 def test_constant_warning
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
24 _, err = capture_io do @app.instance_eval { const_warning("Task") } end
25 assert_match(/warning/i, err)
26 assert_match(/deprecated/i, err)
27 assert_match(/Task/i, err)
c8197eb added rcov and unit tests
jimweirich authored
28 end
29
30 def test_display_tasks
6f8b9a0 @jimweirich Show tasks using :tasks
authored
31 @app.options.show_tasks = :tasks
c8197eb added rcov and unit tests
jimweirich authored
32 @app.options.show_task_pattern = //
d1f89d7 added task parameters, named parameter via desc, column limited output
jimweirich authored
33 @app.last_description = "COMMENT"
c8197eb added rcov and unit tests
jimweirich authored
34 @app.define_task(Rake::Task, "t")
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
35 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
c8197eb added rcov and unit tests
jimweirich authored
36 assert_match(/^rake t/, out)
37 assert_match(/# COMMENT/, out)
38 end
39
e462afc Changes to get 100% code coverage in main rake.rb file.
jimweirich authored
40 def test_display_tasks_with_long_comments
4b4bce1 @jimweirich added in_environment for easier environment modification testing.
authored
41 in_environment('RAKE_COLUMNS' => '80') do
6f8b9a0 @jimweirich Show tasks using :tasks
authored
42 @app.options.show_tasks = :tasks
4b4bce1 @jimweirich added in_environment for easier environment modification testing.
authored
43 @app.options.show_task_pattern = //
44 @app.last_description = "1234567890" * 8
45 @app.define_task(Rake::Task, "t")
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
46 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
4b4bce1 @jimweirich added in_environment for easier environment modification testing.
authored
47 assert_match(/^rake t/, out)
48 assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
49 end
e462afc Changes to get 100% code coverage in main rake.rb file.
jimweirich authored
50 end
51
fba0457 Adding support to output full descriptions when not outputting to a T…
Gavin Stark authored
52 def test_display_tasks_with_task_name_wider_than_tty_display
4b4bce1 @jimweirich added in_environment for easier environment modification testing.
authored
53 in_environment('RAKE_COLUMNS' => '80') do
6f8b9a0 @jimweirich Show tasks using :tasks
authored
54 @app.options.show_tasks = :tasks
4b4bce1 @jimweirich added in_environment for easier environment modification testing.
authored
55 @app.options.show_task_pattern = //
56 task_name = "task name" * 80
57 @app.last_description = "something short"
58 @app.define_task(Rake::Task, task_name )
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
59 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
4b4bce1 @jimweirich added in_environment for easier environment modification testing.
authored
60 # Ensure the entire task name is output and we end up showing no description
61 assert_match(/rake #{task_name} # .../, out)
62 end
fba0457 Adding support to output full descriptions when not outputting to a T…
Gavin Stark authored
63 end
64
65 def test_display_tasks_with_very_long_task_name_to_a_non_tty_shows_name_and_comment
6f8b9a0 @jimweirich Show tasks using :tasks
authored
66 @app.options.show_tasks = :tasks
fba0457 Adding support to output full descriptions when not outputting to a T…
Gavin Stark authored
67 @app.options.show_task_pattern = //
68 @app.tty_output = false
69 description = "something short"
70 task_name = "task name" * 80
71 @app.last_description = "something short"
72 @app.define_task(Rake::Task, task_name )
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
73 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
fba0457 Adding support to output full descriptions when not outputting to a T…
Gavin Stark authored
74 # Ensure the entire task name is output and we end up showing no description
75 assert_match(/rake #{task_name} # #{description}/, out)
76 end
77
78 def test_display_tasks_with_long_comments_to_a_non_tty_shows_entire_comment
6f8b9a0 @jimweirich Show tasks using :tasks
authored
79 @app.options.show_tasks = :tasks
fba0457 Adding support to output full descriptions when not outputting to a T…
Gavin Stark authored
80 @app.options.show_task_pattern = //
81 @app.tty_output = false
82 @app.last_description = "1234567890" * 8
83 @app.define_task(Rake::Task, "t")
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
84 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
fba0457 Adding support to output full descriptions when not outputting to a T…
Gavin Stark authored
85 assert_match(/^rake t/, out)
86 assert_match(/# #{@app.last_description}/, out)
f8a729b Updating based on feedback from Jim regarding Emacs command window no…
Gavin Stark authored
87 end
88
89 def test_display_tasks_with_long_comments_to_a_non_tty_with_columns_set_truncates_comments
4b4bce1 @jimweirich added in_environment for easier environment modification testing.
authored
90 in_environment("RAKE_COLUMNS" => '80') do
6f8b9a0 @jimweirich Show tasks using :tasks
authored
91 @app.options.show_tasks = :tasks
4b4bce1 @jimweirich added in_environment for easier environment modification testing.
authored
92 @app.options.show_task_pattern = //
93 @app.tty_output = false
94 @app.last_description = "1234567890" * 8
95 @app.define_task(Rake::Task, "t")
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
96 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
4b4bce1 @jimweirich added in_environment for easier environment modification testing.
authored
97 assert_match(/^rake t/, out)
98 assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
99 end
fba0457 Adding support to output full descriptions when not outputting to a T…
Gavin Stark authored
100 end
101
e98aa21 @jimweirich Changing show tasks.
authored
102 def test_describe_tasks
d8090fd @jimweirich Fixed tests for show_tasks changes.
authored
103 @app.options.show_tasks = :describe
e462afc Changes to get 100% code coverage in main rake.rb file.
jimweirich authored
104 @app.options.show_task_pattern = //
105 @app.last_description = "COMMENT"
106 @app.define_task(Rake::Task, "t")
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
107 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
e462afc Changes to get 100% code coverage in main rake.rb file.
jimweirich authored
108 assert_match(/^rake t$/, out)
109 assert_match(/^ {4}COMMENT$/, out)
110 end
111
a483460 @jimweirich Added line number stuff (in progress)
authored
112 def test_show_lines
113 @app.options.show_tasks = :lines
114 @app.options.show_task_pattern = //
115 @app.last_description = "COMMENT"
116 @app.define_task(Rake::Task, "t")
89bc2c1 @jimweirich Added line number recording to task definition.
authored
117 @app['t'].locations << "HERE:1"
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
118 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
89bc2c1 @jimweirich Added line number recording to task definition.
authored
119 assert_match(/^rake t +[^:]+:\d+ *$/, out)
a483460 @jimweirich Added line number stuff (in progress)
authored
120 end
121
c8197eb added rcov and unit tests
jimweirich authored
122 def test_finding_rakefile
23275bc @luislavena Really make matching of Rakefile case insensitive.
luislavena authored
123 assert_match(/Rakefile/i, @app.instance_eval { have_rakefile })
c8197eb added rcov and unit tests
jimweirich authored
124 end
125
126 def test_not_finding_rakefile
127 @app.instance_eval { @rakefiles = ['NEVER_FOUND'] }
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
128 assert( ! @app.instance_eval do have_rakefile end )
c8197eb added rcov and unit tests
jimweirich authored
129 assert_nil @app.rakefile
130 end
131
132 def test_load_rakefile
4b4bce1 @jimweirich added in_environment for easier environment modification testing.
authored
133 in_environment("PWD" => "test/data/unittest") do
2365bd2 @drbrain Remove trailing whitespace from rake
drbrain authored
134 @app.instance_eval do
4b4bce1 @jimweirich added in_environment for easier environment modification testing.
authored
135 handle_options
136 options.silent = true
137 load_rakefile
138 end
139 assert_equal "rakefile", @app.rakefile.downcase
140 assert_match(%r(unittest$), Dir.pwd)
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
141 end
c8197eb added rcov and unit tests
jimweirich authored
142 end
143
6632653 @alexch don't print the rakefile directory message if it's in the same direct…
alexch authored
144 def test_load_rakefile_doesnt_print_rakefile_directory_from_same_dir
145 in_environment("PWD" => "test/data/unittest") do
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
146 _, err = capture_io do
6632653 @alexch don't print the rakefile directory message if it's in the same direct…
alexch authored
147 @app.instance_eval do
148 @original_dir = File.expand_path(".") # pretend we started from the unittest dir
149 raw_load_rakefile
150 end
151 end
1483c25 @drbrain Hide maybe-ness of printing the rakefile directory, merge with stdout…
drbrain authored
152 _, location = @app.find_rakefile_location
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
153 refute_match(/\(in #{location}\)/, err)
6632653 @alexch don't print the rakefile directory message if it's in the same direct…
alexch authored
154 end
155 end
156
c8197eb added rcov and unit tests
jimweirich authored
157 def test_load_rakefile_from_subdir
4b4bce1 @jimweirich added in_environment for easier environment modification testing.
authored
158 in_environment("PWD" => "test/data/unittest/subdir") do
159 @app.instance_eval do
160 handle_options
161 options.silent = true
162 load_rakefile
163 end
164 assert_equal "rakefile", @app.rakefile.downcase
165 assert_match(%r(unittest$), Dir.pwd)
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
166 end
c8197eb added rcov and unit tests
jimweirich authored
167 end
168
6632653 @alexch don't print the rakefile directory message if it's in the same direct…
alexch authored
169 def test_load_rakefile_prints_rakefile_directory_from_subdir
170 in_environment("PWD" => "test/data/unittest/subdir") do
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
171 _, err = capture_io do
6632653 @alexch don't print the rakefile directory message if it's in the same direct…
alexch authored
172 @app.instance_eval do
173 raw_load_rakefile
174 end
175 end
1483c25 @drbrain Hide maybe-ness of printing the rakefile directory, merge with stdout…
drbrain authored
176 _, location = @app.find_rakefile_location
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
177 assert_match(/\(in #{location}\)/, err)
6632653 @alexch don't print the rakefile directory message if it's in the same direct…
alexch authored
178 end
179 end
180
181 def test_load_rakefile_doesnt_print_rakefile_directory_from_subdir_if_silent
182 in_environment("PWD" => "test/data/unittest/subdir") do
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
183 _, err = capture_io do
6632653 @alexch don't print the rakefile directory message if it's in the same direct…
alexch authored
184 @app.instance_eval do
185 handle_options
186 options.silent = true
187 raw_load_rakefile
188 end
189 end
1483c25 @drbrain Hide maybe-ness of printing the rakefile directory, merge with stdout…
drbrain authored
190 _, location = @app.find_rakefile_location
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
191 refute_match(/\(in #{location}\)/, err)
6632653 @alexch don't print the rakefile directory message if it's in the same direct…
alexch authored
192 end
193 end
194
c8197eb added rcov and unit tests
jimweirich authored
195 def test_load_rakefile_not_found
f29ae0a @jimweirich fixed finding global rakefiles when no project available. Fixed nose…
authored
196 in_environment("PWD" => "/", "RAKE_SYSTEM" => 'not_exist') do
4b4bce1 @jimweirich added in_environment for easier environment modification testing.
authored
197 @app.instance_eval do
198 handle_options
199 options.silent = true
200 end
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
201 ex = assert_raises(RuntimeError) do
2365bd2 @drbrain Remove trailing whitespace from rake
drbrain authored
202 @app.instance_eval do raw_load_rakefile end
4b4bce1 @jimweirich added in_environment for easier environment modification testing.
authored
203 end
204 assert_match(/no rakefile found/i, ex.message)
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
205 end
c8197eb added rcov and unit tests
jimweirich authored
206 end
207
2da66fd @jimweirich partial implementation of system rakefiles
authored
208 def test_load_from_system_rakefile
209 in_environment('RAKE_SYSTEM' => 'test/data/sys') do
210 @app.options.rakelib = []
211 @app.instance_eval do
212 handle_options
213 options.silent = true
214 options.load_system = true
6cca7de @jimweirich removed rakelib from system load tests to avoid reloading constants
authored
215 options.rakelib = []
2da66fd @jimweirich partial implementation of system rakefiles
authored
216 load_rakefile
217 end
218 assert_equal "test/data/sys", @app.system_dir
219 assert_nil @app.rakefile
220 end
221 end
222
02e7bbb @jimweirich test coverage for system dir
authored
223 def test_load_from_calculated_system_rakefile
224 flexmock(@app, :standard_system_dir => "__STD_SYS_DIR__")
225 in_environment('RAKE_SYSTEM' => nil) do
226 @app.options.rakelib = []
227 @app.instance_eval do
228 handle_options
229 options.silent = true
230 options.load_system = true
231 options.rakelib = []
232 load_rakefile
233 end
234 assert_equal "__STD_SYS_DIR__", @app.system_dir
235 end
236 end
237
fcf0bb1 @jimweirich some refactoring and code cleanup. Better coverage
authored
238 def test_windows
239 assert ! (@app.windows? && @app.unix?)
240 end
241
c8197eb added rcov and unit tests
jimweirich authored
242 def test_loading_imports
243 mock = flexmock("loader")
244 mock.should_receive(:load).with("x.dummy").once
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
245 @app.instance_eval do
246 add_loader("dummy", mock)
247 add_import("x.dummy")
248 load_imports
249 end
c8197eb added rcov and unit tests
jimweirich authored
250 end
251
252 def test_building_imported_files_on_demand
253 mock = flexmock("loader")
254 mock.should_receive(:load).with("x.dummy").once
255 mock.should_receive(:make_dummy).with_no_args.once
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
256 @app.instance_eval do
257 intern(Rake::Task, "x.dummy").enhance do mock.make_dummy end
258 add_loader("dummy", mock)
259 add_import("x.dummy")
260 load_imports
261 end
c8197eb added rcov and unit tests
jimweirich authored
262 end
263
f6d5d5e @jimweirich Removed Application level test for win32 specifics (already covered in
authored
264 def test_handle_options_should_strip_options_from_ARGV
bdb31e3 am - Options parsing now appropriately removed rake options from the …
pivotal authored
265 assert !@app.options.trace
266
267 valid_option = '--trace'
268 ARGV.clear
269 ARGV << valid_option
270
271 @app.handle_options
272
273 assert !ARGV.include?(valid_option)
274 assert @app.options.trace
275 end
276
c8197eb added rcov and unit tests
jimweirich authored
277 def test_good_run
278 ran = false
991f432 Ruby 1.9 commit
jimweirich authored
279 ARGV.clear
280 ARGV << '--rakelib=""'
c8197eb added rcov and unit tests
jimweirich authored
281 @app.options.silent = true
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
282 @app.instance_eval do
283 intern(Rake::Task, "default").enhance { ran = true }
284 end
5af487a @jimweirich updated for ruby 19 compatibility
authored
285 in_environment("PWD" => "test/data/default") do
286 @app.run
287 end
c8197eb added rcov and unit tests
jimweirich authored
288 assert ran
289 end
290
291 def test_display_task_run
292 ran = false
293 ARGV.clear
991f432 Ruby 1.9 commit
jimweirich authored
294 ARGV << '-f' << '-s' << '--tasks' << '--rakelib=""'
d1f89d7 added task parameters, named parameter via desc, column limited output
jimweirich authored
295 @app.last_description = "COMMENT"
c8197eb added rcov and unit tests
jimweirich authored
296 @app.define_task(Rake::Task, "default")
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
297 out, = capture_io { @app.run }
c8197eb added rcov and unit tests
jimweirich authored
298 assert @app.options.show_tasks
299 assert ! ran
300 assert_match(/rake default/, out)
301 assert_match(/# COMMENT/, out)
302 end
303
304 def test_display_prereqs
305 ran = false
306 ARGV.clear
991f432 Ruby 1.9 commit
jimweirich authored
307 ARGV << '-f' << '-s' << '--prereqs' << '--rakelib=""'
d1f89d7 added task parameters, named parameter via desc, column limited output
jimweirich authored
308 @app.last_description = "COMMENT"
c8197eb added rcov and unit tests
jimweirich authored
309 t = @app.define_task(Rake::Task, "default")
310 t.enhance([:a, :b])
311 @app.define_task(Rake::Task, "a")
312 @app.define_task(Rake::Task, "b")
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
313 out, = capture_io { @app.run }
c8197eb added rcov and unit tests
jimweirich authored
314 assert @app.options.show_prereqs
315 assert ! ran
316 assert_match(/rake a$/, out)
317 assert_match(/rake b$/, out)
318 assert_match(/rake default\n( *(a|b)\n){2}/m, out)
319 end
320
321 def test_bad_run
20542ed removed lingering reference to the no_files test directory
jimweirich authored
322 @app.intern(Rake::Task, "default").enhance { fail }
323 ARGV.clear
324 ARGV << '-f' << '-s' << '--rakelib=""'
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
325 assert_raises(SystemExit) {
326 _, err = capture_io { @app.run }
327 assert_match(/see full trace/, err)
20542ed removed lingering reference to the no_files test directory
jimweirich authored
328 }
c8197eb added rcov and unit tests
jimweirich authored
329 ensure
330 ARGV.clear
331 end
332
333 def test_bad_run_with_trace
334 @app.intern(Rake::Task, "default").enhance { fail }
335 ARGV.clear
336 ARGV << '-f' << '-s' << '-t'
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
337 assert_raises(SystemExit) {
338 _, err = capture_io { @app.run }
339 refute_match(/see full trace/, err)
c8197eb added rcov and unit tests
jimweirich authored
340 }
341 ensure
342 ARGV.clear
343 end
344
345 def test_run_with_bad_options
346 @app.intern(Rake::Task, "default").enhance { fail }
347 ARGV.clear
348 ARGV << '-f' << '-s' << '--xyzzy'
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
349 assert_raises(SystemExit) {
350 capture_io { @app.run }
c8197eb added rcov and unit tests
jimweirich authored
351 }
352 ensure
353 ARGV.clear
354 end
efc4a7d @jimweirich Added test for deprecation method
authored
355
356 def test_deprecation_message
357 in_environment do
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
358 _, err = capture_io do
efc4a7d @jimweirich Added test for deprecation method
authored
359 @app.deprecate("a", "b", "c")
360 end
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
361 assert_match(/'a' is deprecated/i, err)
362 assert_match(/use 'b' instead/i, err)
363 assert_match(/at c$/i, err)
efc4a7d @jimweirich Added test for deprecation method
authored
364 end
365 end
c8197eb added rcov and unit tests
jimweirich authored
366 end
367
368
369 ######################################################################
0534fa5 @drbrain Tests now inherit from Rake::TestCase instead of Test::Unit::TestCase…
drbrain authored
370 class TestRakeApplicationOptions < Rake::TestCase
c8197eb added rcov and unit tests
jimweirich authored
371
372 def setup
cbce3c7 @drbrain Make test file requires directory independent
drbrain authored
373 super
374
c8197eb added rcov and unit tests
jimweirich authored
375 clear_argv
321178d @jimweirich Renamed RakeFileUtils to FileUtilsExt
authored
376 Rake::FileUtilsExt.verbose_flag = false
377 Rake::FileUtilsExt.nowrite_flag = false
4b4bce1 @jimweirich added in_environment for easier environment modification testing.
authored
378 TESTING_REQUIRE.clear
c8197eb added rcov and unit tests
jimweirich authored
379 end
380
381 def teardown
382 clear_argv
321178d @jimweirich Renamed RakeFileUtils to FileUtilsExt
authored
383 Rake::FileUtilsExt.verbose_flag = false
384 Rake::FileUtilsExt.nowrite_flag = false
cbce3c7 @drbrain Make test file requires directory independent
drbrain authored
385
386 super
c8197eb added rcov and unit tests
jimweirich authored
387 end
2365bd2 @drbrain Remove trailing whitespace from rake
drbrain authored
388
c8197eb added rcov and unit tests
jimweirich authored
389 def clear_argv
390 while ! ARGV.empty?
391 ARGV.pop
392 end
393 end
394
395 def test_default_options
73d55ff @jimweirich More tests for RAKEOPT.
authored
396 in_environment("RAKEOPT" => nil) do
397 opts = command_line
398 assert_nil opts.classic_namespace
399 assert_nil opts.dryrun
400 assert_nil opts.ignore_system
401 assert_nil opts.load_system
402 assert_nil opts.nosearch
403 assert_equal ['rakelib'], opts.rakelib
404 assert_nil opts.show_prereqs
405 assert_nil opts.show_task_pattern
406 assert_nil opts.show_tasks
407 assert_nil opts.silent
408 assert_nil opts.trace
409 assert_equal ['rakelib'], opts.rakelib
321178d @jimweirich Renamed RakeFileUtils to FileUtilsExt
authored
410 assert ! Rake::FileUtilsExt.verbose_flag
411 assert ! Rake::FileUtilsExt.nowrite_flag
73d55ff @jimweirich More tests for RAKEOPT.
authored
412 end
c8197eb added rcov and unit tests
jimweirich authored
413 end
414
8519372 @jimweirich improved coverage
authored
415 def test_dry_run
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
416 in_environment do
417 flags('--dry-run', '-n') do |opts|
418 assert opts.dryrun
419 assert opts.trace
321178d @jimweirich Renamed RakeFileUtils to FileUtilsExt
authored
420 assert Rake::FileUtilsExt.verbose_flag
421 assert Rake::FileUtilsExt.nowrite_flag
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
422 end
c8197eb added rcov and unit tests
jimweirich authored
423 end
424 end
425
8519372 @jimweirich improved coverage
authored
426 def test_describe
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
427 in_environment do
428 flags('--describe') do |opts|
429 assert_equal :describe, opts.show_tasks
430 assert_equal(//.to_s, opts.show_task_pattern.to_s)
431 end
41d9b92 @jimweirich added system wide option handling
authored
432 end
433 end
434
8519372 @jimweirich improved coverage
authored
435 def test_describe_with_pattern
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
436 in_environment do
437 flags('--describe=X') do |opts|
438 assert_equal :describe, opts.show_tasks
439 assert_equal(/X/.to_s, opts.show_task_pattern.to_s)
440 end
41d9b92 @jimweirich added system wide option handling
authored
441 end
442 end
443
8519372 @jimweirich improved coverage
authored
444 def test_execute
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
445 in_environment do
8519372 @jimweirich improved coverage
authored
446 $xyzzy = 0
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
447 flags('--execute=$xyzzy=1', '-e $xyzzy=1') do |opts|
448 assert_equal 1, $xyzzy
449 assert_equal :exit, @exit
450 $xyzzy = 0
451 end
8519372 @jimweirich improved coverage
authored
452 end
453 end
454
455 def test_execute_and_continue
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
456 in_environment do
8519372 @jimweirich improved coverage
authored
457 $xyzzy = 0
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
458 flags('--execute-continue=$xyzzy=1', '-E $xyzzy=1') do |opts|
459 assert_equal 1, $xyzzy
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
460 refute_equal :exit, @exit
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
461 $xyzzy = 0
462 end
8519372 @jimweirich improved coverage
authored
463 end
464 end
465
466 def test_execute_and_print
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
467 in_environment do
8519372 @jimweirich improved coverage
authored
468 $xyzzy = 0
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
469 out, = capture_io do
470 flags('--execute-print=$xyzzy="pugh"', '-p $xyzzy="pugh"') do |opts|
471 assert_equal 'pugh', $xyzzy
472 assert_equal :exit, @exit
473 $xyzzy = 0
474 end
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
475 end
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
476
477 assert_match(/^pugh$/, out)
c8197eb added rcov and unit tests
jimweirich authored
478 end
479 end
480
481 def test_help
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
482 in_environment do
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
483 out, = capture_io do
484 flags '--help', '-H', '-h'
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
485 end
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
486
487 assert_match(/\Arake/, out)
488 assert_match(/\boptions\b/, out)
489 assert_match(/\btargets\b/, out)
490 assert_equal :exit, @exit
c8197eb added rcov and unit tests
jimweirich authored
491 end
492 end
493
494 def test_libdir
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
495 in_environment do
496 flags(['--libdir', 'xx'], ['-I', 'xx'], ['-Ixx']) do |opts|
497 $:.include?('xx')
498 end
c8197eb added rcov and unit tests
jimweirich authored
499 end
500 ensure
501 $:.delete('xx')
502 end
503
8519372 @jimweirich improved coverage
authored
504 def test_rakefile
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
505 in_environment do
506 flags(['--rakefile', 'RF'], ['--rakefile=RF'], ['-f', 'RF'], ['-fRF']) do |opts|
507 assert_equal ['RF'], @app.instance_eval { @rakefiles }
508 end
8519372 @jimweirich improved coverage
authored
509 end
510 end
511
512 def test_rakelib
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
513 in_environment do
514 flags(['--rakelibdir', 'A:B:C'], ['--rakelibdir=A:B:C'], ['-R', 'A:B:C'], ['-RA:B:C']) do |opts|
515 assert_equal ['A', 'B', 'C'], opts.rakelib
516 end
c8197eb added rcov and unit tests
jimweirich authored
517 end
518 end
519
8519372 @jimweirich improved coverage
authored
520 def test_require
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
521 in_environment do
522 flags(['--require', 'test/reqfile'], '-rtest/reqfile2', '-rtest/reqfile3') do |opts|
523 end
524 assert TESTING_REQUIRE.include?(1)
525 assert TESTING_REQUIRE.include?(2)
526 assert TESTING_REQUIRE.include?(3)
527 assert_equal 3, TESTING_REQUIRE.size
8519372 @jimweirich improved coverage
authored
528 end
529 end
2365bd2 @drbrain Remove trailing whitespace from rake
drbrain authored
530
8519372 @jimweirich improved coverage
authored
531 def test_missing_require
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
532 in_environment do
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
533 ex = assert_raises(LoadError) do
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
534 flags(['--require', 'test/missing']) do |opts|
535 end
8519372 @jimweirich improved coverage
authored
536 end
147a1b7 @drbrain Tests can now run on 1.9
drbrain authored
537 assert_match(/such file/, ex.message)
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
538 assert_match(/test\/missing/, ex.message)
8519372 @jimweirich improved coverage
authored
539 end
540 end
541
542 def test_prereqs
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
543 in_environment do
544 flags('--prereqs', '-P') do |opts|
545 assert opts.show_prereqs
546 end
c8197eb added rcov and unit tests
jimweirich authored
547 end
548 end
549
550 def test_quiet
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
551 in_environment do
552 flags('--quiet', '-q') do |opts|
321178d @jimweirich Renamed RakeFileUtils to FileUtilsExt
authored
553 assert ! Rake::FileUtilsExt.verbose_flag
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
554 assert ! opts.silent
555 end
c8197eb added rcov and unit tests
jimweirich authored
556 end
557 end
558
8519372 @jimweirich improved coverage
authored
559 def test_no_search
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
560 in_environment do
561 flags('--nosearch', '--no-search', '-N') do |opts|
562 assert opts.nosearch
563 end
8519372 @jimweirich improved coverage
authored
564 end
565 end
566
c8197eb added rcov and unit tests
jimweirich authored
567 def test_silent
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
568 in_environment do
569 flags('--silent', '-s') do |opts|
321178d @jimweirich Renamed RakeFileUtils to FileUtilsExt
authored
570 assert ! Rake::FileUtilsExt.verbose_flag
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
571 assert opts.silent
572 end
c8197eb added rcov and unit tests
jimweirich authored
573 end
574 end
575
8519372 @jimweirich improved coverage
authored
576 def test_system
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
577 in_environment do
578 flags('--system', '-g') do |opts|
579 assert opts.load_system
580 end
c8197eb added rcov and unit tests
jimweirich authored
581 end
582 end
583
8519372 @jimweirich improved coverage
authored
584 def test_no_system
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
585 in_environment do
586 flags('--no-system', '-G') do |opts|
587 assert opts.ignore_system
588 end
c8197eb added rcov and unit tests
jimweirich authored
589 end
590 end
591
8519372 @jimweirich improved coverage
authored
592 def test_trace
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
593 in_environment do
594 flags('--trace', '-t') do |opts|
595 assert opts.trace
321178d @jimweirich Renamed RakeFileUtils to FileUtilsExt
authored
596 assert Rake::FileUtilsExt.verbose_flag
597 assert ! Rake::FileUtilsExt.nowrite_flag
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
598 end
c8197eb added rcov and unit tests
jimweirich authored
599 end
600 end
601
8519372 @jimweirich improved coverage
authored
602 def test_trace_rules
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
603 in_environment do
604 flags('--rules') do |opts|
605 assert opts.trace_rules
606 end
c8197eb added rcov and unit tests
jimweirich authored
607 end
608 end
609
610 def test_tasks
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
611 in_environment do
612 flags('--tasks', '-T') do |opts|
613 assert_equal :tasks, opts.show_tasks
614 assert_equal(//.to_s, opts.show_task_pattern.to_s)
615 end
616 flags(['--tasks', 'xyz'], ['-Txyz']) do |opts|
617 assert_equal :tasks, opts.show_tasks
02e7bbb @jimweirich test coverage for system dir
authored
618 assert_equal(/xyz/.to_s, opts.show_task_pattern.to_s)
619 end
620 end
621 end
622
623 def test_where
624 in_environment do
625 flags('--where', '-W') do |opts|
626 assert_equal :lines, opts.show_tasks
627 assert_equal(//.to_s, opts.show_task_pattern.to_s)
628 end
629 flags(['--where', 'xyz'], ['-Wxyz']) do |opts|
630 assert_equal :lines, opts.show_tasks
631 assert_equal(/xyz/.to_s, opts.show_task_pattern.to_s)
632 end
633 end
634 end
635
636 def test_no_deprecated_messages
637 in_environment do
638 flags('--no-deprecation-warnings', '-X') do |opts|
639 assert opts.ignore_deprecate
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
640 end
c8197eb added rcov and unit tests
jimweirich authored
641 end
642 end
643
644 def test_verbose
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
645 in_environment do
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
646 out, = capture_io do
647 flags('--verbose', '-V') do |opts|
648 assert Rake::FileUtilsExt.verbose_flag
649 assert ! opts.silent
650 end
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
651 end
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
652
653 assert_equal "rake, version 0.9.0\n", out
c8197eb added rcov and unit tests
jimweirich authored
654 end
655 end
656
657 def test_version
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
658 in_environment do
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
659 out, = capture_io do
660 flags '--version', '-V'
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
661 end
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
662
663 assert_match(/\bversion\b/, out)
664 assert_match(/\b#{RAKEVERSION}\b/, out)
665 assert_equal :exit, @exit
c8197eb added rcov and unit tests
jimweirich authored
666 end
667 end
2365bd2 @drbrain Remove trailing whitespace from rake
drbrain authored
668
c8197eb added rcov and unit tests
jimweirich authored
669 def test_classic_namespace
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
670 in_environment do
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
671 _, err = capture_io do
672 flags(['--classic-namespace'],
673 ['-C', '-T', '-P', '-n', '-s', '-t']) do |opts|
ae93ad2 @jimweirich Disable expected warning about inline source in rdoc task testing.
authored
674 assert opts.classic_namespace
675 assert_equal opts.show_tasks, $show_tasks
676 assert_equal opts.show_prereqs, $show_prereqs
677 assert_equal opts.trace, $trace
678 assert_equal opts.dryrun, $dryrun
679 assert_equal opts.silent, $silent
680 end
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
681 end
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
682
683 assert_match(/deprecated/, err)
c8197eb added rcov and unit tests
jimweirich authored
684 end
685 end
686
687 def test_bad_option
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
688 in_environment do
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
689 _, err = capture_io do
690 ex = assert_raises(OptionParser::InvalidOption) do
2365bd2 @drbrain Remove trailing whitespace from rake
drbrain authored
691 flags('--bad-option')
6fe3f8e @jimweirich Isolated most flag testing in an in_environment call to prevent the
authored
692 end
693 if ex.message =~ /^While/ # Ruby 1.9 error message
694 assert_match(/while parsing/i, ex.message)
695 else # Ruby 1.8 error message
696 assert_match(/(invalid|unrecognized) option/i, ex.message)
697 assert_match(/--bad-option/, ex.message)
698 end
991f432 Ruby 1.9 commit
jimweirich authored
699 end
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
700 assert_equal '', err
c8197eb added rcov and unit tests
jimweirich authored
701 end
702 end
703
704 def test_task_collection
705 command_line("a", "b")
706 assert_equal ["a", "b"], @tasks.sort
707 end
2365bd2 @drbrain Remove trailing whitespace from rake
drbrain authored
708
c8197eb added rcov and unit tests
jimweirich authored
709 def test_default_task_collection
710 command_line()
711 assert_equal ["default"], @tasks
712 end
2365bd2 @drbrain Remove trailing whitespace from rake
drbrain authored
713
c8197eb added rcov and unit tests
jimweirich authored
714 def test_environment_definition
991f432 Ruby 1.9 commit
jimweirich authored
715 ENV.delete('TESTKEY')
c8197eb added rcov and unit tests
jimweirich authored
716 command_line("a", "TESTKEY=12")
717 assert_equal ["a"], @tasks.sort
718 assert '12', ENV['TESTKEY']
719 end
8e05fcd updates for ruby 1.9
jimweirich authored
720
2365bd2 @drbrain Remove trailing whitespace from rake
drbrain authored
721 private
c8197eb added rcov and unit tests
jimweirich authored
722
723 def flags(*sets)
724 sets.each do |set|
8519372 @jimweirich improved coverage
authored
725 ARGV.clear
0dba7c9 @drbrain Switch rake's tests to minitest
drbrain authored
726
727 @exit = catch(:system_exit) { command_line(*set) }
728
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
729 yield(@app.options) if block_given?
c8197eb added rcov and unit tests
jimweirich authored
730 end
731 end
732
733 def command_line(*options)
734 options.each do |opt| ARGV << opt end
735 @app = Rake::Application.new
736 def @app.exit(*args)
737 throw :system_exit, :exit
738 end
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
739 @app.instance_eval do
bdb31e3 am - Options parsing now appropriately removed rake options from the …
pivotal authored
740 handle_options
741 collect_tasks
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
742 end
743 @tasks = @app.top_level_tasks
c8197eb added rcov and unit tests
jimweirich authored
744 @app.options
745 end
746 end
747
0534fa5 @drbrain Tests now inherit from Rake::TestCase instead of Test::Unit::TestCase…
drbrain authored
748 class TestRakeTaskArgumentParsing < Rake::TestCase
9ca2c3d Added task arguments
jimweirich authored
749 def setup
cbce3c7 @drbrain Make test file requires directory independent
drbrain authored
750 super
751
9ca2c3d Added task arguments
jimweirich authored
752 @app = Rake::Application.new
753 end
2365bd2 @drbrain Remove trailing whitespace from rake
drbrain authored
754
9ca2c3d Added task arguments
jimweirich authored
755 def test_name_only
756 name, args = @app.parse_task_string("name")
757 assert_equal "name", name
758 assert_equal [], args
759 end
2365bd2 @drbrain Remove trailing whitespace from rake
drbrain authored
760
9ca2c3d Added task arguments
jimweirich authored
761 def test_empty_args
762 name, args = @app.parse_task_string("name[]")
763 assert_equal "name", name
764 assert_equal [], args
765 end
2365bd2 @drbrain Remove trailing whitespace from rake
drbrain authored
766
9ca2c3d Added task arguments
jimweirich authored
767 def test_one_argument
768 name, args = @app.parse_task_string("name[one]")
769 assert_equal "name", name
770 assert_equal ["one"], args
771 end
2365bd2 @drbrain Remove trailing whitespace from rake
drbrain authored
772
9ca2c3d Added task arguments
jimweirich authored
773 def test_two_arguments
774 name, args = @app.parse_task_string("name[one,two]")
775 assert_equal "name", name
776 assert_equal ["one", "two"], args
777 end
2365bd2 @drbrain Remove trailing whitespace from rake
drbrain authored
778
9ca2c3d Added task arguments
jimweirich authored
779 def test_can_handle_spaces_between_args
780 name, args = @app.parse_task_string("name[one, two,\tthree , \tfour]")
781 assert_equal "name", name
782 assert_equal ["one", "two", "three", "four"], args
783 end
784
785 def test_keeps_embedded_spaces
786 name, args = @app.parse_task_string("name[a one ana, two]")
787 assert_equal "name", name
788 assert_equal ["a one ana", "two"], args
789 end
790
0b08813 added rubygems whereever flexmock is used
jimweirich authored
791 end
fcf0bb1 @jimweirich some refactoring and code cleanup. Better coverage
authored
792
0534fa5 @drbrain Tests now inherit from Rake::TestCase instead of Test::Unit::TestCase…
drbrain authored
793 class TestRakeTaskArgumentParsing < Rake::TestCase
fcf0bb1 @jimweirich some refactoring and code cleanup. Better coverage
authored
794
795 def test_terminal_width_using_env
796 app = Rake::Application.new
797 in_environment('RAKE_COLUMNS' => '1234') do
798 assert_equal 1234, app.terminal_width
799 end
800 end
801
802 def test_terminal_width_using_stty
803 app = Rake::Application.new
804 flexmock(app,
805 :unix? => true,
806 :dynamic_width_stty => 1235,
807 :dynamic_width_tput => 0)
808 in_environment('RAKE_COLUMNS' => nil) do
809 assert_equal 1235, app.terminal_width
810 end
811 end
812
813 def test_terminal_width_using_tput
814 app = Rake::Application.new
815 flexmock(app,
816 :unix? => true,
817 :dynamic_width_stty => 0,
818 :dynamic_width_tput => 1236)
819 in_environment('RAKE_COLUMNS' => nil) do
820 assert_equal 1236, app.terminal_width
821 end
822 end
823
824 def test_terminal_width_using_hardcoded_80
825 app = Rake::Application.new
826 flexmock(app, :unix? => false)
827 in_environment('RAKE_COLUMNS' => nil) do
828 assert_equal 80, app.terminal_width
829 end
830 end
831
832 def test_terminal_width_with_failure
833 app = Rake::Application.new
834 flexmock(app).should_receive(:unix?).and_throw(RuntimeError)
835 in_environment('RAKE_COLUMNS' => nil) do
836 assert_equal 80, app.terminal_width
837 end
838 end
d000a3d @jimweirich Added RAKEOPT environment variable support.
authored
839
73d55ff @jimweirich More tests for RAKEOPT.
authored
840 def test_no_rakeopt
841 in_environment do
842 ARGV << '--trace'
843 app = Rake::Application.new
844 app.init
845 assert !app.options.silent
846 end
847 end
848
d000a3d @jimweirich Added RAKEOPT environment variable support.
authored
849 def test_rakeopt_with_blank_options
850 in_environment("RAKEOPT" => "") do
851 ARGV << '--trace'
852 app = Rake::Application.new
853 app.init
854 assert !app.options.silent
855 end
856 end
857
858 def test_rakeopt_with_silent_options
859 in_environment("RAKEOPT" => "-s") do
860 app = Rake::Application.new
861 app.init
862 assert app.options.silent
863 end
864 end
fcf0bb1 @jimweirich some refactoring and code cleanup. Better coverage
authored
865 end
Something went wrong with that request. Please try again.