Auto-fix Style/RedundantBegin offenses

- This also required auto-fixes for Layout/EmptyLinesAroundBlockBody and
  Layout/InconsistentIndentation once the auto-fixer had got rid of the
  "redundant begin"s.
This commit is contained in:
Issy Long 2019-10-13 10:03:26 +01:00
parent b78028b9c2
commit 341ea60807
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4
40 changed files with 376 additions and 479 deletions

View File

@ -142,17 +142,15 @@ class BottlePublisher
retry_count = 0
# We're in the cache; make sure to force re-download
loop do
begin
curl_download url, to: filename
break
rescue
raise "Failed to download #{f} bottle from #{url}!" if retry_count >= max_curl_retries
curl_download url, to: filename
break
rescue
raise "Failed to download #{f} bottle from #{url}!" if retry_count >= max_curl_retries
puts "curl download failed; retrying in #{curl_retry_delay_seconds} sec"
sleep curl_retry_delay_seconds
curl_retry_delay_seconds *= 2
retry_count += 1
end
puts "curl download failed; retrying in #{curl_retry_delay_seconds} sec"
sleep curl_retry_delay_seconds
curl_retry_delay_seconds *= 2
retry_count += 1
end
checksum = Checksum.new(:sha256, bottle_info["sha256"])
Pathname.new(filename).verify_checksum(checksum)

View File

@ -65,13 +65,11 @@ module Cask
return yield nil if choices.empty?
Tempfile.open(["choices", ".xml"]) do |file|
begin
file.write Plist::Emit.dump(choices)
file.close
yield file.path
ensure
file.unlink
end
file.write Plist::Emit.dump(choices)
file.close
yield file.path
ensure
file.unlink
end
end
end

View File

@ -19,11 +19,9 @@ module Cask
return to_enum unless block_given?
Tap.flat_map(&:cask_files).each do |f|
begin
yield CaskLoader::FromTapPathLoader.new(f).load
rescue CaskUnreadableError => e
opoo e.message
end
yield CaskLoader::FromTapPathLoader.new(f).load
rescue CaskUnreadableError => e
opoo e.message
end
end

View File

@ -200,11 +200,9 @@ module Cask
end
remaining = all_args.select do |arg|
begin
!process_arguments([arg]).empty?
rescue OptionParser::InvalidOption, OptionParser::MissingArgument, OptionParser::AmbiguousOption
true
end
!process_arguments([arg]).empty?
rescue OptionParser::InvalidOption, OptionParser::MissingArgument, OptionParser::AmbiguousOption
true
end
remaining + non_options

View File

@ -14,16 +14,14 @@ module Cask
def run
odie "Installing casks is supported only on macOS" unless OS.mac?
casks.each do |cask|
begin
Installer.new(cask, binaries: binaries?,
verbose: verbose?,
force: force?,
skip_cask_deps: skip_cask_deps?,
require_sha: require_sha?,
quarantine: quarantine?).install
rescue CaskAlreadyInstalledError => e
opoo e.message
end
Installer.new(cask, binaries: binaries?,
verbose: verbose?,
force: force?,
skip_cask_deps: skip_cask_deps?,
require_sha: require_sha?,
quarantine: quarantine?).install
rescue CaskAlreadyInstalledError => e
opoo e.message
end
end

View File

@ -45,12 +45,10 @@ module Cask
return if dry_run?
upgradable_casks.each do |(old_cask, new_cask)|
begin
upgrade_cask(old_cask, new_cask)
rescue CaskError => e
caught_exceptions << e
next
end
upgrade_cask(old_cask, new_cask)
rescue CaskError => e
caught_exceptions << e
next
end
return if caught_exceptions.empty?

View File

@ -137,11 +137,9 @@ module Cask
locales = MacOS.languages
.map do |language|
begin
Locale.parse(language)
rescue Locale::ParserError
nil
end
Locale.parse(language)
rescue Locale::ParserError
nil
end
.compact
@ -255,18 +253,16 @@ module Cask
ORDINARY_ARTIFACT_CLASSES.each do |klass|
define_method(klass.dsl_key) do |*args|
begin
if [*artifacts.map(&:class), klass].include?(Artifact::StageOnly) &&
(artifacts.map(&:class) & ACTIVATABLE_ARTIFACT_CLASSES).any?
raise CaskInvalidError.new(cask, "'stage_only' must be the only activatable artifact.")
end
artifacts.add(klass.from_args(cask, *args))
rescue CaskInvalidError
raise
rescue => e
raise CaskInvalidError.new(cask, "invalid '#{klass.dsl_key}' stanza: #{e}")
if [*artifacts.map(&:class), klass].include?(Artifact::StageOnly) &&
(artifacts.map(&:class) & ACTIVATABLE_ARTIFACT_CLASSES).any?
raise CaskInvalidError.new(cask, "'stage_only' must be the only activatable artifact.")
end
artifacts.add(klass.from_args(cask, *args))
rescue CaskInvalidError
raise
rescue => e
raise CaskInvalidError.new(cask, "invalid '#{klass.dsl_key}' stanza: #{e}")
end
end

