From 4f9c15644910c4c82c318f18753480adf4caa284 Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Wed, 28 Jun 2017 18:36:29 -0700 Subject: [PATCH] Always set_default_options This allows Rake.with_application to work without users having to know to set the default options manually. --- lib/rake/application.rb | 2 ++ lib/rake/rake_module.rb | 2 -- test/test_rake_application.rb | 9 +++++++++ test/test_rake_task.rb | 12 +++++++++--- test/test_rake_win32.rb | 6 +++++- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/rake/application.rb b/lib/rake/application.rb index 650b6522c..8c896888f 100644 --- a/lib/rake/application.rb +++ b/lib/rake/application.rb @@ -62,6 +62,8 @@ def initialize add_loader("rake", DefaultLoader.new) @tty_output = STDOUT.tty? @terminal_columns = ENV["RAKE_COLUMNS"].to_i + + set_default_options end # Run the Rake application. The run method performs the following diff --git a/lib/rake/rake_module.rb b/lib/rake/rake_module.rb index 1ee9d7d63..03c295624 100644 --- a/lib/rake/rake_module.rb +++ b/lib/rake/rake_module.rb @@ -46,8 +46,6 @@ def add_rakelib(*files) # Dir.chdir 'other/directory' # # other_rake = Rake.with_application do |rake| - # rake.set_default_options - # # rake.load_rakefile # end # diff --git a/test/test_rake_application.rb b/test/test_rake_application.rb index c7d45652c..456f7d878 100644 --- a/test/test_rake_application.rb +++ b/test/test_rake_application.rb @@ -49,6 +49,8 @@ def test_display_exception_details end out, err = capture_io do + @app.set_default_options # reset trace output IO + @app.display_error_message ex end @@ -65,6 +67,8 @@ def test_display_exception_details_bad_encoding end out, err = capture_io do + @app.set_default_options # reset trace output IO + @app.display_error_message ex end @@ -86,6 +90,8 @@ def test_display_exception_details_cause end out, err = capture_io do + @app.set_default_options # reset trace output IO + @app.display_error_message ex end @@ -472,6 +478,7 @@ def test_bad_run def test_bad_run_with_trace @app.intern(Rake::Task, "default").enhance { fail } _, err = capture_io { + @app.set_default_options assert_raises(SystemExit) { @app.run %w[-f -s -t] } } refute_match(/see full trace/i, err) @@ -563,6 +570,8 @@ def test_standard_exception_handling_invalid_option def test_standard_exception_handling_other out, err = capture_io do + @app.set_default_options # reset trace output IO + e = assert_raises SystemExit do @app.standard_exception_handling do raise "blah" diff --git a/test/test_rake_task.rb b/test/test_rake_task.rb index b2bbb6d95..8bfdedb4e 100644 --- a/test/test_rake_task.rb +++ b/test/test_rake_task.rb @@ -62,10 +62,14 @@ def test_invoke_with_circular_dependencies end def test_dry_run_prevents_actions - Rake.application.options.dryrun = true runlist = [] t1 = task(:t1) { |t| runlist << t.name; 3321 } - _, err = capture_io { t1.invoke } + _, err = capture_io { + Rake.application.set_default_options # reset trace output IO + Rake.application.options.dryrun = true + + t1.invoke + } assert_match(/execute .*t1/i, err) assert_match(/dry run/i, err) refute_match(/invoke/i, err) @@ -75,9 +79,11 @@ def test_dry_run_prevents_actions end def test_tasks_can_be_traced - Rake.application.options.trace = true t1 = task(:t1) _, err = capture_io { + Rake.application.set_default_options # reset trace output IO + Rake.application.options.trace = true + t1.invoke } assert_match(/invoke t1/i, err) diff --git a/test/test_rake_win32.rb b/test/test_rake_win32.rb index 292af4715..6c341f486 100644 --- a/test/test_rake_win32.rb +++ b/test/test_rake_win32.rb @@ -65,7 +65,11 @@ def test_win32_backtrace_with_different_case rake.options.trace = true rake.instance_variable_set(:@rakefile, "Rakefile") - _, err = capture_io { rake.display_error_message(ex) } + _, err = capture_io { + rake.set_default_options # reset trace output IO + + rake.display_error_message(ex) + } assert_match(/rakefile/, err) end