From 9c914106ed9adc47a649a77332cdda57ab89fbbb Mon Sep 17 00:00:00 2001
From: nandahkrishna <nanda.harishankar@gmail.com>
Date: Mon, 25 Jan 2021 17:12:43 +0530
Subject: [PATCH] dev-cmd/bump: increase test coverage

---
 Library/Homebrew/dev-cmd/bump.rb           | 34 +++++++++-------------
 Library/Homebrew/test/dev-cmd/bump_spec.rb | 14 +++++++++
 2 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/Library/Homebrew/dev-cmd/bump.rb b/Library/Homebrew/dev-cmd/bump.rb
index 18f9fb2d18..f9ee8b6ff8 100644
--- a/Library/Homebrew/dev-cmd/bump.rb
+++ b/Library/Homebrew/dev-cmd/bump.rb
@@ -41,18 +41,8 @@ module Homebrew
           next
         end
 
-        current_version = formula.stable.version.to_s
-
         package_data = Repology.single_package_query(formula.name)
-        repology_latest = if package_data.present?
-          Repology.latest_version(package_data.values.first)
-        else
-          "not found"
-        end
-
-        livecheck_latest = livecheck_result(formula)
-        pull_requests = retrieve_pull_requests(formula)
-        display(formula, current_version, repology_latest, livecheck_latest, pull_requests)
+        retrieve_and_display_info(formula, package_data&.values&.first)
       end
     else
       outdated_packages = Repology.parse_api_response(requested_limit)
@@ -71,11 +61,7 @@ module Homebrew
           next
         end
 
-        current_version = formula.stable.version.to_s
-        repology_latest = Repology.latest_version(repositories)
-        livecheck_latest = livecheck_result(formula)
-        pull_requests = retrieve_pull_requests(formula)
-        display(formula, current_version, repology_latest, livecheck_latest, pull_requests)
+        retrieve_and_display_info(formula, repositories)
 
         break if requested_limit && i >= requested_limit
       end
@@ -110,12 +96,18 @@ module Homebrew
     pull_requests
   end
 
-  def up_to_date?(current_version, repology_latest, livecheck_latest)
-    current_version == repology_latest &&
-      current_version == livecheck_latest
-  end
+  def retrieve_and_display_info(formula, repositories)
+    current_version = formula.stable.version.to_s
+
+    repology_latest = if repositories.present?
+      Repology.latest_version(repositories)
+    else
+      "not found"
+    end
+
+    livecheck_latest = livecheck_result(formula)
+    pull_requests = retrieve_pull_requests(formula)
 
-  def display(formula, current_version, repology_latest, livecheck_latest, pull_requests)
     title = if current_version == repology_latest &&
                current_version == livecheck_latest
       "#{formula} is up to date!"
diff --git a/Library/Homebrew/test/dev-cmd/bump_spec.rb b/Library/Homebrew/test/dev-cmd/bump_spec.rb
index e3105920ac..c4265dfe88 100644
--- a/Library/Homebrew/test/dev-cmd/bump_spec.rb
+++ b/Library/Homebrew/test/dev-cmd/bump_spec.rb
@@ -27,5 +27,19 @@ describe "brew bump" do
         .and not_to_output.to_stderr
         .and be_a_success
     end
+
+    it "returns no data and prints a message for HEAD-only formulae" do
+      content = <<~RUBY
+        desc "HEAD-only test formula"
+        homepage "https://brew.sh"
+        head "https://github.com/Homebrew/brew.git"
+      RUBY
+      setup_test_formula("headonly", content)
+
+      expect { brew "bump", "headonly" }
+        .to output(/Formula is HEAD-only./).to_stdout
+        .and not_to_output.to_stderr
+        .and be_a_success
+    end
   end
 end
-- 
GitLab