View File

@ -111,12 +111,10 @@ module Cask
return unless @cask.conflicts_with
@cask.conflicts_with[:cask].each do |conflicting_cask|
begin
conflicting_cask = CaskLoader.load(conflicting_cask)
raise CaskConflictError.new(@cask, conflicting_cask) if conflicting_cask.installed?
rescue CaskUnavailableError
next # Ignore conflicting Casks that do not exist.
end
conflicting_cask = CaskLoader.load(conflicting_cask)
raise CaskConflictError.new(@cask, conflicting_cask) if conflicting_cask.installed?
rescue CaskUnavailableError
next # Ignore conflicting Casks that do not exist.
end
end

View File

@ -86,11 +86,9 @@ class Caveats
def keg
@keg ||= [f.prefix, f.opt_prefix, f.linked_keg].map do |d|
begin
Keg.new(d.resolved_path)
rescue
nil
end
Keg.new(d.resolved_path)
rescue
nil
end.compact.first
end

View File

@ -25,11 +25,9 @@ module Homebrew
deps_of_installed = installed.flat_map do |f|
f.runtime_dependencies.map do |dep|
begin
dep.to_formula.full_name
rescue FormulaUnavailableError
dep.name
end
dep.to_formula.full_name
rescue FormulaUnavailableError
dep.name
end
end

View File

@ -382,21 +382,19 @@ module Homebrew
end
reinstallable.each do |f|
begin
reinstall_formula(f, build_from_source: true)
rescue FormulaInstallationAlreadyAttemptedError
# We already attempted to reinstall f as part of the dependency tree of
# another formula. In that case, don't generate an error, just move on.
nil
rescue CannotInstallFormulaError => e
ofail e
rescue BuildError => e
e.dump
puts
Homebrew.failed = true
rescue DownloadError => e
ofail e
end
reinstall_formula(f, build_from_source: true)
rescue FormulaInstallationAlreadyAttemptedError
# We already attempted to reinstall f as part of the dependency tree of
# another formula. In that case, don't generate an error, just move on.
nil
rescue CannotInstallFormulaError => e
ofail e
rescue BuildError => e
e.dump
puts
Homebrew.failed = true
rescue DownloadError => e
ofail e
end
end
end

View File

@ -68,26 +68,22 @@ module Homebrew
uses = formulae.select do |f|
used_formulae.all? do |ff|
begin
deps = f.runtime_dependencies if only_installed_arg
deps ||= if recursive
recursive_includes(Dependency, f, includes, ignores)
else
reject_ignores(f.deps, ignores, includes)
end
deps.any? do |dep|
begin
dep.to_formula.full_name == ff.full_name
rescue
dep.name == ff.name
end
end
rescue FormulaUnavailableError
# Silently ignore this case as we don't care about things used in
# taps that aren't currently tapped.
next
deps = f.runtime_dependencies if only_installed_arg
deps ||= if recursive
recursive_includes(Dependency, f, includes, ignores)
else
reject_ignores(f.deps, ignores, includes)
end
deps.any? do |dep|
dep.to_formula.full_name == ff.full_name
rescue
dep.name == ff.name
end
rescue FormulaUnavailableError
# Silently ignore this case as we don't care about things used in
# taps that aren't currently tapped.
next
end
end

View File

@ -63,11 +63,9 @@ class DescriptionCacheStore < CacheStore
return populate_if_empty! if database.empty?
formula_names.each do |name|
begin
update!(name, Formula[name].desc)
rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS
delete!(name)
end
update!(name, Formula[name].desc)
rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS
delete!(name)
end
end

View File

@ -434,16 +434,14 @@ module Homebrew
def audit_conflicts
formula.conflicts.each do |c|
begin
Formulary.factory(c.name)
rescue TapFormulaUnavailableError
# Don't complain about missing cross-tap conflicts.
next
rescue FormulaUnavailableError
problem "Can't find conflicting formula #{c.name.inspect}."
rescue TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError
problem "Ambiguous conflicting formula #{c.name.inspect}."
end
Formulary.factory(c.name)
rescue TapFormulaUnavailableError
# Don't complain about missing cross-tap conflicts.
next
rescue FormulaUnavailableError
problem "Can't find conflicting formula #{c.name.inspect}."
rescue TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError
problem "Ambiguous conflicting formula #{c.name.inspect}."
end
end

