mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Merge pull request #16984 from Homebrew/no-tty
rm unused OutputAsTTY helper
This commit is contained in:
commit
9ae51618b9
@ -5,6 +5,7 @@ require "deprecate_disable"
|
||||
require "formula_text_auditor"
|
||||
require "formula_versions"
|
||||
require "resource_auditor"
|
||||
require "utils/shared_audits"
|
||||
|
||||
module Homebrew
|
||||
# Auditor for checking common violations in {Formula}e.
|
||||
|
@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe "Internal Tap JSON -- Formula" do
|
||||
include FileUtils
|
||||
|
||||
let(:internal_tap_json) { File.read(TEST_FIXTURE_DIR/"internal_tap_json/homebrew-core.json").chomp }
|
||||
let(:tap_git_head) { "9977471165641744a829d3e494fa563407503297" }
|
||||
|
||||
|
@ -4,6 +4,8 @@ require "cmd/deps"
|
||||
require "cmd/shared_examples/args_parse"
|
||||
|
||||
RSpec.describe Homebrew::Cmd::Deps do
|
||||
include FileUtils
|
||||
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
it "outputs all of a Formula's dependencies and their dependencies on separate lines", :integration_test do
|
||||
|
@ -4,6 +4,15 @@ require "cmd/info"
|
||||
require "cmd/shared_examples/args_parse"
|
||||
|
||||
RSpec.describe Homebrew::Cmd::Info do
|
||||
RSpec::Matchers.define :a_json_string do
|
||||
match do |actual|
|
||||
JSON.parse(actual)
|
||||
true
|
||||
rescue JSON::ParserError
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
it "prints as json with the --json=v1 flag", :integration_test do
|
||||
|
@ -3,6 +3,8 @@
|
||||
require "cmd/shared_examples/args_parse"
|
||||
|
||||
RSpec.describe "brew uses" do
|
||||
include FileUtils
|
||||
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
it "prints the Formulae a given Formula is used by", :integration_test do
|
||||
|
@ -6,6 +6,8 @@ require "tap"
|
||||
require "cmd/shared_examples/args_parse"
|
||||
|
||||
RSpec.describe Homebrew::DevCmd::PrPull do
|
||||
include FileUtils
|
||||
|
||||
let(:pr_pull) { described_class.new(["foo"]) }
|
||||
let(:formula_rebuild) do
|
||||
<<~EOS
|
||||
|
@ -3,6 +3,8 @@
|
||||
require "formula_auditor"
|
||||
|
||||
RSpec.describe Homebrew::FormulaAuditor do
|
||||
include FileUtils
|
||||
|
||||
let(:dir) { mktmpdir }
|
||||
let(:foo_version) do
|
||||
@count ||= 0
|
||||
|
@ -4,6 +4,8 @@ require "keg"
|
||||
require "stringio"
|
||||
|
||||
RSpec.describe Keg do
|
||||
include FileUtils
|
||||
|
||||
def setup_test_keg(name, version)
|
||||
path = HOMEBREW_CELLAR/name/version
|
||||
(path/"bin").mkpath
|
||||
|
@ -44,7 +44,6 @@ require "test/support/helper/files"
|
||||
require "test/support/helper/fixtures"
|
||||
require "test/support/helper/formula"
|
||||
require "test/support/helper/mktmpdir"
|
||||
require "test/support/helper/output_as_tty"
|
||||
|
||||
require "test/support/helper/spec/shared_context/homebrew_cask" if OS.mac?
|
||||
require "test/support/helper/spec/shared_context/integration_test"
|
||||
@ -129,17 +128,12 @@ RSpec.configure do |config|
|
||||
# Never truncate output objects.
|
||||
RSpec::Support::ObjectFormatter.default_instance.max_formatted_output_length = nil
|
||||
|
||||
config.include(FileUtils)
|
||||
|
||||
config.include(Context)
|
||||
|
||||
config.include(RuboCop::RSpec::ExpectOffense)
|
||||
|
||||
config.include(Test::Helper::Cask)
|
||||
config.include(Test::Helper::Fixtures)
|
||||
config.include(Test::Helper::Formula)
|
||||
config.include(Test::Helper::MkTmpDir)
|
||||
config.include(Test::Helper::OutputAsTTY)
|
||||
|
||||
config.before(:each, :needs_linux) do
|
||||
skip "Not running on Linux." unless OS.linux?
|
||||
@ -310,16 +304,6 @@ end
|
||||
|
||||
RSpec::Matchers.define_negated_matcher :not_to_output, :output
|
||||
RSpec::Matchers.alias_matcher :have_failed, :be_failed
|
||||
RSpec::Matchers.alias_matcher :a_string_containing, :include
|
||||
|
||||
RSpec::Matchers.define :a_json_string do
|
||||
match do |actual|
|
||||
JSON.parse(actual)
|
||||
true
|
||||
rescue JSON::ParserError
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
# Match consecutive elements in an array.
|
||||
RSpec::Matchers.define :array_including_cons do |*cons|
|
||||
|
@ -1,88 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "delegate"
|
||||
|
||||
module Test
|
||||
module Helper
|
||||
module OutputAsTTY
|
||||
# This is a custom wrapper for the `output` matcher,
|
||||
# used for testing output to a TTY:
|
||||
#
|
||||
# expect {
|
||||
# print "test" if $stdout.tty?
|
||||
# }.to output("test").to_stdout.as_tty
|
||||
#
|
||||
# expect {
|
||||
# # command
|
||||
# }.to output(...).to_stderr.as_tty.with_color
|
||||
#
|
||||
class Output < SimpleDelegator
|
||||
def matches?(block)
|
||||
return super(block) unless @tty
|
||||
|
||||
colored_tty_block = lambda do
|
||||
instance_eval("$#{@output} # $stdout", __FILE__, __LINE__).extend(Module.new do
|
||||
def tty?
|
||||
true
|
||||
end
|
||||
|
||||
alias_method :isatty, :tty?
|
||||
end)
|
||||
block.call
|
||||
end
|
||||
|
||||
return super(colored_tty_block) if @colors
|
||||
|
||||
uncolored_tty_block = lambda do
|
||||
instance_eval <<-EOS, __FILE__, __LINE__ + 1
|
||||
begin # begin
|
||||
captured_stream = StringIO.new # captured_stream = StringIO.new
|
||||
|
||||
original_stream = $#{@output} # original_stream = $stdout
|
||||
$#{@output} = captured_stream # $stdout = captured_stream
|
||||
|
||||
colored_tty_block.call # colored_tty_block.call
|
||||
ensure # ensure
|
||||
$#{@output} = original_stream # $stdout = original_stream
|
||||
$#{@output}.print Tty.strip_ansi(captured_stream.string) # $stdout.print Tty.strip_ansi(captured_stream.string)
|
||||
end # end
|
||||
EOS
|
||||
end
|
||||
|
||||
super(uncolored_tty_block)
|
||||
end
|
||||
|
||||
def to_stdout
|
||||
@output = :stdout
|
||||
super
|
||||
self
|
||||
end
|
||||
|
||||
def to_stderr
|
||||
@output = :stderr
|
||||
super
|
||||
self
|
||||
end
|
||||
|
||||
def as_tty
|
||||
@tty = true
|
||||
return self if [:stdout, :stderr].include?(@output)
|
||||
|
||||
raise "`as_tty` can only be chained to `stdout` or `stderr`."
|
||||
end
|
||||
|
||||
def with_color
|
||||
@colors = true
|
||||
return self if @tty
|
||||
|
||||
raise "`with_color` can only be chained to `as_tty`."
|
||||
end
|
||||
end
|
||||
|
||||
def output(*args)
|
||||
core_matcher = super(*args)
|
||||
Output.new(core_matcher)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -3,6 +3,8 @@
|
||||
require "system_command"
|
||||
|
||||
RSpec.describe SystemCommand::Result do
|
||||
RSpec::Matchers.alias_matcher :a_string_containing, :include
|
||||
|
||||
subject(:result) do
|
||||
described_class.new([], output_array, instance_double(Process::Status, exitstatus: 0, success?: true),
|
||||
secrets: [])
|
||||
|
@ -194,6 +194,8 @@ RSpec.describe SystemCommand do
|
||||
end
|
||||
|
||||
context "when `debug?` is true" do
|
||||
include Context
|
||||
|
||||
let(:options) do
|
||||
{ args: [
|
||||
"-c",
|
||||
|
@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Tap do
|
||||
include FileUtils
|
||||
|
||||
alias_matcher :have_formula_file, :be_formula_file
|
||||
alias_matcher :have_custom_remote, :be_custom_remote
|
||||
|
||||
|
@ -3,6 +3,8 @@
|
||||
require "utils/gzip"
|
||||
|
||||
RSpec.describe Utils::Gzip do
|
||||
include FileUtils
|
||||
|
||||
describe "compress_with_options" do
|
||||
it "uses the explicitly specified mtime, orig_name, and output path when passed" do
|
||||
mktmpdir do |path|
|
||||
|
Loading…
x
Reference in New Issue
Block a user