diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb
index e5a7d9202b..0c6f0eb367 100644
--- a/Library/Homebrew/cask/lib/hbc/system_command.rb
+++ b/Library/Homebrew/cask/lib/hbc/system_command.rb
@@ -25,11 +25,11 @@ module Hbc
each_output_line do |type, line|
case type
when :stdout
+ puts line.chomp if print_stdout?
processed_output[:stdout] << line
- ohai line.chomp if print_stdout?
when :stderr
+ $stderr.puts Formatter.error(line.chomp) if print_stderr?
processed_output[:stderr] << line
- ohai line.chomp if print_stderr?
end
end
@@ -100,17 +100,23 @@ module Hbc
def each_line_from(sources)
loop do
- readable_sources = IO.select(sources)[0]
- readable_sources.delete_if(&:eof?).first(1).each do |source|
- type = ((source == sources[0]) ? :stdout : :stderr)
+ readable_sources, = IO.select(sources)
+
+ readable_sources = readable_sources.reject(&:eof?)
+
+ break if readable_sources.empty?
+
+ readable_sources.each do |source|
begin
- yield(type, source.readline_nonblock || "")
+ line = source.readline_nonblock || ""
+ type = (source == sources[0]) ? :stdout : :stderr
+ yield(type, line)
rescue IO::WaitReadable, EOFError
next
end
end
- break if readable_sources.empty?
end
+
sources.each(&:close_read)
end
diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb
index 02bbb7c6d9..362a5134c0 100644
--- a/Library/Homebrew/rubocops/extend/formula_cop.rb
+++ b/Library/Homebrew/rubocops/extend/formula_cop.rb
@@ -460,7 +460,7 @@ module RuboCop
when :str
node.str_content
when :dstr
- node.each_child_node(:str).map(&:str_content).join("")
+ node.each_child_node(:str).map(&:str_content).join
when :const
node.const_name
when :sym
diff --git a/Library/Homebrew/test/cask/download_strategy_spec.rb b/Library/Homebrew/test/cask/download_strategy_spec.rb
index ed8cd01ef6..3a69edaaf4 100644
--- a/Library/Homebrew/test/cask/download_strategy_spec.rb
+++ b/Library/Homebrew/test/cask/download_strategy_spec.rb
@@ -148,7 +148,7 @@ describe "download strategies", :cask do
"DBw2KdR24q9t1wfjS9LUzelf5TWk6ojj8p9%2FHjl%2Fi%2FVCXN",
"N4o1mW%2FMayy2tTY1qcC%2FTmqI1ulZS8SNuaSgr9Iys9oDF1%2",
"BPK%2B4Sg==",
- ].join("")
+ ].join
end
describe "#tarball_path" do
diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb
index 67fcb027a8..2500a53fa3 100644
--- a/Library/Homebrew/test/cask/dsl_spec.rb
+++ b/Library/Homebrew/test/cask/dsl_spec.rb
@@ -20,7 +20,7 @@ describe Hbc::DSL, :cask do
}
it "prints a warning that it has encountered an unexpected method" do
- expected = Regexp.compile(<<~EOS.lines.map(&:chomp).join(""))
+ expected = Regexp.compile(<<~EOS.lines.map(&:chomp).join)
(?m)
Warning:
.*
diff --git a/Library/Homebrew/test/cask/pkg_spec.rb b/Library/Homebrew/test/cask/pkg_spec.rb
index f92d6854e2..6a7247058e 100644
--- a/Library/Homebrew/test/cask/pkg_spec.rb
+++ b/Library/Homebrew/test/cask/pkg_spec.rb
@@ -134,7 +134,7 @@ describe Hbc::Pkg, :cask do
#{volume}
paths
- #{(pkg_files + pkg_directories).map { |f| "#{f}" }.join("")}
+ #{(pkg_files + pkg_directories).map { |f| "#{f}" }.join}
diff --git a/Library/Homebrew/test/cask/system_command_spec.rb b/Library/Homebrew/test/cask/system_command_spec.rb
index ba5ea03fcb..6e7397931f 100644
--- a/Library/Homebrew/test/cask/system_command_spec.rb
+++ b/Library/Homebrew/test/cask/system_command_spec.rb
@@ -66,10 +66,10 @@ describe Hbc::SystemCommand, :cask do
describe "with default options" do
it "echoes only STDERR" do
- expected = [2, 4, 6].map { |i| "==> #{i}\n" }.join("")
+ expected = [2, 4, 6].map { |i| "#{i}\n" }.join
expect {
described_class.run(command, options)
- }.to output(expected).to_stdout
+ }.to output(expected).to_stderr
end
include_examples("it returns '1 2 3 4 5 6'")
@@ -80,12 +80,10 @@ describe Hbc::SystemCommand, :cask do
options.merge!(print_stdout: true)
end
- it "echoes both STDOUT and STDERR" do
- (1..6).each do |i|
- expect {
- described_class.run(command, options)
- }.to output(/==> #{ i }/).to_stdout
- end
+ it "echoes both STDOUT and STDERR", :focus do
+ expect { described_class.run(command, options) }
+ .to output("1\n3\n5\n").to_stdout
+ .and output("2\n4\n6\n").to_stderr
end
include_examples("it returns '1 2 3 4 5 6'")
@@ -111,7 +109,7 @@ describe Hbc::SystemCommand, :cask do
end
it "echoes only STDOUT" do
- expected = [1, 3, 5].map { |i| "==> #{i}\n" }.join("")
+ expected = [1, 3, 5].map { |i| "#{i}\n" }.join
expect {
described_class.run(command, options)
}.to output(expected).to_stdout
diff --git a/Library/Homebrew/utils/tty.rb b/Library/Homebrew/utils/tty.rb
index 6e321b2f9b..eb6f02746f 100644
--- a/Library/Homebrew/utils/tty.rb
+++ b/Library/Homebrew/utils/tty.rb
@@ -6,10 +6,12 @@ module Tty
end
def width
- width = `/bin/stty size 2>/dev/null`.split[1]
- width = `/usr/bin/tput cols 2>/dev/null`.split[0] if width.to_i.zero?
- width ||= 80
- width.to_i
+ @width ||= begin
+ width = `/bin/stty size 2>/dev/null`.split[1]
+ width = `/usr/bin/tput cols 2>/dev/null`.split[0] if width.to_i.zero?
+ width ||= 80
+ width.to_i
+ end
end
def truncate(string)