From a1748605abd02e6057c38778275a6217e0290c79 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Tue, 14 Mar 2023 10:23:29 -0700 Subject: [PATCH 1/2] Minor Kernel cleanup --- Library/Homebrew/extend/kernel.rb | 21 --------------------- Library/Homebrew/test/extend/kernel_spec.rb | 13 ------------- Library/Homebrew/test/utils_spec.rb | 13 +++++++++++++ Library/Homebrew/utils.rb | 12 ++++++++++++ 4 files changed, 25 insertions(+), 34 deletions(-) diff --git a/Library/Homebrew/extend/kernel.rb b/Library/Homebrew/extend/kernel.rb index c9500c28f6..635eb9530d 100644 --- a/Library/Homebrew/extend/kernel.rb +++ b/Library/Homebrew/extend/kernel.rb @@ -351,16 +351,6 @@ module Kernel # rubocop:enable Style/GlobalVars end - sig { returns(String) } - def capture_stderr - old = $stderr - $stderr = StringIO.new - yield - $stderr.string - ensure - $stderr = old - end - def redirect_stdout(file) out = $stdout.dup $stdout.reopen(file) @@ -428,17 +418,6 @@ module Kernel @paths ||= ORIGINAL_PATHS.uniq.map(&:to_s) end - def parse_author!(author) - match_data = /^(?[^<]+?)[ \t]*<(?[^>]+?)>$/.match(author) - if match_data - name = match_data[:name] - email = match_data[:email] - end - raise UsageError, "Unable to parse name and email." if name.blank? && email.blank? - - { name: name, email: email } - end - def disk_usage_readable(size_in_bytes) if size_in_bytes >= 1_073_741_824 size = size_in_bytes.to_f / 1_073_741_824 diff --git a/Library/Homebrew/test/extend/kernel_spec.rb b/Library/Homebrew/test/extend/kernel_spec.rb index 083d7fcf91..0864e50e0e 100644 --- a/Library/Homebrew/test/extend/kernel_spec.rb +++ b/Library/Homebrew/test/extend/kernel_spec.rb @@ -200,19 +200,6 @@ describe "globally-scoped helper methods" do end end - specify "#parse_author!" do - parse_error_msg = /Unable to parse name and email/ - - expect(parse_author!("John Doe ")) - .to eq({ name: "John Doe", email: "john.doe@example.com" }) - expect { parse_author!("") } - .to raise_error(parse_error_msg) - expect { parse_author!("John Doe") } - .to raise_error(parse_error_msg) - expect { parse_author!("") } - .to raise_error(parse_error_msg) - end - specify "#disk_usage_readable" do expect(disk_usage_readable(1)).to eq("1B") expect(disk_usage_readable(1000)).to eq("1000B") diff --git a/Library/Homebrew/test/utils_spec.rb b/Library/Homebrew/test/utils_spec.rb index 9555f1622f..8b9b5e89e8 100644 --- a/Library/Homebrew/test/utils_spec.rb +++ b/Library/Homebrew/test/utils_spec.rb @@ -33,6 +33,19 @@ describe Utils do end end + specify ".parse_author!" do + parse_error_msg = /Unable to parse name and email/ + + expect(described_class.parse_author!("John Doe ")) + .to eq({ name: "John Doe", email: "john.doe@example.com" }) + expect { described_class.parse_author!("") } + .to raise_error(parse_error_msg) + expect { described_class.parse_author!("John Doe") } + .to raise_error(parse_error_msg) + expect { described_class.parse_author!("") } + .to raise_error(parse_error_msg) + end + describe ".pluralize" do it "combines the stem with the default suffix based on the count" do expect(described_class.pluralize("foo", 0)).to eq("foos") diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 6eb651979d..a0bf5fdcec 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -132,6 +132,18 @@ module Utils "#{stem}#{suffix}" end + sig { params(author: String).returns({ email: String, name: String }) } + def self.parse_author!(author) + match_data = /^(?[^<]+?)[ \t]*<(?[^>]+?)>$/.match(author) + if match_data + name = match_data[:name] + email = match_data[:email] + end + raise UsageError, "Unable to parse name and email." if name.blank? && email.blank? + + { name: T.must(name), email: T.must(email) } + end + # Makes an underscored, lowercase form from the expression in the string. # # Changes '::' to '/' to convert namespaces to paths. From 6238a0779d68a2277f8a952f525c3dad8951efa2 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Tue, 14 Mar 2023 11:46:38 -0700 Subject: [PATCH 2/2] remove test --- Library/Homebrew/test/extend/kernel_spec.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Library/Homebrew/test/extend/kernel_spec.rb b/Library/Homebrew/test/extend/kernel_spec.rb index 0864e50e0e..bcd63aed12 100644 --- a/Library/Homebrew/test/extend/kernel_spec.rb +++ b/Library/Homebrew/test/extend/kernel_spec.rb @@ -182,14 +182,6 @@ describe "globally-scoped helper methods" do expect(which_editor).to eq("vemate -w") end - specify "#capture_stderr" do - err = capture_stderr do - $stderr.print "test" - end - - expect(err).to eq("test") - end - describe "#pretty_duration" do it "converts seconds to a human-readable string" do expect(pretty_duration(1)).to eq("1 second")