Skip to content

Commit

Permalink
Use capture_output instead of capture_io
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Jan 10, 2024
1 parent c94aff8 commit 2bc6561
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 60 deletions.
58 changes: 29 additions & 29 deletions test/test_rake_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_display_exception_details
rescue => ex
end

out, err = capture_io do
out, err = capture_output do
@app.set_default_options # reset trace output IO

@app.display_error_message ex
Expand All @@ -72,7 +72,7 @@ def detailed_message(**)
rescue error_class => ex
end

out, err = capture_io do
out, err = capture_output do
@app.set_default_options # reset trace output IO

@app.display_error_message ex
Expand All @@ -91,7 +91,7 @@ def test_display_exception_details_bad_encoding
rescue => ex
end

out, err = capture_io do
out, err = capture_output do
@app.set_default_options # reset trace output IO

@app.display_error_message ex
Expand All @@ -111,7 +111,7 @@ def test_display_exception_details_cause
end
end

out, err = capture_io do
out, err = capture_output do
@app.set_default_options # reset trace output IO

@app.display_error_message ex
Expand All @@ -129,7 +129,7 @@ def test_display_tasks
@app.options.show_task_pattern = //
@app.last_description = "COMMENT"
@app.define_task(Rake::Task, "t")
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
out, = capture_output do @app.instance_eval { display_tasks_and_comments } end
assert_match(/^rake t/, out)
assert_match(/# COMMENT/, out)
end
Expand All @@ -142,7 +142,7 @@ def test_display_tasks_with_long_comments
@app.last_description = numbers
@app.define_task(Rake::Task, "t")

out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
out, = capture_output do @app.instance_eval { display_tasks_and_comments } end

assert_match(/^rake t/, out)
assert_match(/# #{numbers[0, 65]}\.\.\./, out)
Expand All @@ -156,7 +156,7 @@ def test_display_tasks_with_task_name_wider_than_tty_display
@app.last_description = "something short"
@app.define_task(Rake::Task, task_name)

out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
out, = capture_output do @app.instance_eval { display_tasks_and_comments } end

# Ensure the entire task name is output and we end up showing no description
assert_match(/rake #{task_name} # .../, out)
Expand All @@ -171,7 +171,7 @@ def test_display_tasks_with_very_long_task_name_to_a_non_tty_shows_name_and_comm
@app.last_description = "something short"
@app.define_task(Rake::Task, task_name)

out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
out, = capture_output do @app.instance_eval { display_tasks_and_comments } end

# Ensure the entire task name is output and we end up showing no description
assert_match(/rake #{task_name} # #{description}/, out)
Expand All @@ -183,7 +183,7 @@ def test_display_tasks_with_long_comments_to_a_non_tty_shows_entire_comment
@app.tty_output = false
@app.last_description = "1234567890" * 8
@app.define_task(Rake::Task, "t")
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
out, = capture_output do @app.instance_eval { display_tasks_and_comments } end
assert_match(/^rake t/, out)
assert_match(/# #{@app.last_description}/, out)
end
Expand All @@ -197,7 +197,7 @@ def test_truncating_comments_to_a_non_tty
@app.last_description = numbers
@app.define_task(Rake::Task, "t")

out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
out, = capture_output do @app.instance_eval { display_tasks_and_comments } end

assert_match(/^rake t/, out)
assert_match(/# #{numbers[0, 65]}\.\.\./, out)
Expand All @@ -208,7 +208,7 @@ def test_describe_tasks
@app.options.show_task_pattern = //
@app.last_description = "COMMENT"
@app.define_task(Rake::Task, "t")
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
out, = capture_output do @app.instance_eval { display_tasks_and_comments } end
assert_match(/^rake t$/, out)
assert_match(/^ {4}COMMENT$/, out)
end
Expand All @@ -219,7 +219,7 @@ def test_show_lines
@app.last_description = "COMMENT"
@app.define_task(Rake::Task, "t")
@app["t"].locations << "HERE:1"
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
out, = capture_output do @app.instance_eval { display_tasks_and_comments } end
assert_match(/^rake t +[^:]+:\d+ *$/, out)
end

Expand Down Expand Up @@ -251,7 +251,7 @@ def test_load_rakefile
def test_load_rakefile_doesnt_print_rakefile_directory_from_same_dir
rakefile_unittest

_, err = capture_io do
_, err = capture_output do
@app.instance_eval do
# pretend we started from the unittest dir
@original_dir = File.expand_path(".")
Expand Down Expand Up @@ -283,7 +283,7 @@ def test_load_rakefile_prints_rakefile_directory_from_subdir
app = Rake::Application.new
app.options.rakelib = []

_, err = capture_io do
_, err = capture_output do
app.instance_eval do
raw_load_rakefile
end
Expand All @@ -296,7 +296,7 @@ def test_load_rakefile_doesnt_print_rakefile_directory_from_subdir_if_silent
rakefile_unittest
Dir.chdir "subdir"

_, err = capture_io do
_, err = capture_output do
@app.instance_eval do
handle_options []
options.silent = true
Expand Down Expand Up @@ -455,7 +455,7 @@ def test_good_run

rakefile_default

out, err = capture_io do
out, err = capture_output do
@app.run %w[--rakelib=""]
end

Expand All @@ -468,7 +468,7 @@ def test_display_task_run
ran = false
@app.last_description = "COMMENT"
@app.define_task(Rake::Task, "default")
out, = capture_io { @app.run %w[-f -s --tasks --rakelib=""] }
out, = capture_output { @app.run %w[-f -s --tasks --rakelib=""] }
assert @app.options.show_tasks
assert ! ran
assert_match(/rake default/, out)
Expand All @@ -482,7 +482,7 @@ def test_display_prereqs
t.enhance([:a, :b])
@app.define_task(Rake::Task, "a")
@app.define_task(Rake::Task, "b")
out, = capture_io { @app.run %w[-f -s --prereqs --rakelib=""] }
out, = capture_output { @app.run %w[-f -s --prereqs --rakelib=""] }
assert @app.options.show_prereqs
assert ! ran
assert_match(/rake a$/, out)
Expand All @@ -492,15 +492,15 @@ def test_display_prereqs

def test_bad_run
@app.intern(Rake::Task, "default").enhance { fail }
_, err = capture_io {
_, err = capture_output {
assert_raises(SystemExit) { @app.run %w[-f -s --rakelib=""] }
}
assert_match(/see full trace/i, err)
end

def test_bad_run_with_trace
@app.intern(Rake::Task, "default").enhance { fail }
_, err = capture_io {
_, err = capture_output {
@app.set_default_options
assert_raises(SystemExit) { @app.run %w[-f -s -t] }
}
Expand All @@ -509,7 +509,7 @@ def test_bad_run_with_trace

def test_bad_run_with_backtrace
@app.intern(Rake::Task, "default").enhance { fail }
_, err = capture_io {
_, err = capture_output {
assert_raises(SystemExit) {
@app.run %w[-f -s --backtrace]
}
Expand All @@ -523,7 +523,7 @@ def test_bad_run_includes_exception_name
@app.intern(Rake::Task, "default").enhance {
raise CustomError, "intentional"
}
_, err = capture_io {
_, err = capture_output {
assert_raises(SystemExit) {
@app.run %w[-f -s]
}
Expand All @@ -535,7 +535,7 @@ def test_rake_error_excludes_exception_name
@app.intern(Rake::Task, "default").enhance {
fail "intentional"
}
_, err = capture_io {
_, err = capture_output {
assert_raises(SystemExit) {
@app.run %w[-f -s]
}
Expand All @@ -558,7 +558,7 @@ def test_printing_original_exception_cause
raise custom_error, "Secondary Error"
end
}
_ ,err = capture_io {
_ ,err = capture_output {
assert_raises(SystemExit) {
@app.run %w[-f -s]
}
Expand All @@ -572,12 +572,12 @@ def test_printing_original_exception_cause
def test_run_with_bad_options
@app.intern(Rake::Task, "default").enhance { fail }
assert_raises(SystemExit) {
capture_io { @app.run %w[-f -s --xyzzy] }
capture_output { @app.run %w[-f -s --xyzzy] }
}
end

def test_standard_exception_handling_invalid_option
out, err = capture_io do
out, err = capture_output do
e = assert_raises SystemExit do
@app.standard_exception_handling do
raise OptionParser::InvalidOption, "blah"
Expand All @@ -592,7 +592,7 @@ def test_standard_exception_handling_invalid_option
end

def test_standard_exception_handling_other
out, err = capture_io do
out, err = capture_output do
@app.set_default_options # reset trace output IO

e = assert_raises SystemExit do
Expand All @@ -610,7 +610,7 @@ def test_standard_exception_handling_other
end

def test_standard_exception_handling_system_exit
out, err = capture_io do
out, err = capture_output do
e = assert_raises SystemExit do
@app.standard_exception_handling do
exit 0
Expand All @@ -625,7 +625,7 @@ def test_standard_exception_handling_system_exit
end

def test_standard_exception_handling_system_exit_nonzero
out, err = capture_io do
out, err = capture_output do
e = assert_raises SystemExit do
@app.standard_exception_handling do
exit 5
Expand Down
10 changes: 5 additions & 5 deletions test/test_rake_application_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_execute_and_continue

def test_execute_and_print
$xyzzy = 0
out, = capture_io do
out, = capture_output do
flags('--execute-print=$xyzzy="pugh"', '-p $xyzzy="pugh"') do
assert_equal "pugh", $xyzzy
assert_equal :exit, @exit
Expand All @@ -119,7 +119,7 @@ def test_execute_and_print
end

def test_help
out, = capture_io do
out, = capture_output do
flags "--help", "-H", "-h"
end

Expand Down Expand Up @@ -386,7 +386,7 @@ def test_no_deprecated_messages
end

def test_verbose
capture_io do
capture_output do
flags("--verbose", "-v") do |opts|
assert Rake::FileUtilsExt.verbose_flag, "verbose should be true"
assert ! opts.silent, "opts should not be silent"
Expand All @@ -395,7 +395,7 @@ def test_verbose
end

def test_version
out, _ = capture_io do
out, _ = capture_output do
flags "--version", "-V"
end

Expand All @@ -405,7 +405,7 @@ def test_version
end

def test_bad_option
_, err = capture_io do
_, err = capture_output do
ex = assert_raises(OptionParser::InvalidOption) do
flags("--bad-option")
end
Expand Down
10 changes: 5 additions & 5 deletions test/test_rake_clean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_clean
def test_cleanup
file_name = create_undeletable_file

out, _ = capture_io do
out, _ = capture_output do
Rake::Cleaner.cleanup(file_name, verbose: false)
end
assert_match(/failed to remove/i, out)
Expand All @@ -31,7 +31,7 @@ def test_cleanup
def test_cleanup_ignores_missing_files
file_name = File.join(@tempdir, "missing_directory", "no_such_file")

out, _ = capture_io do
out, _ = capture_output do
Rake::Cleaner.cleanup(file_name, verbose: false)
end
refute_match(/failed to remove/i, out)
Expand All @@ -40,7 +40,7 @@ def test_cleanup_ignores_missing_files
def test_cleanup_trace
file_name = create_file

out, err = capture_io do
out, err = capture_output do
with_trace true do
Rake::Cleaner.cleanup(file_name)
end
Expand Down Expand Up @@ -79,7 +79,7 @@ def test_cleanup_opt_overrides_trace_silent
def test_cleanup_opt_overrides_trace_verbose
file_name = create_file

out, err = capture_io do
out, err = capture_output do
with_trace false do
Rake::Cleaner.cleanup(file_name, verbose: true)
end
Expand Down Expand Up @@ -132,7 +132,7 @@ def with_trace(value)
old, Rake.application.options.trace =
Rake.application.options.trace, value

# FileUtils caches the $stderr object, which breaks capture_io et. al.
# FileUtils caches the $stderr object, which breaks capture_output et. al.
# We hack it here where it's convenient to do so.
Rake::Cleaner.instance_variable_set :@fileutils_output, nil
yield
Expand Down
4 changes: 2 additions & 2 deletions test/test_rake_file_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def test_egrep_returns_0_if_no_matches
def test_egrep_with_output
files = FileList["*.txt"]

out, = capture_io do
out, = capture_output do
files.egrep(/XYZZY/)
end

Expand All @@ -404,7 +404,7 @@ def test_egrep_with_block
def test_egrep_with_error
files = FileList["*.txt"]

_, err = capture_io do
_, err = capture_output do
files.egrep(/XYZZY/) do |fn, ln, line |
raise "_EGREP_FAILURE_"
end
Expand Down
6 changes: 3 additions & 3 deletions test/test_rake_file_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_nowrite
def test_file_utils_methods_are_available_at_top_level
create_file("a")

capture_io do
capture_output do
rm_rf "a"
end

Expand Down Expand Up @@ -256,7 +256,7 @@ def test_sh_bad_option
def test_sh_verbose
shellcommand

_, err = capture_io do
_, err = capture_output do
verbose(true) {
sh %{shellcommand.rb}, noop: true
}
Expand All @@ -268,7 +268,7 @@ def test_sh_verbose
def test_sh_verbose_false
shellcommand

_, err = capture_io do
_, err = capture_output do
verbose(false) {
sh %{shellcommand.rb}, noop: true
}
Expand Down
Loading

0 comments on commit 2bc6561

Please sign in to comment.