View File

@ -718,15 +718,13 @@ module Homebrew
def check_for_unreadable_installed_formula
formula_unavailable_exceptions = []
Formula.racks.each do |rack|
begin
Formulary.from_rack(rack)
rescue FormulaUnreadableError, FormulaClassUnavailableError,
TapFormulaUnreadableError, TapFormulaClassUnavailableError => e
formula_unavailable_exceptions << e
rescue FormulaUnavailableError,
TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError
nil
end
Formulary.from_rack(rack)
rescue FormulaUnreadableError, FormulaClassUnavailableError,
TapFormulaUnreadableError, TapFormulaClassUnavailableError => e
formula_unavailable_exceptions << e
rescue FormulaUnavailableError,
TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError
nil
end
return if formula_unavailable_exceptions.empty?

View File

@ -213,11 +213,9 @@ module SharedEnvExtension
path.append(
# user paths
ORIGINAL_PATHS.map do |p|
begin
p.realpath.to_s
rescue
nil
end
p.realpath.to_s
rescue
nil
end - %w[/usr/X11/bin /opt/X11/bin],
)
self["PATH"] = path

View File

@ -17,12 +17,10 @@ module Superenv
def homebrew_extra_paths
paths = []
paths += %w[binutils make].map do |f|
begin
bin = Formula[f].opt_bin
bin if bin.directory?
rescue FormulaUnavailableError
nil
end
bin = Formula[f].opt_bin
bin if bin.directory?
rescue FormulaUnavailableError
nil
end.compact
paths
end

View File

@ -387,11 +387,9 @@ class Formula
return [] if versioned_formula?
Pathname.glob(path.to_s.gsub(/\.rb$/, "@*.rb")).map do |path|
begin
Formula[path.basename(".rb").to_s]
rescue FormulaUnavailableError
nil
end
Formula[path.basename(".rb").to_s]
rescue FormulaUnavailableError
nil
end.compact.sort
end
@ -1387,14 +1385,12 @@ class Formula
# @private
def self.each
files.each do |file|
begin
yield Formulary.factory(file)
rescue => e
# Don't let one broken formula break commands. But do complain.
onoe "Failed to import: #{file}"
puts e
next
end
yield Formulary.factory(file)
rescue => e
# Don't let one broken formula break commands. But do complain.
onoe "Failed to import: #{file}"
puts e
next
end
end
@ -1425,11 +1421,9 @@ class Formula
# @private
def self.installed
@installed ||= racks.flat_map do |rack|
begin
Formulary.from_rack(rack)
rescue
[]
end
Formulary.from_rack(rack)
rescue
[]
end.uniq(&:name)
end
@ -1568,11 +1562,9 @@ class Formula
read_from_tab: read_from_tab,
undeclared: undeclared,
).map do |d|
begin
d.to_formula
rescue FormulaUnavailableError
nil
end
d.to_formula
rescue FormulaUnavailableError
nil
end.compact
end

View File

@ -351,28 +351,26 @@ class FormulaInstaller
return if ARGV.force?
conflicts = formula.conflicts.select do |c|
begin
f = Formulary.factory(c.name)
rescue TapFormulaUnavailableError
# If the formula name is a fully-qualified name let's silently
# ignore it as we don't care about things used in taps that aren't
# currently tapped.
false
rescue FormulaUnavailableError => e
# If the formula name doesn't exist any more then complain but don't
# stop installation from continuing.
opoo <<~EOS
f = Formulary.factory(c.name)
rescue TapFormulaUnavailableError
# If the formula name is a fully-qualified name let's silently
# ignore it as we don't care about things used in taps that aren't
# currently tapped.
false
rescue FormulaUnavailableError => e
# If the formula name doesn't exist any more then complain but don't
# stop installation from continuing.
opoo <<~EOS
#{formula}: #{e.message}
'conflicts_with \"#{c.name}\"' should be removed from #{formula.path.basename}.
EOS
raise if ARGV.homebrew_developer?
raise if ARGV.homebrew_developer?
$stderr.puts "Please report this to the #{formula.tap} tap!"
false
else
f.linked_keg.exist? && f.opt_prefix.exist?
end
$stderr.puts "Please report this to the #{formula.tap} tap!"
false
else
f.linked_keg.exist? && f.opt_prefix.exist?
end
raise FormulaConflictError.new(formula, conflicts) unless conflicts.empty?

View File

