Skip to content
Snippets Groups Projects
Commit acd0877d authored by Mike McQuaid's avatar Mike McQuaid Committed by GitHub
Browse files

Merge pull request #772 from reitermarkus/shutup-helper

Refactor `shutup`.
parents 340e967a 39e95065
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,8 @@ $LOAD_PATH.push(project_root.join("lib").to_s) ...@@ -22,6 +22,8 @@ $LOAD_PATH.push(project_root.join("lib").to_s)
ENV["HOMEBREW_NO_EMOJI"] = "1" ENV["HOMEBREW_NO_EMOJI"] = "1"
ENV["HOMEBREW_CASK_OPTS"] = nil ENV["HOMEBREW_CASK_OPTS"] = nil
require "test/helper/shutup"
Dir["#{project_root}/spec/support/*.rb"].each(&method(:require)) Dir["#{project_root}/spec/support/*.rb"].each(&method(:require))
# from Homebrew. Provides expects method. # from Homebrew. Provides expects method.
...@@ -63,5 +65,5 @@ Hbc.caskroom = Hbc.homebrew_prefix.join("TestCaskroom") ...@@ -63,5 +65,5 @@ Hbc.caskroom = Hbc.homebrew_prefix.join("TestCaskroom")
RSpec.configure do |config| RSpec.configure do |config|
config.order = :random config.order = :random
config.include ShutupHelper config.include(Test::Helper::Shutup)
end end
module ShutupHelper
def shutup
if ENV.key?("VERBOSE_TESTS")
yield
else
begin
tmperr = $stderr.clone
tmpout = $stdout.clone
$stderr.reopen "/dev/null", "w"
$stdout.reopen "/dev/null", "w"
yield
ensure
$stderr.reopen tmperr
$stdout.reopen tmpout
end
end
end
end
...@@ -23,23 +23,8 @@ $LOAD_PATH.push(project_root.join("lib").to_s) ...@@ -23,23 +23,8 @@ $LOAD_PATH.push(project_root.join("lib").to_s)
ENV["HOMEBREW_NO_EMOJI"] = "1" ENV["HOMEBREW_NO_EMOJI"] = "1"
ENV["HOMEBREW_CASK_OPTS"] = nil ENV["HOMEBREW_CASK_OPTS"] = nil
# TODO: temporary, copied from old Homebrew, this method is now moved inside a class require "test/helper/shutup"
def shutup include Test::Helper::Shutup
if ENV.key?("VERBOSE_TESTS")
yield
else
begin
tmperr = $stderr.clone
tmpout = $stdout.clone
$stderr.reopen "/dev/null", "w"
$stdout.reopen "/dev/null", "w"
yield
ensure
$stderr.reopen tmperr
$stdout.reopen tmpout
end
end
end
def sudo(*args) def sudo(*args)
%w[/usr/bin/sudo -E --] + Array(args).flatten %w[/usr/bin/sudo -E --] + Array(args).flatten
......
module Test
module Helper
module Shutup
def shutup
if ENV.key?("VERBOSE_TESTS")
yield
else
begin
tmperr = $stderr.clone
tmpout = $stdout.clone
$stderr.reopen("/dev/null")
$stdout.reopen("/dev/null")
yield
ensure
$stderr.reopen(tmperr)
$stdout.reopen(tmpout)
tmperr.close
tmpout.close
end
end
end
end
end
end
...@@ -63,6 +63,9 @@ module Homebrew ...@@ -63,6 +63,9 @@ module Homebrew
end end
class TestCase < ::Minitest::Test class TestCase < ::Minitest::Test
require "test/helper/shutup"
include Test::Helper::Shutup
include VersionAssertions include VersionAssertions
include FSLeakLogger include FSLeakLogger
...@@ -73,22 +76,6 @@ module Homebrew ...@@ -73,22 +76,6 @@ module Homebrew
@_f = Class.new(Formula, &block).new(name, path, spec) @_f = Class.new(Formula, &block).new(name, path, spec)
end end
def shutup
err = $stderr.dup
out = $stdout.dup
begin
$stderr.reopen("/dev/null")
$stdout.reopen("/dev/null")
yield
ensure
$stderr.reopen(err)
$stdout.reopen(out)
err.close
out.close
end
end
def mktmpdir(prefix_suffix = nil, &block) def mktmpdir(prefix_suffix = nil, &block)
Dir.mktmpdir(prefix_suffix, HOMEBREW_TEMP, &block) Dir.mktmpdir(prefix_suffix, HOMEBREW_TEMP, &block)
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment