diff --git a/Library/Homebrew/sandbox.rb b/Library/Homebrew/sandbox.rb index ab94abc9f8..a389505b0f 100644 --- a/Library/Homebrew/sandbox.rb +++ b/Library/Homebrew/sandbox.rb @@ -101,8 +101,21 @@ class Sandbox command = [SANDBOX_EXEC, "-f", seatbelt.path, *args] # Start sandbox in a pseudoterminal to prevent access of the parent terminal. T.unsafe(PTY).spawn(*command) do |r, w, pid| - old_winch = trap(:WINCH) { w.winsize = $stdout.winsize if $stdout.tty? } - w.winsize = $stdout.winsize if $stdout.tty? + # Set the PTY's window size to match the parent terminal. + # Some formula tests are sensitive to the terminal size and fail if this is not set. + winch = proc do |_sig| + w.winsize = if $stdout.tty? + # We can only use IO#winsize if the IO object is a TTY. + $stdout.winsize + else + # Otherwise, default to tput, if available. + # This relies on ncurses rather than the system's ioctl. + [Utils.popen_read("tput", "lines").to_i, Utils.popen_read("tput", "cols").to_i] + end + end + # Update the window size whenever the parent terminal's window size changes. + old_winch = trap(:WINCH, &winch) + winch.call(nil) $stdin.raw! if $stdin.tty? stdin_thread = Thread.new { IO.copy_stream($stdin, w) } diff --git a/Library/Homebrew/test/sandbox_spec.rb b/Library/Homebrew/test/sandbox_spec.rb index 2d827f9e06..46b3a57df5 100644 --- a/Library/Homebrew/test/sandbox_spec.rb +++ b/Library/Homebrew/test/sandbox_spec.rb @@ -34,7 +34,8 @@ describe Sandbox, :needs_macos do it "complains on failure" do ENV["HOMEBREW_VERBOSE"] = "1" - expect(Utils).to receive(:popen_read).and_return("foo") + allow(Utils).to receive(:popen_read).and_call_original + allow(Utils).to receive(:popen_read).with("syslog", any_args).and_return("foo") expect { sandbox.exec "false" } .to raise_error(ErrorDuringExecution) @@ -49,7 +50,8 @@ describe Sandbox, :needs_macos do Mar 17 02:55:06 sandboxd[342]: Python(49765) deny file-write-unlink /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/errors.pyc bar EOS - expect(Utils).to receive(:popen_read).and_return(with_bogus_error) + allow(Utils).to receive(:popen_read).and_call_original + allow(Utils).to receive(:popen_read).with("syslog", any_args).and_return(with_bogus_error) expect { sandbox.exec "false" } .to raise_error(ErrorDuringExecution)