diff options
Diffstat (limited to 'Library/Homebrew')
34 files changed, 231 insertions, 104 deletions
diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 86b40a79d..8c5386612 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -9,7 +9,7 @@ RUBY_VERSION_SPLIT = RUBY_VERSION.split "." RUBY_X = RUBY_VERSION_SPLIT[0].to_i RUBY_Y = RUBY_VERSION_SPLIT[1].to_i if RUBY_X < 2 || (RUBY_X == 2 && RUBY_Y < 3) - raise "Homebrew must be run under Ruby 2.3!" + raise "Homebrew must be run under Ruby 2.3! You're running #{RUBY_VERSION}." end require "pathname" diff --git a/Library/Homebrew/cask/lib/hbc/cli/edit.rb b/Library/Homebrew/cask/lib/hbc/cli/edit.rb index 8bce81c52..693edcd51 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/edit.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/edit.rb @@ -8,9 +8,6 @@ module Hbc end def run - cask = casks.first - cask_path = cask.sourcefile_path - odebug "Opening editor for Cask #{cask.token}" exec_editor cask_path rescue CaskUnavailableError => e reason = e.reason.empty? ? "" : "#{e.reason} " @@ -18,6 +15,14 @@ module Hbc raise e.class.new(e.token, reason) end + def cask_path + casks.first.sourcefile_path + rescue CaskInvalidError + path = CaskLoader.path(args.first) + return path if path.file? + raise + end + def self.help "edits the given Cask" end diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index 1849ea79b..ef8028339 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -161,49 +161,7 @@ class Caveats EOS end - def plist_caveats - s = [] - if f.plist || (keg&.plist_installed?) - plist_domain = f.plist_path.basename(".plist") - - # we readlink because this path probably doesn't exist since caveats - # occurs before the link step of installation - # Yosemite security measures mildly tighter rules: - # https://github.com/Homebrew/legacy-homebrew/issues/33815 - if !plist_path.file? || !plist_path.symlink? - if f.plist_startup - s << "To have launchd start #{f.full_name} now and restart at startup:" - s << " sudo brew services start #{f.full_name}" - else - s << "To have launchd start #{f.full_name} now and restart at login:" - s << " brew services start #{f.full_name}" - end - # For startup plists, we cannot tell whether it's running on launchd, - # as it requires for `sudo launchctl list` to get real result. - elsif f.plist_startup - s << "To restart #{f.full_name} after an upgrade:" - s << " sudo brew services restart #{f.full_name}" - elsif Kernel.system "/bin/launchctl list #{plist_domain} &>/dev/null" - s << "To restart #{f.full_name} after an upgrade:" - s << " brew services restart #{f.full_name}" - else - s << "To start #{f.full_name}:" - s << " brew services start #{f.full_name}" - end - - if f.plist_manual - s << "Or, if you don't want/need a background service you can just run:" - s << " #{f.plist_manual}" - end - - # pbpaste is the system clipboard tool on macOS and fails with `tmux` by default - # check if this is being run under `tmux` to avoid failing - if ENV["TMUX"] && !quiet_system("/usr/bin/pbpaste") - s << "" << "WARNING: brew services will fail when run under tmux." - end - end - s.join("\n") + "\n" unless s.empty? - end + def plist_caveats; end def plist_path destination = if f.plist_startup @@ -222,3 +180,5 @@ class Caveats destination_path/plist_filename end end + +require "extend/os/caveats" diff --git a/Library/Homebrew/cmd/commands.rb b/Library/Homebrew/cmd/commands.rb index addccd609..a3527bc94 100644 --- a/Library/Homebrew/cmd/commands.rb +++ b/Library/Homebrew/cmd/commands.rb @@ -16,12 +16,12 @@ module Homebrew else # Find commands in Homebrew/cmd puts "Built-in commands" - puts Formatter.columns(internal_commands) + puts Formatter.columns(internal_commands.sort) # Find commands in Homebrew/dev-cmd puts puts "Built-in developer commands" - puts Formatter.columns(internal_developer_commands) + puts Formatter.columns(internal_developer_commands.sort) # Find commands in the path unless (exts = external_commands).empty? diff --git a/Library/Homebrew/cmd/deps.rb b/Library/Homebrew/cmd/deps.rb index de7aa4a51..ae758e143 100644 --- a/Library/Homebrew/cmd/deps.rb +++ b/Library/Homebrew/cmd/deps.rb @@ -68,16 +68,16 @@ module Homebrew if mode.tree? if mode.installed? - puts_deps_tree Formula.installed, !ARGV.one? + puts_deps_tree Formula.installed.sort, !ARGV.one? else raise FormulaUnspecifiedError if ARGV.named.empty? puts_deps_tree ARGV.formulae, !ARGV.one? end elsif mode.all? - puts_deps Formula + puts_deps Formula.sort elsif ARGV.named.empty? raise FormulaUnspecifiedError unless mode.installed? - puts_deps Formula.installed + puts_deps Formula.installed.sort elsif mode.for_each? puts_deps ARGV.formulae else diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 5eb033706..6ee24a7fa 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -67,9 +67,9 @@ module Homebrew def print_json ff = if ARGV.include? "--all" - Formula + Formula.sort elsif ARGV.include? "--installed" - Formula.installed + Formula.installed.sort else ARGV.formulae end diff --git a/Library/Homebrew/cmd/leaves.rb b/Library/Homebrew/cmd/leaves.rb index 4038aee4c..574ceb64e 100644 --- a/Library/Homebrew/cmd/leaves.rb +++ b/Library/Homebrew/cmd/leaves.rb @@ -9,7 +9,7 @@ module Homebrew module_function def leaves - installed = Formula.installed + installed = Formula.installed.sort deps_of_installed = Set.new installed.each do |f| diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index 436fc1f97..263f33564 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -87,7 +87,7 @@ module Homebrew dirs.delete "etc" dirs.delete "var" - args = dirs + %w[-type f (] + args = dirs.sort + %w[-type f (] args.concat UNBREWED_EXCLUDE_FILES.flat_map { |f| %W[! -name #{f}] } args.concat UNBREWED_EXCLUDE_PATHS.flat_map { |d| %W[! -path #{d}] } args.concat %w[)] diff --git a/Library/Homebrew/cmd/missing.rb b/Library/Homebrew/cmd/missing.rb index 8a1dc506d..707ad6834 100644 --- a/Library/Homebrew/cmd/missing.rb +++ b/Library/Homebrew/cmd/missing.rb @@ -16,9 +16,9 @@ module Homebrew return unless HOMEBREW_CELLAR.exist? ff = if ARGV.named.empty? - Formula.installed + Formula.installed.sort else - ARGV.resolved_formulae + ARGV.resolved_formulae.sort end ff.each do |f| diff --git a/Library/Homebrew/cmd/options.rb b/Library/Homebrew/cmd/options.rb index 843d3a1ee..6bb6afafe 100644 --- a/Library/Homebrew/cmd/options.rb +++ b/Library/Homebrew/cmd/options.rb @@ -16,9 +16,9 @@ module Homebrew def options if ARGV.include? "--all" - puts_options Formula.to_a + puts_options Formula.to_a.sort elsif ARGV.include? "--installed" - puts_options Formula.installed + puts_options Formula.installed.sort else raise FormulaUnspecifiedError if ARGV.named.empty? puts_options ARGV.formulae diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index c01a11c10..d0f85a858 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -24,7 +24,7 @@ module Homebrew def search if ARGV.empty? - puts Formatter.columns(Formula.full_names) + puts Formatter.columns(Formula.full_names.sort) elsif ARGV.include? "--macports" exec_browser "https://www.macports.org/ports.php?by=name&substr=#{ARGV.next}" elsif ARGV.include? "--fink" @@ -52,15 +52,15 @@ module Homebrew results = search_taps(name) end - puts Formatter.columns(results) unless results.empty? + puts Formatter.columns(results.sort) unless results.empty? else query = ARGV.first regex = query_regexp(query) local_results = search_formulae(regex) - puts Formatter.columns(local_results) unless local_results.empty? + puts Formatter.columns(local_results.sort) unless local_results.empty? tap_results = search_taps(query) - puts Formatter.columns(tap_results) unless tap_results.empty? + puts Formatter.columns(tap_results.sort) unless tap_results.empty? if $stdout.tty? count = local_results.length + tap_results.length diff --git a/Library/Homebrew/cmd/tap-info.rb b/Library/Homebrew/cmd/tap-info.rb index cb0e0b387..d01ce8a02 100644 --- a/Library/Homebrew/cmd/tap-info.rb +++ b/Library/Homebrew/cmd/tap-info.rb @@ -21,10 +21,11 @@ module Homebrew module_function def tap_info + # TODO: This still returns a non-alphabetised list on APFS. if ARGV.include? "--installed" taps = Tap else - taps = ARGV.named.map do |name| + taps = ARGV.named.sort.map do |name| Tap.fetch(name) end end diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index 0974df0b4..e3d3c10bb 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -598,7 +598,7 @@ class ReporterHub return if formulae.empty? # Dump formula list. ohai title - puts Formatter.columns(formulae) + puts Formatter.columns(formulae.sort) end def installed?(formula) diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb index 0b09e1bf1..1688899f9 100644 --- a/Library/Homebrew/cmd/uses.rb +++ b/Library/Homebrew/cmd/uses.rb @@ -125,7 +125,7 @@ module Homebrew end return if uses.empty? - puts Formatter.columns(uses.map(&:full_name)) + puts Formatter.columns(uses.map(&:full_name).sort) odie "Missing formulae should not have dependents!" if used_formulae_missing end end diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index 88041bdc1..15caca8ef 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -81,9 +81,9 @@ fetch() { trap - SIGINT fi - if [[ -x "$(which shasum)" ]] + if [[ -x "/usr/bin/shasum" ]] then - sha="$(shasum -a 256 "$CACHED_LOCATION" | cut -d' ' -f1)" + sha="$(/usr/bin/shasum -a 256 "$CACHED_LOCATION" | cut -d' ' -f1)" elif [[ -x "$(which sha256sum)" ]] then sha="$(sha256sum "$CACHED_LOCATION" | cut -d' ' -f1)" diff --git a/Library/Homebrew/compat/requirements.rb b/Library/Homebrew/compat/requirements.rb index 77760d1dc..3886cd7c7 100644 --- a/Library/Homebrew/compat/requirements.rb +++ b/Library/Homebrew/compat/requirements.rb @@ -17,3 +17,4 @@ PythonDependency = PythonRequirement TuntapDependency = TuntapRequirement X11Dependency = X11Requirement ConflictsWithBinaryOsxfuse = NonBinaryOsxfuseRequirement +MinimumMacOSRequirement = MacOSRequirement diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb index f855669e0..bc0246dd2 100644 --- a/Library/Homebrew/dependency_collector.rb +++ b/Library/Homebrew/dependency_collector.rb @@ -105,7 +105,8 @@ class DependencyCollector case spec when :x11 then X11Requirement.new(spec.to_s, tags) when :xcode then XcodeRequirement.new(tags) - when :macos then MinimumMacOSRequirement.new(tags) + when :linux then LinuxRequirement.new(tags) + when :macos then MacOSRequirement.new(tags) when :mysql then MysqlRequirement.new(tags) when :postgresql then PostgresqlRequirement.new(tags) when :gpg then GPG2Requirement.new(tags) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 200b2597f..a9d27afa9 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -974,8 +974,12 @@ class FormulaAuditor problem "Use `assert_predicate <path_to_file>, :exist?` instead of `#{Regexp.last_match(1)}`" end - if line =~ /assert !File\.exist\?/ - problem "Use `refute_predicate <path_to_file>, :exist?` instead of `assert !File.exist?`" + if line =~ /(assert !File\.exist\?|assert !\(.*\)\.exist\?)/ + problem "Use `refute_predicate <path_to_file>, :exist?` instead of `#{Regexp.last_match(1)}`" + end + + if line =~ /(assert File\.executable\?|assert \(.*\)\.executable\?)/ + problem "Use `assert_predicate <path_to_file>, :executable?` instead of `#{Regexp.last_match(1)}`" end return unless @strict diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb index 8cb270303..aa3c9a9d7 100644 --- a/Library/Homebrew/dev-cmd/pull.rb +++ b/Library/Homebrew/dev-cmd/pull.rb @@ -560,7 +560,7 @@ module Homebrew req = Net::HTTP::Head.new bottle_info.url req.initialize_http_header "User-Agent" => HOMEBREW_USER_AGENT_RUBY res = http.request req - break if res.is_a?(Net::HTTPSuccess) + break if res.is_a?(Net::HTTPSuccess) || res.code == "302" unless res.is_a?(Net::HTTPClientError) raise "Failed to find published #{f} bottle at #{url} (#{res.code} #{res.message})!" diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 3edf31012..9ab83c1a2 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -787,6 +787,18 @@ module Homebrew git -C "#{coretap_path}" remote set-url origin #{Formatter.url("https://github.com/Homebrew/homebrew-core.git")} EOS end + + return if ENV["CI"] || ENV["JENKINS_HOME"] + + branch = coretap_path.git_branch + return if branch.nil? || branch =~ /master/ + + <<-EOS.undent + Homebrew/homebrew-core is not on the master branch + + Check out the master branch by running: + git -C "$(brew --repo homebrew/core)" checkout master + EOS end def __check_linked_brew(f) @@ -804,7 +816,7 @@ module Homebrew def check_for_linked_keg_only_brews return unless HOMEBREW_CELLAR.exist? - linked = Formula.installed.select do |f| + linked = Formula.installed.sort.select do |f| f.keg_only? && __check_linked_brew(f) end return if linked.empty? diff --git a/Library/Homebrew/extend/git_repository.rb b/Library/Homebrew/extend/git_repository.rb index c15988550..6b89d175c 100644 --- a/Library/Homebrew/extend/git_repository.rb +++ b/Library/Homebrew/extend/git_repository.rb @@ -36,6 +36,15 @@ module GitRepositoryExtension end end + def git_branch + return unless git? && Utils.git_available? + cd do + Utils.popen_read( + "git", "rev-parse", "--abbrev-ref", "HEAD" + ).chuzzle + end + end + def git_last_commit_date return unless git? && Utils.git_available? cd do diff --git a/Library/Homebrew/extend/os/caveats.rb b/Library/Homebrew/extend/os/caveats.rb new file mode 100644 index 000000000..e67138087 --- /dev/null +++ b/Library/Homebrew/extend/os/caveats.rb @@ -0,0 +1 @@ +require "extend/os/mac/caveats" if OS.mac? diff --git a/Library/Homebrew/extend/os/mac/caveats.rb b/Library/Homebrew/extend/os/mac/caveats.rb new file mode 100644 index 000000000..d912a8307 --- /dev/null +++ b/Library/Homebrew/extend/os/mac/caveats.rb @@ -0,0 +1,45 @@ +class Caveats + def plist_caveats + s = [] + if f.plist || (keg&.plist_installed?) + plist_domain = f.plist_path.basename(".plist") + + # we readlink because this path probably doesn't exist since caveats + # occurs before the link step of installation + # Yosemite security measures mildly tighter rules: + # https://github.com/Homebrew/legacy-homebrew/issues/33815 + if !plist_path.file? || !plist_path.symlink? + if f.plist_startup + s << "To have launchd start #{f.full_name} now and restart at startup:" + s << " sudo brew services start #{f.full_name}" + else + s << "To have launchd start #{f.full_name} now and restart at login:" + s << " brew services start #{f.full_name}" + end + # For startup plists, we cannot tell whether it's running on launchd, + # as it requires for `sudo launchctl list` to get real result. + elsif f.plist_startup + s << "To restart #{f.full_name} after an upgrade:" + s << " sudo brew services restart #{f.full_name}" + elsif Kernel.system "/bin/launchctl list #{plist_domain} &>/dev/null" + s << "To restart #{f.full_name} after an upgrade:" + s << " brew services restart #{f.full_name}" + else + s << "To start #{f.full_name}:" + s << " brew services start #{f.full_name}" + end + + if f.plist_manual + s << "Or, if you don't want/need a background service you can just run:" + s << " #{f.plist_manual}" + end + + # pbpaste is the system clipboard tool on macOS and fails with `tmux` by default + # check if this is being run under `tmux` to avoid failing + if ENV["TMUX"] && !quiet_system("/usr/bin/pbpaste") + s << "" << "WARNING: brew services will fail when run under tmux." + end + end + s.join("\n") + "\n" unless s.empty? + end +end diff --git a/Library/Homebrew/requirements.rb b/Library/Homebrew/requirements.rb index 553beb2a2..bac7d5790 100644 --- a/Library/Homebrew/requirements.rb +++ b/Library/Homebrew/requirements.rb @@ -2,7 +2,8 @@ require "requirement" require "requirements/fortran_requirement" require "requirements/gpg2_requirement" require "requirements/language_module_requirement" -require "requirements/minimum_macos_requirement" +require "requirements/linux_requirement" +require "requirements/macos_requirement" require "requirements/maximum_macos_requirement" require "requirements/mpi_requirement" require "requirements/osxfuse_requirement" diff --git a/Library/Homebrew/requirements/java_requirement.rb b/Library/Homebrew/requirements/java_requirement.rb index de3a33eb4..949978dbd 100644 --- a/Library/Homebrew/requirements/java_requirement.rb +++ b/Library/Homebrew/requirements/java_requirement.rb @@ -11,7 +11,7 @@ class JavaRequirement < Requirement end def initialize(tags) - @version = tags.shift if /(\d\.)+\d/ =~ tags.first + @version = tags.shift if /(\d+\.)+\d/ =~ tags.first super end @@ -103,7 +103,7 @@ class JavaRequirement < Requirement end def satisfies_version(java) - java_version_s = Utils.popen_read("#{java} -version 2>&1")[/1.\d/] + java_version_s = Utils.popen_read("#{java} -version 2>&1")[/\d+.\d/] return false unless java_version_s java_version = Version.create(java_version_s) needed_version = Version.create(version_without_plus) diff --git a/Library/Homebrew/requirements/linux_requirement.rb b/Library/Homebrew/requirements/linux_requirement.rb new file mode 100644 index 000000000..cb4666e56 --- /dev/null +++ b/Library/Homebrew/requirements/linux_requirement.rb @@ -0,0 +1,9 @@ +class LinuxRequirement < Requirement + fatal true + + satisfy(build_env: false) { OS.linux? } + + def message + "Linux is required." + end +end diff --git a/Library/Homebrew/requirements/macos_requirement.rb b/Library/Homebrew/requirements/macos_requirement.rb new file mode 100644 index 000000000..c89144d2c --- /dev/null +++ b/Library/Homebrew/requirements/macos_requirement.rb @@ -0,0 +1,31 @@ +require "requirement" + +class MacOSRequirement < Requirement + fatal true + + def initialize(tags = []) + @version = MacOS::Version.from_symbol(tags.first) unless tags.empty? + super + end + + def minimum_version_specified? + OS.mac? && @version + end + + satisfy(build_env: false) do + next MacOS.version >= @version if minimum_version_specified? + next true if OS.mac? + next true if @version + false + end + + def message + return "macOS is required." unless minimum_version_specified? + "macOS #{@version.pretty_name} or newer is required." + end + + def display_s + return "macOS is required" unless minimum_version_specified? + "macOS >= #{@version}" + end +end diff --git a/Library/Homebrew/requirements/minimum_macos_requirement.rb b/Library/Homebrew/requirements/minimum_macos_requirement.rb deleted file mode 100644 index 2cb63f740..000000000 --- a/Library/Homebrew/requirements/minimum_macos_requirement.rb +++ /dev/null @@ -1,20 +0,0 @@ -require "requirement" - -class MinimumMacOSRequirement < Requirement - fatal true - - def initialize(tags) - @version = MacOS::Version.from_symbol(tags.first) - super - end - - satisfy(build_env: false) { MacOS.version >= @version } - - def message - "macOS #{@version.pretty_name} or newer is required." - end - - def display_s - "macOS >= #{@version}" - end -end diff --git a/Library/Homebrew/rubocops/formula_desc_cop.rb b/Library/Homebrew/rubocops/formula_desc_cop.rb index 2b613c9b4..2ef60303d 100644 --- a/Library/Homebrew/rubocops/formula_desc_cop.rb +++ b/Library/Homebrew/rubocops/formula_desc_cop.rb @@ -18,8 +18,14 @@ module RuboCop return end - # Check if a formula's desc is too long + # Check the formula's desc length. Should be >0 and <80 characters. desc = parameters(desc_call).first + pure_desc_length = string_content(desc).length + if pure_desc_length.zero? + problem "The desc (description) should not be an empty string." + return + end + desc_length = "#{@formula_name}: #{string_content(desc)}".length max_desc_length = 80 return if desc_length <= max_desc_length diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb index 01b13585c..a45f673c6 100644 --- a/Library/Homebrew/rubocops/lines_cop.rb +++ b/Library/Homebrew/rubocops/lines_cop.rb @@ -121,6 +121,7 @@ module RuboCop end find_instance_method_call(body_node, "ENV", :universal_binary) do + next if @formula_name == "wine" problem "macOS has been 64-bit only since 10.6 so ENV.universal_binary is deprecated." end diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 78dc4cf4e..c12c121e4 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -115,6 +115,12 @@ class Tap path.git? end + # git branch for this {Tap}. + def git_branch + raise TapUnavailableError, name unless installed? + path.git_branch + end + # git HEAD for this {Tap}. def git_head raise TapUnavailableError, name unless installed? @@ -494,7 +500,7 @@ class Tap # an array of all installed {Tap} names. def self.names - map(&:name) + map(&:name).sort end # @private diff --git a/Library/Homebrew/test/os_requirement_spec.rb b/Library/Homebrew/test/os_requirement_spec.rb new file mode 100644 index 000000000..87f86231c --- /dev/null +++ b/Library/Homebrew/test/os_requirement_spec.rb @@ -0,0 +1,18 @@ +require "requirements/linux_requirement" +require "requirements/macos_requirement" + +describe LinuxRequirement do + describe "#satisfied?" do + it "returns true if OS is Linux" do + expect(subject.satisfied?).to eq(OS.linux?) + end + end +end + +describe MacOSRequirement do + describe "#satisfied?" do + it "returns true if OS is macOS" do + expect(subject.satisfied?).to eq(OS.mac?) + end + end +end diff --git a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb index ac8893e18..4816c3b26 100644 --- a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb @@ -27,6 +27,27 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do end end + it "reports an offense when desc is an empty string" do + source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + desc '' + end + EOS + + msg = "The desc (description) should not be an empty string." + expected_offenses = [{ message: msg, + severity: :convention, + line: 3, + column: 2, + source: source }] + + inspect_source(source, "/homebrew-core/Formula/foo.rb") + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + it "When desc is too long" do source = <<-EOS.undent class Foo < Formula diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 753439c8e..af816a5a9 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -82,7 +82,7 @@ end describe RuboCop::Cop::FormulaAudit::Comments do subject(:cop) { described_class.new } - context "When auditing formula" do + context "When auditing formulae" do it "with commented cmake call" do source = <<-EOS.undent class Foo < Formula @@ -154,7 +154,7 @@ end describe RuboCop::Cop::FormulaAudit::Miscellaneous do subject(:cop) { described_class.new } - context "When auditing formula" do + context "When auditing formulae" do it "with FileUtils" do source = <<-EOS.undent class Foo < Formula @@ -380,7 +380,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with build.universal? exempted formula" do + it "with a build.universal? exemption reports no offenses" do source = <<-EOS.undent class Wine < Formula desc "foo" @@ -392,7 +392,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do EOS inspect_source(source, "/homebrew-core/Formula/wine.rb") - expect(cop.offenses).to eq([]) + expect(cop.offenses).to be_empty end it "with ENV.universal_binary" do @@ -419,7 +419,22 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with ENV.universal_binary" do + it "with an ENV.universal_binary exemption reports no offenses" do + source = <<-EOS.undent + class Wine < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + if build? + ENV.universal_binary + end + end + EOS + + inspect_source(source, "/homebrew-core/Formula/wine.rb") + expect(cop.offenses).to be_empty + end + + it "with ENV.x11" do source = <<-EOS.undent class Foo < Formula desc "foo" |