@ -106,11 +106,9 @@ require "PATH"
ENV["HOMEBREW_PATH"] ||= ENV["PATH"]
ORIGINAL_PATHS = PATH.new(ENV["HOMEBREW_PATH"]).map do |p|
begin
Pathname.new(p).expand_path
rescue
nil
end
Pathname.new(p).expand_path
rescue
nil
end.compact.freeze
HOMEBREW_INTERNAL_COMMAND_ALIASES = {

View File

@ -22,17 +22,15 @@ module Homebrew
def attempt_directory_creation
Keg::MUST_EXIST_DIRECTORIES.each do |dir|
begin
FileUtils.mkdir_p(dir) unless dir.exist?
FileUtils.mkdir_p(dir) unless dir.exist?
# Create these files to ensure that these directories aren't removed
# by the Catalina installer.
# (https://github.com/Homebrew/brew/issues/6263)
keep_file = dir/".keepme"
FileUtils.touch(keep_file) unless keep_file.exist?
rescue
nil
end
# Create these files to ensure that these directories aren't removed
# by the Catalina installer.
# (https://github.com/Homebrew/brew/issues/6263)
keep_file = dir/".keepme"
FileUtils.touch(keep_file) unless keep_file.exist?
rescue
nil
end
end

View File

@ -128,17 +128,15 @@ class Keg
keg_names = kegs.select(&:optlinked?).map(&:name)
keg_formulae = []
kegs_by_source = kegs.group_by do |keg|
begin
# First, attempt to resolve the keg to a formula
# to get up-to-date name and tap information.
f = keg.to_formula
keg_formulae << f
[f.name, f.tap]
rescue FormulaUnavailableError
# If the formula for the keg can't be found,
# fall back to the information in the tab.
[keg.name, keg.tab.tap]
end
f = keg.to_formula
keg_formulae << f
[f.name, f.tap]
rescue FormulaUnavailableError
# If the formula for the keg can't be found,
# fall back to the information in the tab.
[keg.name, keg.tab.tap]
end
all_required_kegs = Set.new

View File

@ -37,15 +37,13 @@ module Readall
def valid_formulae?(formulae)
failed = false
formulae.each do |file|
begin
Formulary.factory(file)
rescue Interrupt
raise
rescue Exception => e # rubocop:disable Lint/RescueException
onoe "Invalid formula: #{file}"
puts e
failed = true
end
Formulary.factory(file)
rescue Interrupt
raise
rescue Exception => e # rubocop:disable Lint/RescueException
onoe "Invalid formula: #{file}"
puts e
failed = true
end
!failed
end

View File

@ -184,13 +184,11 @@ class SoftwareSpec
def recursive_dependencies
deps_f = []
recursive_dependencies = deps.map do |dep|
begin
deps_f << dep.to_formula
dep
rescue TapFormulaUnavailableError
# Don't complain about missing cross-tap dependencies
next
end
deps_f << dep.to_formula
dep
rescue TapFormulaUnavailableError
# Don't complain about missing cross-tap dependencies
next
end.compact.uniq
deps_f.compact.each do |f|
f.recursive_dependencies.each do |dep|
@ -386,11 +384,10 @@ class BottleSpecification
def checksums
tags = collector.keys.sort_by do |tag|
# Sort non-MacOS tags below MacOS tags.
begin
OS::Mac::Version.from_symbol tag
rescue ArgumentError
"0.#{tag}"
end
OS::Mac::Version.from_symbol tag
rescue ArgumentError
"0.#{tag}"
end
checksums = {}
tags.reverse_each do |tag|

View File

@ -148,13 +148,11 @@ class SystemCommand
break if readable_sources.empty?
readable_sources.each do |source|
begin
line = source.readline_nonblock || ""
type = (source == sources[0]) ? :stdout : :stderr
yield(type, line)
rescue IO::WaitReadable, EOFError
next
end
line = source.readline_nonblock || ""
type = (source == sources[0]) ? :stdout : :stderr
yield(type, line)
rescue IO::WaitReadable, EOFError
next
end
end

View File

@ -199,15 +199,13 @@ shared_examples "#uninstall_phase or #zap_phase" do
let(:cask) { Cask::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-#{directive}")) }
around do |example|
begin
ENV["HOME"] = dir
ENV["HOME"] = dir
FileUtils.touch paths
FileUtils.touch paths
example.run
ensure
FileUtils.rm_f paths
end
example.run
ensure
FileUtils.rm_f paths
end
before do

View File

@ -5,12 +5,10 @@ require_relative "shared_examples/invalid_option"
describe Cask::Cmd::Create, :cask do
around do |example|
begin
example.run
ensure
%w[new-cask additional-cask another-cask yet-another-cask local-caff].each do |cask|
FileUtils.rm_f Cask::CaskLoader.path(cask)
end
example.run
ensure
%w[new-cask additional-cask another-cask yet-another-cask local-caff].each do |cask|
FileUtils.rm_f Cask::CaskLoader.path(cask)
end
end

View File

@ -473,18 +473,16 @@ describe Cask::DSL, :cask do
end
it "does not include a trailing slash" do
begin
original_appdir = Cask::Config.global.appdir
Cask::Config.global.appdir = "#{original_appdir}/"
original_appdir = Cask::Config.global.appdir
Cask::Config.global.appdir = "#{original_appdir}/"
cask = Cask::Cask.new("appdir-trailing-slash") do
binary "#{appdir}/some/path"
end
expect(cask.artifacts.first.source).to eq(original_appdir/"some/path")
ensure
Cask::Config.global.appdir = original_appdir
cask = Cask::Cask.new("appdir-trailing-slash") do
binary "#{appdir}/some/path"
end
expect(cask.artifacts.first.source).to eq(original_appdir/"some/path")
ensure
Cask::Config.global.appdir = original_appdir
end
end

View File

@ -34,15 +34,13 @@ describe Homebrew::Cleanup do
let(:lock_file) { Pathname.new("#{HOMEBREW_LOCKS}/foo") }
around do |example|
begin
FileUtils.touch ds_store
FileUtils.touch lock_file
FileUtils.touch ds_store
FileUtils.touch lock_file
example.run
ensure
FileUtils.rm_f ds_store
FileUtils.rm_f lock_file
end
example.run
ensure
FileUtils.rm_f ds_store
FileUtils.rm_f lock_file
end
describe "::cleanup" do

View File

@ -33,15 +33,13 @@ RSpec.shared_context "custom internal commands" do
end
around do |example|
begin
cmds.each do |f|
FileUtils.touch f
end
example.run
ensure
FileUtils.rm_f cmds
cmds.each do |f|
FileUtils.touch f
end
example.run
ensure
FileUtils.rm_f cmds
end
end

View File

@ -9,17 +9,15 @@ end
describe "brew style" do
around do |example|
begin
FileUtils.ln_s HOMEBREW_LIBRARY_PATH, HOMEBREW_LIBRARY/"Homebrew"
FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop.yml", HOMEBREW_LIBRARY/".rubocop_audit.yml"
FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop_shared.yml", HOMEBREW_LIBRARY/".rubocop_shared.yml"
FileUtils.ln_s HOMEBREW_LIBRARY_PATH, HOMEBREW_LIBRARY/"Homebrew"
FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop.yml", HOMEBREW_LIBRARY/".rubocop_audit.yml"
FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop_shared.yml", HOMEBREW_LIBRARY/".rubocop_shared.yml"
example.run
ensure
FileUtils.rm_f HOMEBREW_LIBRARY/"Homebrew"
FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_audit.yml"
FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_shared.yml"
end
example.run
ensure
FileUtils.rm_f HOMEBREW_LIBRARY/"Homebrew"
FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_audit.yml"
FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_shared.yml"
end
before do

View File

@ -73,20 +73,18 @@ describe Homebrew::Diagnostic::Checks do
end
specify "#check_user_path_3" do
begin
sbin = HOMEBREW_PREFIX/"sbin"
ENV["HOMEBREW_PATH"] =
"#{HOMEBREW_PREFIX}/bin#{File::PATH_SEPARATOR}" +
ENV["HOMEBREW_PATH"].gsub(/(?:^|#{Regexp.escape(File::PATH_SEPARATOR)})#{Regexp.escape(sbin)}/, "")
(sbin/"something").mkpath
sbin = HOMEBREW_PREFIX/"sbin"
ENV["HOMEBREW_PATH"] =
"#{HOMEBREW_PREFIX}/bin#{File::PATH_SEPARATOR}" +
ENV["HOMEBREW_PATH"].gsub(/(?:^|#{Regexp.escape(File::PATH_SEPARATOR)})#{Regexp.escape(sbin)}/, "")
(sbin/"something").mkpath
expect(subject.check_user_path_1).to be nil
expect(subject.check_user_path_2).to be nil
expect(subject.check_user_path_3)
.to match("Homebrew's sbin was not found in your PATH")
ensure
sbin.rmtree
end
expect(subject.check_user_path_1).to be nil
expect(subject.check_user_path_2).to be nil
expect(subject.check_user_path_3)
.to match("Homebrew's sbin was not found in your PATH")
ensure
sbin.rmtree
end
specify "#check_for_config_scripts" do
@ -103,18 +101,16 @@ describe Homebrew::Diagnostic::Checks do
end
specify "#check_for_symlinked_cellar" do
begin
HOMEBREW_CELLAR.rmtree
HOMEBREW_CELLAR.rmtree
mktmpdir do |path|
FileUtils.ln_s path, HOMEBREW_CELLAR
mktmpdir do |path|
FileUtils.ln_s path, HOMEBREW_CELLAR
expect(subject.check_for_symlinked_cellar).to match(path)
end
ensure
HOMEBREW_CELLAR.unlink
HOMEBREW_CELLAR.mkpath
expect(subject.check_for_symlinked_cellar).to match(path)
end
ensure
HOMEBREW_CELLAR.unlink
HOMEBREW_CELLAR.mkpath
end
specify "#check_ld_vars catches LD vars" do

View File

@ -1266,42 +1266,40 @@ describe Formula do
let(:testball_repo) { HOMEBREW_PREFIX/"testball_repo" }
example do
begin
outdated_stable_prefix = HOMEBREW_CELLAR/"testball/1.0"
head_prefix_a = HOMEBREW_CELLAR/"testball/HEAD"
head_prefix_b = HOMEBREW_CELLAR/"testball/HEAD-aaaaaaa_1"
head_prefix_c = HOMEBREW_CELLAR/"testball/HEAD-18a7103"
outdated_stable_prefix = HOMEBREW_CELLAR/"testball/1.0"
head_prefix_a = HOMEBREW_CELLAR/"testball/HEAD"
head_prefix_b = HOMEBREW_CELLAR/"testball/HEAD-aaaaaaa_1"
head_prefix_c = HOMEBREW_CELLAR/"testball/HEAD-18a7103"
setup_tab_for_prefix(outdated_stable_prefix)
tab_a = setup_tab_for_prefix(head_prefix_a, versions: { "stable" => "1.0" })
setup_tab_for_prefix(head_prefix_b)
setup_tab_for_prefix(outdated_stable_prefix)
tab_a = setup_tab_for_prefix(head_prefix_a, versions: { "stable" => "1.0" })
setup_tab_for_prefix(head_prefix_b)
testball_repo.mkdir
testball_repo.cd do
FileUtils.touch "LICENSE"
testball_repo.mkdir
testball_repo.cd do
FileUtils.touch "LICENSE"
system("git", "init")
system("git", "add", "--all")
system("git", "commit", "-m", "Initial commit")
end
expect(f.outdated_kegs(fetch_head: true)).not_to be_empty
tab_a.source["versions"] = { "stable" => f.version.to_s }
tab_a.write
reset_outdated_kegs
expect(f.outdated_kegs(fetch_head: true)).not_to be_empty
head_prefix_a.rmtree
reset_outdated_kegs
expect(f.outdated_kegs(fetch_head: true)).not_to be_empty
setup_tab_for_prefix(head_prefix_c, source_modified_time: 1)
reset_outdated_kegs
expect(f.outdated_kegs(fetch_head: true)).to be_empty
ensure
testball_repo.rmtree if testball_repo.exist?
system("git", "init")
system("git", "add", "--all")
system("git", "commit", "-m", "Initial commit")
end
expect(f.outdated_kegs(fetch_head: true)).not_to be_empty
tab_a.source["versions"] = { "stable" => f.version.to_s }
tab_a.write
reset_outdated_kegs
expect(f.outdated_kegs(fetch_head: true)).not_to be_empty
head_prefix_a.rmtree
reset_outdated_kegs
expect(f.outdated_kegs(fetch_head: true)).not_to be_empty
setup_tab_for_prefix(head_prefix_c, source_modified_time: 1)
reset_outdated_kegs
expect(f.outdated_kegs(fetch_head: true)).to be_empty
ensure
testball_repo.rmtree if testball_repo.exist?
end
end

View File

@ -217,11 +217,9 @@ RSpec::Matchers.alias_matcher :a_string_containing, :include
RSpec::Matchers.define :a_json_string do
match do |actual|
begin
JSON.parse(actual)
true
rescue JSON::ParserError
false
end
JSON.parse(actual)
true
rescue JSON::ParserError
false
end
end

View File

@ -66,10 +66,8 @@ end
RSpec.configure do |config|
config.after do
begin
FakeSystemCommand.verify_expectations!
ensure
FakeSystemCommand.clear
end
FakeSystemCommand.verify_expectations!
ensure
FakeSystemCommand.clear
end
end

View File

@ -41,14 +41,12 @@ RSpec.shared_context "integration test" do
end
around do |example|
begin
(HOMEBREW_PREFIX/"bin").mkpath
FileUtils.touch HOMEBREW_PREFIX/"bin/brew"
(HOMEBREW_PREFIX/"bin").mkpath
FileUtils.touch HOMEBREW_PREFIX/"bin/brew"
example.run
ensure
FileUtils.rm_r HOMEBREW_PREFIX/"bin"
end
example.run
ensure
FileUtils.rm_r HOMEBREW_PREFIX/"bin"
end
# Generate unique ID to be able to
@ -94,11 +92,9 @@ RSpec.shared_context "integration test" do
simplecov_spec = Gem.loaded_specs["simplecov"]
specs = [simplecov_spec]
simplecov_spec.runtime_dependencies.each do |dep|
begin
specs += dep.to_specs
rescue Gem::LoadError => e
onoe e
end
specs += dep.to_specs
rescue Gem::LoadError => e
onoe e
end
libs = specs.flat_map do |spec|
full_gem_path = spec.full_gem_path

View File

@ -267,14 +267,12 @@ describe SystemCommand do
it "does not leak the secrets set by environment" do
redacted_msg = /#{Regexp.escape("username:******")}/
expect do
begin
ENV["PASSWORD"] = "hunter2"
described_class.run! "curl",
args: %w[--user username:hunter2],
verbose: true
ensure
ENV.delete "PASSWORD"
end
ENV["PASSWORD"] = "hunter2"
described_class.run! "curl",
args: %w[--user username:hunter2],
verbose: true
ensure
ENV.delete "PASSWORD"
end.to raise_error.with_message(redacted_msg).and output(redacted_msg).to_stdout
end
end

View File

@ -61,27 +61,25 @@ describe Tap do
end
specify "::fetch" do
begin
expect(described_class.fetch("Homebrew", "core")).to be_kind_of(CoreTap)
expect(described_class.fetch("Homebrew", "homebrew")).to be_kind_of(CoreTap)
tap = described_class.fetch("Homebrew", "foo")
expect(tap).to be_kind_of(described_class)
expect(tap.name).to eq("homebrew/foo")
expect(described_class.fetch("Homebrew", "core")).to be_kind_of(CoreTap)
expect(described_class.fetch("Homebrew", "homebrew")).to be_kind_of(CoreTap)
tap = described_class.fetch("Homebrew", "foo")
expect(tap).to be_kind_of(described_class)
expect(tap.name).to eq("homebrew/foo")
expect {
described_class.fetch("foo")
}.to raise_error(/Invalid tap name/)
expect {
described_class.fetch("foo")
}.to raise_error(/Invalid tap name/)
expect {
described_class.fetch("homebrew/homebrew/bar")
}.to raise_error(/Invalid tap name/)
expect {
described_class.fetch("homebrew/homebrew/bar")
}.to raise_error(/Invalid tap name/)
expect {
described_class.fetch("homebrew", "homebrew/baz")
}.to raise_error(/Invalid tap name/)
ensure
described_class.clear_cache
end
expect {
described_class.fetch("homebrew", "homebrew/baz")
}.to raise_error(/Invalid tap name/)
ensure
described_class.clear_cache
end
describe "::from_path" do
@ -113,23 +111,21 @@ describe Tap do
end
specify "#issues_url" do
begin
t = described_class.new("someone", "foo")
path = Tap::TAP_DIRECTORY/"someone/homebrew-foo"
path.mkpath
cd path do
system "git", "init"
system "git", "remote", "add", "origin",
"https://github.com/someone/homebrew-foo"
end
expect(t.issues_url).to eq("https://github.com/someone/homebrew-foo/issues")
expect(subject.issues_url).to eq("https://github.com/Homebrew/homebrew-foo/issues")
(Tap::TAP_DIRECTORY/"someone/homebrew-no-git").mkpath
expect(described_class.new("someone", "no-git").issues_url).to be nil
ensure
path.parent.rmtree
t = described_class.new("someone", "foo")
path = Tap::TAP_DIRECTORY/"someone/homebrew-foo"
path.mkpath
cd path do
system "git", "init"
system "git", "remote", "add", "origin",
"https://github.com/someone/homebrew-foo"
end
expect(t.issues_url).to eq("https://github.com/someone/homebrew-foo/issues")
expect(subject.issues_url).to eq("https://github.com/Homebrew/homebrew-foo/issues")
(Tap::TAP_DIRECTORY/"someone/homebrew-no-git").mkpath
expect(described_class.new("someone", "no-git").issues_url).to be nil
ensure
path.parent.rmtree
end
specify "files" do
@ -272,53 +268,49 @@ describe Tap do
end
specify "#install and #uninstall" do
begin
setup_tap_files
setup_git_repo
setup_tap_files
setup_git_repo
tap = described_class.new("Homebrew", "bar")
tap = described_class.new("Homebrew", "bar")
tap.install clone_target: subject.path/".git"
tap.install clone_target: subject.path/".git"
expect(tap).to be_installed
expect(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").to be_a_file
expect(HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").to be_a_file
expect(HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").to be_a_file
expect(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").to be_a_file
tap.uninstall
expect(tap).to be_installed
expect(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").to be_a_file
expect(HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").to be_a_file
expect(HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").to be_a_file
expect(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").to be_a_file
tap.uninstall
expect(tap).not_to be_installed
expect(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").not_to exist
expect(HOMEBREW_PREFIX/"share/man/man1").not_to exist
expect(HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").not_to exist
expect(HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").not_to exist
expect(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").not_to exist
ensure
(HOMEBREW_PREFIX/"etc").rmtree if (HOMEBREW_PREFIX/"etc").exist?
(HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist?
end
expect(tap).not_to be_installed
expect(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").not_to exist
expect(HOMEBREW_PREFIX/"share/man/man1").not_to exist
expect(HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").not_to exist
expect(HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").not_to exist
expect(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").not_to exist
ensure
(HOMEBREW_PREFIX/"etc").rmtree if (HOMEBREW_PREFIX/"etc").exist?
(HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist?
end
specify "#link_completions_and_manpages" do
begin
setup_tap_files
setup_git_repo
tap = described_class.new("Homebrew", "baz")
tap.install clone_target: subject.path/".git"
(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").delete
(HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").delete
(HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").delete
(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").delete
tap.link_completions_and_manpages
expect(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").to be_a_file
expect(HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").to be_a_file
expect(HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").to be_a_file
expect(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").to be_a_file
tap.uninstall
ensure
(HOMEBREW_PREFIX/"etc").rmtree if (HOMEBREW_PREFIX/"etc").exist?
(HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist?
end
setup_tap_files
setup_git_repo
tap = described_class.new("Homebrew", "baz")
tap.install clone_target: subject.path/".git"
(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").delete
(HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").delete
(HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").delete
(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").delete
tap.link_completions_and_manpages
expect(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").to be_a_file
expect(HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").to be_a_file
expect(HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").to be_a_file
expect(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").to be_a_file
tap.uninstall
ensure
(HOMEBREW_PREFIX/"etc").rmtree if (HOMEBREW_PREFIX/"etc").exist?
(HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist?
end
specify "#pin and #unpin" do

View File

@ -50,13 +50,11 @@ module Homebrew
method = instance_method(name)
define_method(name) do |*args, &block|
begin
time = Time.now
method.bind(self).call(*args, &block)
ensure
$times[name] ||= 0
$times[name] += Time.now - time
end
time = Time.now
method.bind(self).call(*args, &block)
ensure
$times[name] ||= 0
$times[name] += Time.now - time
end
end
end
@ -388,11 +386,9 @@ module Kernel
def paths
@paths ||= PATH.new(ENV["HOMEBREW_PATH"]).map do |p|
begin
File.expand_path(p).chomp("/")
rescue ArgumentError
onoe "The following PATH component is invalid: #{p}"
end
File.expand_path(p).chomp("/")
rescue ArgumentError
onoe "The following PATH component is invalid: #{p}"
end.uniq.compact
end

View File

@ -32,31 +32,29 @@ module Utils
read, write = IO.pipe
pid = fork do
begin
ENV["HOMEBREW_ERROR_PIPE"] = server.path
server.close
read.close
write.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
yield
rescue Exception => e # rubocop:disable Lint/RescueException
error_hash = JSON.parse e.to_json
ENV["HOMEBREW_ERROR_PIPE"] = server.path
server.close
read.close
write.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
yield
rescue Exception => e # rubocop:disable Lint/RescueException
error_hash = JSON.parse e.to_json
# Special case: We need to recreate ErrorDuringExecutions
# for proper error messages and because other code expects
# to rescue them further down.
if e.is_a?(ErrorDuringExecution)
error_hash["cmd"] = e.cmd
error_hash["status"] = e.status.exitstatus
error_hash["output"] = e.output
end
write.puts error_hash.to_json
write.close
exit!
else
exit!(true)
# Special case: We need to recreate ErrorDuringExecutions
# for proper error messages and because other code expects
# to rescue them further down.
if e.is_a?(ErrorDuringExecution)
error_hash["cmd"] = e.cmd
error_hash["status"] = e.status.exitstatus
error_hash["output"] = e.output
end
write.puts error_hash.to_json
write.close
exit!
else
exit!(true)
end
ignore_interrupts(:quietly) do # the child will receive the interrupt and marshal it back