Skip to content

Commit

Permalink
Always set_default_options
Browse files Browse the repository at this point in the history
This allows Rake.with_application to work without users having to know
to set the default options manually.
  • Loading branch information
drbrain committed Jun 29, 2017
1 parent ae4f786 commit 4f9c156
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/rake/application.rb
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions lib/rake/rake_module.rb
Expand Up @@ -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
#
Expand Down
9 changes: 9 additions & 0 deletions test/test_rake_application.rb
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down
12 changes: 9 additions & 3 deletions test/test_rake_task.rb
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion test/test_rake_win32.rb
Expand Up @@ -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
Expand Down

0 comments on commit 4f9c156

Please sign in to comment.