mirror of
https://github.com/Homebrew/brew.git
synced 2026-08-12 22:29:27 +04:00
Fix formula reporter inconsistencies
This commit is contained in:
@@ -216,7 +216,7 @@ module Homebrew
|
||||
names_path = HOMEBREW_CACHE_API/"#{type}_names.txt"
|
||||
if !names_path.exist? || regenerate
|
||||
names_path.unlink if names_path.exist?
|
||||
names_path.write(names.join("\n"))
|
||||
names_path.write(names.sort.join("\n"))
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -231,7 +231,7 @@ module Homebrew
|
||||
"#{alias_name}|#{real_name}"
|
||||
end
|
||||
aliases_path.unlink if aliases_path.exist?
|
||||
aliases_path.write(aliases_text.join("\n"))
|
||||
aliases_path.write(aliases_text.sort.join("\n"))
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
@@ -785,14 +785,27 @@ class Reporter
|
||||
|
||||
api_dir_prefix_basename = T.must(api_dir_prefix).basename
|
||||
|
||||
diff_output.lines.filter_map do |line|
|
||||
diff_hash = diff_output.lines.each_with_object({}) do |line, hash|
|
||||
next if line.match?(header_regex)
|
||||
next unless add_delete_characters.include?(line[0])
|
||||
|
||||
line.sub(/^\+/, "A #{api_dir_prefix_basename}/")
|
||||
.sub(/^-/, "D #{api_dir_prefix_basename}/")
|
||||
.sub(/$/, ".rb")
|
||||
.chomp
|
||||
name = line.chomp.delete_prefix("+").delete_prefix("-")
|
||||
file = "#{api_dir_prefix_basename}/#{name}.rb"
|
||||
|
||||
hash[file] ||= 0
|
||||
if line.start_with?("+")
|
||||
hash[file] += 1
|
||||
elsif line.start_with?("-")
|
||||
hash[file] -= 1
|
||||
end
|
||||
end
|
||||
|
||||
diff_hash.filter_map do |file, count|
|
||||
if count.positive?
|
||||
"A #{file}"
|
||||
elsif count.negative?
|
||||
"D #{file}"
|
||||
end
|
||||
end.join("\n")
|
||||
else
|
||||
Utils.popen_read(
|
||||
|
||||
@@ -152,6 +152,45 @@ RSpec.describe Homebrew::Cmd::UpdateReport do
|
||||
expect(tap.cask_tokens).to include("new-cask")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#diff" do
|
||||
context "when using the API" do
|
||||
subject(:reporter) do
|
||||
described_class.new(tap,
|
||||
api_names_txt: Pathname("formula_names.txt"),
|
||||
api_names_before_txt: Pathname("formula_names_before.txt"),
|
||||
api_dir_prefix: HOMEBREW_CACHE/"api")
|
||||
end
|
||||
|
||||
it "ignore lines that haven't changed" do
|
||||
expect(Utils).to receive(:popen_read).and_return(<<~DIFF)
|
||||
foo
|
||||
+bar
|
||||
-baz
|
||||
DIFF
|
||||
|
||||
expect(reporter.send(:diff)).to eq(<<~DIFF.strip)
|
||||
A api/bar.rb
|
||||
D api/baz.rb
|
||||
DIFF
|
||||
end
|
||||
|
||||
it "handles moved lines" do
|
||||
expect(Utils).to receive(:popen_read).and_return(<<~DIFF)
|
||||
+baz
|
||||
foo
|
||||
+bar
|
||||
+baz
|
||||
-bar
|
||||
-baz
|
||||
DIFF
|
||||
|
||||
expect(reporter.send(:diff)).to eq(<<~DIFF.strip)
|
||||
A api/baz.rb
|
||||
DIFF
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ReporterHub do
|
||||
|
||||
Reference in New Issue
Block a user