Skip to content
This repository
Newer
Older
100644 576 lines (465 sloc) 13.734 kb
cbce3c7b »
2011-05-21 Make test file requires directory independent
1 require File.expand_path('../helper', __FILE__)
c8197eb5 »
2006-06-01 added rcov and unit tests
2
0534fa59 »
2011-05-20 Tests now inherit from Rake::TestCase instead of Test::Unit::TestCase…
3 class TestRakeApplication < Rake::TestCase
c8197eb5 »
2006-06-01 added rcov and unit tests
4
5 def setup
43f2ec67 »
2009-12-23 Cleanup up tests. Added prereq and timestamp tests.
6 super
cbce3c7b »
2011-05-21 Make test file requires directory independent
7
8f02e238 »
2011-06-23 Rake tests now create all files in a temporary directory
8 @app = Rake.application
991f4322 »
2007-11-16 Ruby 1.9 commit
9 @app.options.rakelib = []
43f2ec67 »
2009-12-23 Cleanup up tests. Added prereq and timestamp tests.
10 end
c8197eb5 »
2006-06-01 added rcov and unit tests
11
336559f2 »
2014-02-13 Refactor ARGV setup into setup_command_line method.
12 def setup_command_line(*options)
13 ARGV.clear
14 options.each do |option|
15 ARGV << option
16 end
17 end
18
c8197eb5 »
2006-06-01 added rcov and unit tests
19 def test_display_tasks
6f8b9a0f »
2009-05-18 Show tasks using :tasks
20 @app.options.show_tasks = :tasks
c8197eb5 »
2006-06-01 added rcov and unit tests
21 @app.options.show_task_pattern = //
d1f89d7c »
2007-05-26 added task parameters, named parameter via desc, column limited output
22 @app.last_description = "COMMENT"
c8197eb5 »
2006-06-01 added rcov and unit tests
23 @app.define_task(Rake::Task, "t")
0dba7c92 »
2011-05-20 Switch rake's tests to minitest
24 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
c8197eb5 »
2006-06-01 added rcov and unit tests
25 assert_match(/^rake t/, out)
26 assert_match(/# COMMENT/, out)
27 end
28
e462afc4 »
2007-07-22 Changes to get 100% code coverage in main rake.rb file.
29 def test_display_tasks_with_long_comments
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
30 @app.terminal_columns = 80
31 @app.options.show_tasks = :tasks
32 @app.options.show_task_pattern = //
9d09be75 »
2013-04-12 Applied style guide to tests.
33 numbers = "1234567890" * 8
34 @app.last_description = numbers
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
35 @app.define_task(Rake::Task, "t")
36
37 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
38
39 assert_match(/^rake t/, out)
9d09be75 »
2013-04-12 Applied style guide to tests.
40 assert_match(/# #{numbers[0, 65]}\.\.\./, out)
e462afc4 »
2007-07-22 Changes to get 100% code coverage in main rake.rb file.
41 end
42
fba0457b »
2008-08-09 Adding support to output full descriptions when not outputting to a T…
43 def test_display_tasks_with_task_name_wider_than_tty_display
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
44 @app.terminal_columns = 80
45 @app.options.show_tasks = :tasks
46 @app.options.show_task_pattern = //
47 task_name = "task name" * 80
48 @app.last_description = "something short"
9d09be75 »
2013-04-12 Applied style guide to tests.
49 @app.define_task(Rake::Task, task_name)
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
50
51 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
52
53 # Ensure the entire task name is output and we end up showing no description
54 assert_match(/rake #{task_name} # .../, out)
fba0457b »
2008-08-09 Adding support to output full descriptions when not outputting to a T…
55 end
56
57 def test_display_tasks_with_very_long_task_name_to_a_non_tty_shows_name_and_comment
6f8b9a0f »
2009-05-18 Show tasks using :tasks
58 @app.options.show_tasks = :tasks
fba0457b »
2008-08-09 Adding support to output full descriptions when not outputting to a T…
59 @app.options.show_task_pattern = //
60 @app.tty_output = false
61 description = "something short"
62 task_name = "task name" * 80
63 @app.last_description = "something short"
9d09be75 »
2013-04-12 Applied style guide to tests.
64 @app.define_task(Rake::Task, task_name)
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
65
0dba7c92 »
2011-05-20 Switch rake's tests to minitest
66 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
67
fba0457b »
2008-08-09 Adding support to output full descriptions when not outputting to a T…
68 # Ensure the entire task name is output and we end up showing no description
69 assert_match(/rake #{task_name} # #{description}/, out)
70 end
71
72 def test_display_tasks_with_long_comments_to_a_non_tty_shows_entire_comment
6f8b9a0f »
2009-05-18 Show tasks using :tasks
73 @app.options.show_tasks = :tasks
fba0457b »
2008-08-09 Adding support to output full descriptions when not outputting to a T…
74 @app.options.show_task_pattern = //
75 @app.tty_output = false
76 @app.last_description = "1234567890" * 8
77 @app.define_task(Rake::Task, "t")
0dba7c92 »
2011-05-20 Switch rake's tests to minitest
78 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
fba0457b »
2008-08-09 Adding support to output full descriptions when not outputting to a T…
79 assert_match(/^rake t/, out)
80 assert_match(/# #{@app.last_description}/, out)
f8a729ba »
2008-08-11 Updating based on feedback from Jim regarding Emacs command window no…
81 end
82
9d09be75 »
2013-04-12 Applied style guide to tests.
83 def test_truncating_comments_to_a_non_tty
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
84 @app.terminal_columns = 80
85 @app.options.show_tasks = :tasks
86 @app.options.show_task_pattern = //
87 @app.tty_output = false
9d09be75 »
2013-04-12 Applied style guide to tests.
88 numbers = "1234567890" * 8
89 @app.last_description = numbers
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
90 @app.define_task(Rake::Task, "t")
91
92 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
93
94 assert_match(/^rake t/, out)
9d09be75 »
2013-04-12 Applied style guide to tests.
95 assert_match(/# #{numbers[0, 65]}\.\.\./, out)
fba0457b »
2008-08-09 Adding support to output full descriptions when not outputting to a T…
96 end
97
e98aa212 »
2009-05-18 Changing show tasks.
98 def test_describe_tasks
d8090fd1 »
2009-05-18 Fixed tests for show_tasks changes.
99 @app.options.show_tasks = :describe
e462afc4 »
2007-07-22 Changes to get 100% code coverage in main rake.rb file.
100 @app.options.show_task_pattern = //
101 @app.last_description = "COMMENT"
102 @app.define_task(Rake::Task, "t")
0dba7c92 »
2011-05-20 Switch rake's tests to minitest
103 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
e462afc4 »
2007-07-22 Changes to get 100% code coverage in main rake.rb file.
104 assert_match(/^rake t$/, out)
105 assert_match(/^ {4}COMMENT$/, out)
106 end
107
a483460a »
2009-05-18 Added line number stuff (in progress)
108 def test_show_lines
109 @app.options.show_tasks = :lines
110 @app.options.show_task_pattern = //
111 @app.last_description = "COMMENT"
112 @app.define_task(Rake::Task, "t")
89bc2c1e »
2009-05-18 Added line number recording to task definition.
113 @app['t'].locations << "HERE:1"
0dba7c92 »
2011-05-20 Switch rake's tests to minitest
114 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
89bc2c1e »
2009-05-18 Added line number recording to task definition.
115 assert_match(/^rake t +[^:]+:\d+ *$/, out)
a483460a »
2009-05-18 Added line number stuff (in progress)
116 end
117
c8197eb5 »
2006-06-01 added rcov and unit tests
118 def test_finding_rakefile
2f25507a »
2011-06-22 Make fileutils tests be non-directory-dependent
119 rakefile_default
120
23275bc7 »
2008-10-23 Really make matching of Rakefile case insensitive.
121 assert_match(/Rakefile/i, @app.instance_eval { have_rakefile })
c8197eb5 »
2006-06-01 added rcov and unit tests
122 end
123
124 def test_not_finding_rakefile
125 @app.instance_eval { @rakefiles = ['NEVER_FOUND'] }
9d09be75 »
2013-04-12 Applied style guide to tests.
126 assert(! @app.instance_eval do have_rakefile end)
c8197eb5 »
2006-06-01 added rcov and unit tests
127 assert_nil @app.rakefile
128 end
129
130 def test_load_rakefile
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
131 rakefile_unittest
132
133 @app.instance_eval do
134 handle_options
135 options.silent = true
136 load_rakefile
9bb3cb27 »
2007-04-21 Changes for Rake 0.7 3
137 end
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
138
139 assert_equal "rakefile", @app.rakefile.downcase
140 assert_equal @tempdir, Dir.pwd
c8197eb5 »
2006-06-01 added rcov and unit tests
141 end
142
66326539 »
2010-11-12 don't print the rakefile directory message if it's in the same direct…
143 def test_load_rakefile_doesnt_print_rakefile_directory_from_same_dir
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
144 rakefile_unittest
145
146 _, err = capture_io do
147 @app.instance_eval do
148 # pretend we started from the unittest dir
149 @original_dir = File.expand_path(".")
150 raw_load_rakefile
66326539 »
2010-11-12 don't print the rakefile directory message if it's in the same direct…
151 end
152 end
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
153
164bd2f3 »
2011-06-22 Fix failures on 1.8 and warnings on 1.9.3
154 assert_empty err
66326539 »
2010-11-12 don't print the rakefile directory message if it's in the same direct…
155 end
156
c8197eb5 »
2006-06-01 added rcov and unit tests
157 def test_load_rakefile_from_subdir
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
158 rakefile_unittest
159 Dir.chdir 'subdir'
160
161 @app.instance_eval do
162 handle_options
163 options.silent = true
164 load_rakefile
9bb3cb27 »
2007-04-21 Changes for Rake 0.7 3
165 end
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
166
167 assert_equal "rakefile", @app.rakefile.downcase
168 assert_equal @tempdir, Dir.pwd
c8197eb5 »
2006-06-01 added rcov and unit tests
169 end
170
66326539 »
2010-11-12 don't print the rakefile directory message if it's in the same direct…
171 def test_load_rakefile_prints_rakefile_directory_from_subdir
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
172 rakefile_unittest
173 Dir.chdir 'subdir'
174
8f02e238 »
2011-06-23 Rake tests now create all files in a temporary directory
175 app = Rake::Application.new
176 app.options.rakelib = []
177
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
178 _, err = capture_io do
8f02e238 »
2011-06-23 Rake tests now create all files in a temporary directory
179 app.instance_eval do
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
180 raw_load_rakefile
66326539 »
2010-11-12 don't print the rakefile directory message if it's in the same direct…
181 end
182 end
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
183
184 assert_equal "(in #{@tempdir}\)\n", err
66326539 »
2010-11-12 don't print the rakefile directory message if it's in the same direct…
185 end
186
187 def test_load_rakefile_doesnt_print_rakefile_directory_from_subdir_if_silent
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
188 rakefile_unittest
189 Dir.chdir 'subdir'
66326539 »
2010-11-12 don't print the rakefile directory message if it's in the same direct…
190
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
191 _, err = capture_io do
4b4bce10 »
2008-08-30 added in_environment for easier environment modification testing.
192 @app.instance_eval do
193 handle_options
194 options.silent = true
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
195 raw_load_rakefile
4b4bce10 »
2008-08-30 added in_environment for easier environment modification testing.
196 end
9bb3cb27 »
2007-04-21 Changes for Rake 0.7 3
197 end
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
198
164bd2f3 »
2011-06-22 Fix failures on 1.8 and warnings on 1.9.3
199 assert_empty err
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
200 end
201
202 def test_load_rakefile_not_found
336559f2 »
2014-02-13 Refactor ARGV setup into setup_command_line method.
203 ARGV.clear
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
204 Dir.chdir @tempdir
205 ENV['RAKE_SYSTEM'] = 'not_exist'
206
207 @app.instance_eval do
208 handle_options
209 options.silent = true
210 end
211
336559f2 »
2014-02-13 Refactor ARGV setup into setup_command_line method.
212
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
213 ex = assert_raises(RuntimeError) do
336559f2 »
2014-02-13 Refactor ARGV setup into setup_command_line method.
214 @app.instance_eval do
215 raw_load_rakefile
216 end
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
217 end
218
219 assert_match(/no rakefile found/i, ex.message)
c8197eb5 »
2006-06-01 added rcov and unit tests
220 end
221
2da66fd9 »
2008-08-30 partial implementation of system rakefiles
222 def test_load_from_system_rakefile
a119d1b8 »
2011-06-22 Remove in_environment from test/test_rake_task_argument_parsing.rb
223 rake_system_dir
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
224
225 @app.instance_eval do
226 handle_options
227 options.silent = true
228 options.load_system = true
229 options.rakelib = []
230 load_rakefile
2da66fd9 »
2008-08-30 partial implementation of system rakefiles
231 end
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
232
233 assert_equal @system_dir, @app.system_dir
234 assert_nil @app.rakefile
8f02e238 »
2011-06-23 Rake tests now create all files in a temporary directory
235 rescue SystemExit
236 flunk 'failed to load rakefile'
2da66fd9 »
2008-08-30 partial implementation of system rakefiles
237 end
238
02e7bbbe »
2011-03-13 test coverage for system dir
239 def test_load_from_calculated_system_rakefile
2f25507a »
2011-06-22 Make fileutils tests be non-directory-dependent
240 rakefile_default
928e0a23 »
2011-07-22 Remove requirement of flexmock per Ruby bug #4987
241 def @app.standard_system_dir
242 "__STD_SYS_DIR__"
243 end
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
244
245 ENV['RAKE_SYSTEM'] = nil
246
247 @app.instance_eval do
248 handle_options
249 options.silent = true
250 options.load_system = true
251 options.rakelib = []
252 load_rakefile
253 end
254
255 assert_equal "__STD_SYS_DIR__", @app.system_dir
2f25507a »
2011-06-22 Make fileutils tests be non-directory-dependent
256 rescue SystemExit
257 flunk 'failed to find system rakefile'
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
258 end
259
260 def test_terminal_columns
9d09be75 »
2013-04-12 Applied style guide to tests.
261 old_rake_columns = ENV['RAKE_COLUMNS']
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
262
263 ENV['RAKE_COLUMNS'] = '42'
264
265 app = Rake::Application.new
266
267 assert_equal 42, app.terminal_columns
268 ensure
9d09be75 »
2013-04-12 Applied style guide to tests.
269 if old_rake_columns
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
270 ENV['RAKE_COLUMNS'].delete
271 else
9d09be75 »
2013-04-12 Applied style guide to tests.
272 ENV['RAKE_COLUMNS'] = old_rake_columns
02e7bbbe »
2011-03-13 test coverage for system dir
273 end
274 end
275
fcf0bb1b »
2008-09-01 some refactoring and code cleanup. Better coverage
276 def test_windows
277 assert ! (@app.windows? && @app.unix?)
278 end
279
c8197eb5 »
2006-06-01 added rcov and unit tests
280 def test_loading_imports
928e0a23 »
2011-07-22 Remove requirement of flexmock per Ruby bug #4987
281 loader = util_loader
282
9bb3cb27 »
2007-04-21 Changes for Rake 0.7 3
283 @app.instance_eval do
928e0a23 »
2011-07-22 Remove requirement of flexmock per Ruby bug #4987
284 add_loader("dummy", loader)
9bb3cb27 »
2007-04-21 Changes for Rake 0.7 3
285 add_import("x.dummy")
286 load_imports
287 end
928e0a23 »
2011-07-22 Remove requirement of flexmock per Ruby bug #4987
288
289 # HACK no assertions
c8197eb5 »
2006-06-01 added rcov and unit tests
290 end
291
292 def test_building_imported_files_on_demand
928e0a23 »
2011-07-22 Remove requirement of flexmock per Ruby bug #4987
293 loader = util_loader
294
9bb3cb27 »
2007-04-21 Changes for Rake 0.7 3
295 @app.instance_eval do
928e0a23 »
2011-07-22 Remove requirement of flexmock per Ruby bug #4987
296 intern(Rake::Task, "x.dummy").enhance do loader.make_dummy end
297 add_loader("dummy", loader)
9bb3cb27 »
2007-04-21 Changes for Rake 0.7 3
298 add_import("x.dummy")
299 load_imports
300 end
928e0a23 »
2011-07-22 Remove requirement of flexmock per Ruby bug #4987
301
302 # HACK no assertions
c8197eb5 »
2006-06-01 added rcov and unit tests
303 end
304
9d09be75 »
2013-04-12 Applied style guide to tests.
305 def test_handle_options_should_strip_options_from_argv
bdb31e3b »
2008-10-31 am - Options parsing now appropriately removed rake options from the …
306 assert !@app.options.trace
307
308 valid_option = '--trace'
336559f2 »
2014-02-13 Refactor ARGV setup into setup_command_line method.
309 setup_command_line(valid_option)
bdb31e3b »
2008-10-31 am - Options parsing now appropriately removed rake options from the …
310
311 @app.handle_options
312
313 assert !ARGV.include?(valid_option)
314 assert @app.options.trace
315 end
316
e82809b3 »
2012-11-16 Fix trace swallowing task name arguments.
317 def test_handle_options_trace_default_is_stderr
336559f2 »
2014-02-13 Refactor ARGV setup into setup_command_line method.
318 setup_command_line("--trace")
e82809b3 »
2012-11-16 Fix trace swallowing task name arguments.
319
320 @app.handle_options
321
322 assert_equal STDERR, @app.options.trace_output
323 assert @app.options.trace
324 end
325
326 def test_handle_options_trace_overrides_to_stdout
336559f2 »
2014-02-13 Refactor ARGV setup into setup_command_line method.
327 setup_command_line("--trace=stdout")
e82809b3 »
2012-11-16 Fix trace swallowing task name arguments.
328
329 @app.handle_options
330
331 assert_equal STDOUT, @app.options.trace_output
332 assert @app.options.trace
333 end
334
335 def test_handle_options_trace_does_not_eat_following_task_names
336 assert !@app.options.trace
337
336559f2 »
2014-02-13 Refactor ARGV setup into setup_command_line method.
338 setup_command_line("--trace", "sometask")
e82809b3 »
2012-11-16 Fix trace swallowing task name arguments.
339
340 @app.handle_options
341 assert ARGV.include?("sometask")
342 assert @app.options.trace
bdb31e3b »
2008-10-31 am - Options parsing now appropriately removed rake options from the …
343 end
344
c8197eb5 »
2006-06-01 added rcov and unit tests
345 def test_good_run
346 ran = false
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
347
991f4322 »
2007-11-16 Ruby 1.9 commit
348 ARGV << '--rakelib=""'
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
349
c8197eb5 »
2006-06-01 added rcov and unit tests
350 @app.options.silent = true
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
351
9bb3cb27 »
2007-04-21 Changes for Rake 0.7 3
352 @app.instance_eval do
353 intern(Rake::Task, "default").enhance { ran = true }
354 end
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
355
356 rakefile_default
357
8f02e238 »
2011-06-23 Rake tests now create all files in a temporary directory
358 out, err = capture_io do
359 @app.run
360 end
98e8772d »
2011-06-22 Remove InEnvironment from TestRakeApplication
361
c8197eb5 »
2006-06-01 added rcov and unit tests
362 assert ran
8f02e238 »
2011-06-23 Rake tests now create all files in a temporary directory
363 assert_empty err
364 assert_equal "DEFAULT\n", out
c8197eb5 »
2006-06-01 added rcov and unit tests
365 end
366
367 def test_display_task_run
368 ran = false
336559f2 »
2014-02-13 Refactor ARGV setup into setup_command_line method.
369 setup_command_line('-f', '-s', '--tasks', '--rakelib=""')
d1f89d7c »
2007-05-26 added task parameters, named parameter via desc, column limited output
370 @app.last_description = "COMMENT"
c8197eb5 »
2006-06-01 added rcov and unit tests
371 @app.define_task(Rake::Task, "default")
0dba7c92 »
2011-05-20 Switch rake's tests to minitest
372 out, = capture_io { @app.run }
c8197eb5 »
2006-06-01 added rcov and unit tests
373 assert @app.options.show_tasks
374 assert ! ran
375 assert_match(/rake default/, out)
376 assert_match(/# COMMENT/, out)
377 end
378
379 def test_display_prereqs
380 ran = false
336559f2 »
2014-02-13 Refactor ARGV setup into setup_command_line method.
381 setup_command_line('-f', '-s', '--prereqs', '--rakelib=""')
d1f89d7c »
2007-05-26 added task parameters, named parameter via desc, column limited output
382 @app.last_description = "COMMENT"
c8197eb5 »
2006-06-01 added rcov and unit tests
383 t = @app.define_task(Rake::Task, "default")
384 t.enhance([:a, :b])
385 @app.define_task(Rake::Task, "a")
386 @app.define_task(Rake::Task, "b")
0dba7c92 »
2011-05-20 Switch rake's tests to minitest
387 out, = capture_io { @app.run }
c8197eb5 »
2006-06-01 added rcov and unit tests
388 assert @app.options.show_prereqs
389 assert ! ran
390 assert_match(/rake a$/, out)
391 assert_match(/rake b$/, out)
392 assert_match(/rake default\n( *(a|b)\n){2}/m, out)
393 end
394
395 def test_bad_run
20542edc »
2007-11-16 removed lingering reference to the no_files test directory
396 @app.intern(Rake::Task, "default").enhance { fail }
336559f2 »
2014-02-13 Refactor ARGV setup into setup_command_line method.
397 setup_command_line('-f', '-s', '--rakelib=""')
fbb22e7f »
2014-02-13 Add display of cause exception.
398 _, err = capture_io {
399 assert_raises(SystemExit){ @app.run }
20542edc »
2007-11-16 removed lingering reference to the no_files test directory
400 }
fbb22e7f »
2014-02-13 Add display of cause exception.
401 assert_match(/see full trace/i, err)
c8197eb5 »
2006-06-01 added rcov and unit tests
402 ensure
403 ARGV.clear
404 end
405
406 def test_bad_run_with_trace
407 @app.intern(Rake::Task, "default").enhance { fail }
336559f2 »
2014-02-13 Refactor ARGV setup into setup_command_line method.
408 setup_command_line('-f', '-s', '-t')
fbb22e7f »
2014-02-13 Add display of cause exception.
409 _, err = capture_io {
410 assert_raises(SystemExit) { @app.run }
c8197eb5 »
2006-06-01 added rcov and unit tests
411 }
fbb22e7f »
2014-02-13 Add display of cause exception.
412 refute_match(/see full trace/i, err)
c8197eb5 »
2006-06-01 added rcov and unit tests
413 ensure
414 ARGV.clear
415 end
416
e90ce277 »
2012-03-31 Add --backtrace option to see the backtrace without seing the trace.
417 def test_bad_run_with_backtrace
418 @app.intern(Rake::Task, "default").enhance { fail }
336559f2 »
2014-02-13 Refactor ARGV setup into setup_command_line method.
419 setup_command_line('-f', '-s', '--backtrace')
fbb22e7f »
2014-02-13 Add display of cause exception.
420 _, err = capture_io {
421 assert_raises(SystemExit) {
422 @app.run
423 }
424 }
425 refute_match(/see full trace/, err)
426 ensure
427 ARGV.clear
428 end
429
6e50eab3 »
2014-02-13 Don't display RuntimeError class names in error messages
430 CustomError = Class.new(RuntimeError)
431
432 def test_bad_run_includes_exception_name
433 @app.intern(Rake::Task, "default").enhance {
434 raise CustomError, "intentional"
435 }
336559f2 »
2014-02-13 Refactor ARGV setup into setup_command_line method.
436 setup_command_line('-f', '-s')
6e50eab3 »
2014-02-13 Don't display RuntimeError class names in error messages
437 _, err = capture_io {
438 assert_raises(SystemExit) {
439 @app.run
440 }
441 }
442 assert_match(/CustomError: intentional/, err)
443 end
444
445 def test_rake_error_excludes_exception_name
446 @app.intern(Rake::Task, "default").enhance {
447 fail "intentional"
448 }
336559f2 »
2014-02-13 Refactor ARGV setup into setup_command_line method.
449 setup_command_line('-f', '-s')
6e50eab3 »
2014-02-13 Don't display RuntimeError class names in error messages
450 _, err = capture_io {
451 assert_raises(SystemExit) {
452 @app.run
453 }
454 }
455 refute_match(/RuntimeError/, err)
456 assert_match(/intentional/, err)
457 end
458
000928ef »
2014-02-13 Allow the exception/cause test to work with older Rubies.
459 def cause_supported?
460 ex = StandardError.new
461 ex.respond_to?(:cause)
462 end
463
fbb22e7f »
2014-02-13 Add display of cause exception.
464 def test_printing_original_exception_cause
465 custom_error = Class.new(StandardError)
466 @app.intern(Rake::Task, "default").enhance {
467 begin
468 raise custom_error, "Original Error"
fa694ecc »
2014-02-13 Fix unused variable warning
469 rescue custom_error
fbb22e7f »
2014-02-13 Add display of cause exception.
470 raise custom_error, "Secondary Error"
471 end
472 }
336559f2 »
2014-02-13 Refactor ARGV setup into setup_command_line method.
473 setup_command_line('-f', '-s')
fbb22e7f »
2014-02-13 Add display of cause exception.
474 _ ,err = capture_io {
475 assert_raises(SystemExit) {
476 @app.run
477 }
e90ce277 »
2012-03-31 Add --backtrace option to see the backtrace without seing the trace.
478 }
000928ef »
2014-02-13 Allow the exception/cause test to work with older Rubies.
479 if cause_supported?
480 assert_match(/Original Error/, err)
481 end
fbb22e7f »
2014-02-13 Add display of cause exception.
482 assert_match(/Secondary Error/, err)
e90ce277 »
2012-03-31 Add --backtrace option to see the backtrace without seing the trace.
483 ensure
484 ARGV.clear
485 end
486
c8197eb5 »
2006-06-01 added rcov and unit tests
487 def test_run_with_bad_options
488 @app.intern(Rake::Task, "default").enhance { fail }
336559f2 »
2014-02-13 Refactor ARGV setup into setup_command_line method.
489 setup_command_line('-f', '-s', '--xyzzy')
0dba7c92 »
2011-05-20 Switch rake's tests to minitest
490 assert_raises(SystemExit) {
491 capture_io { @app.run }
c8197eb5 »
2006-06-01 added rcov and unit tests
492 }
493 ensure
494 ARGV.clear
495 end
efc4a7d3 »
2011-03-13 Added test for deprecation method
496
3680bf61 »
2011-07-22 Remove requirement for session gem from rake tests
497 def test_standard_exception_handling_invalid_option
498 out, err = capture_io do
499 e = assert_raises SystemExit do
500 @app.standard_exception_handling do
501 raise OptionParser::InvalidOption, 'blah'
502 end
503 end
504
505 assert_equal 1, e.status
506 end
507
508 assert_empty out
509 assert_equal "invalid option: blah\n", err
510 end
511
512 def test_standard_exception_handling_other
513 out, err = capture_io do
514 e = assert_raises SystemExit do
515 @app.standard_exception_handling do
516 raise 'blah'
517 end
518 end
519
520 assert_equal 1, e.status
521 end
522
523 assert_empty out
524 assert_match "rake aborted!\n", err
525 assert_match "blah\n", err
526 end
527
528 def test_standard_exception_handling_system_exit
529 out, err = capture_io do
530 e = assert_raises SystemExit do
531 @app.standard_exception_handling do
532 exit 0
533 end
534 end
535
536 assert_equal 0, e.status
537 end
538
539 assert_empty out
540 assert_empty err
541 end
542
543 def test_standard_exception_handling_system_exit_nonzero
544 out, err = capture_io do
545 e = assert_raises SystemExit do
546 @app.standard_exception_handling do
547 exit 5
548 end
549 end
550
551 assert_equal 5, e.status
552 end
553
554 assert_empty out
555 assert_empty err
556 end
557
928e0a23 »
2011-07-22 Remove requirement of flexmock per Ruby bug #4987
558 def util_loader
559 loader = Object.new
560
561 loader.instance_variable_set :@load_called, false
562 def loader.load arg
563 raise ArgumentError, arg unless arg == 'x.dummy'
564 @load_called = true
565 end
566
567 loader.instance_variable_set :@make_dummy_called, false
568 def loader.make_dummy
569 @make_dummy_called = true
570 end
571
572 loader
573 end
574
c8197eb5 »
2006-06-01 added rcov and unit tests
575 end
Something went wrong with that request. Please try again.