Skip to content

Commit

Permalink
Improve mark_spec performance
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhongRuoyu committed Jun 11, 2024
1 parent 497b5d7 commit 663cea0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
28 changes: 14 additions & 14 deletions Library/Homebrew/test/cmd/mark_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,39 @@ def installed_as_dependency?(formula)
Tab.for_formula(formula).installed_as_dependency
end

let(:testball) { Formula["testball"] }
let(:foo) { Formula["foo"] }

before do
install_test_formula "testball", tab_attributes: {
setup_test_formula "foo", tab_attributes: {
"installed_on_request" => false,
"installed_as_dependency" => true,
}
end

it "marks or unmarks a formula as installed on request" do
expect { brew "mark", "--installed-on-request", "testball" }
expect { brew "mark", "--installed-on-request", "foo" }
.to be_a_success
.and output(/testball is now marked as installed on request/).to_stdout
.and output(/foo is now marked as installed on request/).to_stdout
.and not_to_output.to_stderr
expect(installed_on_request?(testball)).to be true
expect(installed_on_request?(foo)).to be true

expect { brew "mark", "--no-installed-on-request", "testball" }
expect { brew "mark", "--no-installed-on-request", "foo" }
.to be_a_success
.and output(/testball is now marked as not installed on request/).to_stdout
.and output(/foo is now marked as not installed on request/).to_stdout
.and not_to_output.to_stderr
expect(installed_on_request?(testball)).to be false
expect(installed_on_request?(foo)).to be false

expect { brew "mark", "--no-installed-as-dependency", "testball" }
expect { brew "mark", "--no-installed-as-dependency", "foo" }
.to be_a_success
.and output(/testball is now marked as not installed as dependency/).to_stdout
.and output(/foo is now marked as not installed as dependency/).to_stdout
.and not_to_output.to_stderr
expect(installed_as_dependency?(testball)).to be false
expect(installed_as_dependency?(foo)).to be false

expect { brew "mark", "--installed-as-dependency", "testball" }
expect { brew "mark", "--installed-as-dependency", "foo" }
.to be_a_success
.and output(/testball is now marked as installed as dependency/).to_stdout
.and output(/foo is now marked as installed as dependency/).to_stdout
.and not_to_output.to_stderr
expect(installed_as_dependency?(testball)).to be true
expect(installed_as_dependency?(foo)).to be true
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def brew_sh(*args)
end
end

def setup_test_formula(name, content = nil, tap: CoreTap.instance, bottle_block: nil)
def setup_test_formula(name, content = nil, tap: CoreTap.instance,
bottle_block: nil, tab_attributes: nil)
case name
when /^testball/
tarball = if OS.linux?
Expand Down Expand Up @@ -174,34 +175,38 @@ def install
RUBY
end

Formulary.find_formula_in_tap(name.downcase, tap).tap do |formula_path|
formula_path.write <<~RUBY
formula_path = Formulary.find_formula_in_tap(name.downcase, tap).tap do |path|
path.write <<~RUBY
class #{Formulary.class_s(name)} < Formula
#{content.gsub(/^(?!$)/, " ")}
end
RUBY

tap.clear_cache
end
end

def install_test_formula(name, content = nil, build_bottle: false,
tab_attributes: nil)
setup_test_formula(name, content)
fi = FormulaInstaller.new(Formula[name], build_bottle:)
fi.prelude
fi.fetch
fi.install
fi.finish
return formula_path if tab_attributes.nil?

return if tab_attributes.nil?
keg = Formula[name].prefix
keg.mkpath

tab = Tab.for_name(name)
tab.tabfile ||= keg/Tab::FILENAME
tab_attributes.each do |key, value|
tab.instance_variable_set(:"@#{key}", value)
end
tab.write
nil

formula_path
end

def install_test_formula(name, content = nil, build_bottle: false)
setup_test_formula(name, content)
fi = FormulaInstaller.new(Formula[name], build_bottle:)
fi.prelude
fi.fetch
fi.install
fi.finish
end

def setup_test_tap
Expand Down

0 comments on commit 663cea0

Please sign in to comment.