Merge pull request #2209 from reitermarkus/spec-formula_installer
Convert FormulaInstaller test to spec.
This commit is contained in:
commit
c66b840f7b
137
Library/Homebrew/test/formula_installer_spec.rb
Normal file
137
Library/Homebrew/test/formula_installer_spec.rb
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
require "formula"
|
||||||
|
require "formula_installer"
|
||||||
|
require "keg"
|
||||||
|
require "tab"
|
||||||
|
require "test/support/fixtures/testball"
|
||||||
|
require "test/support/fixtures/testball_bottle"
|
||||||
|
|
||||||
|
RSpec::Matchers.define_negated_matcher :need_bottle, :be_bottle_unneeded
|
||||||
|
RSpec::Matchers.alias_matcher :have_disabled_bottle, :be_bottle_disabled
|
||||||
|
|
||||||
|
describe FormulaInstaller do
|
||||||
|
matcher :be_poured_from_bottle do
|
||||||
|
match(&:poured_from_bottle)
|
||||||
|
end
|
||||||
|
|
||||||
|
def temporary_install(formula)
|
||||||
|
expect(formula).not_to be_installed
|
||||||
|
|
||||||
|
installer = described_class.new(formula)
|
||||||
|
|
||||||
|
shutup do
|
||||||
|
installer.install
|
||||||
|
end
|
||||||
|
|
||||||
|
keg = Keg.new(formula.prefix)
|
||||||
|
|
||||||
|
expect(formula).to be_installed
|
||||||
|
|
||||||
|
begin
|
||||||
|
Tab.clear_cache
|
||||||
|
expect(Tab.for_keg(keg)).not_to be_poured_from_bottle
|
||||||
|
|
||||||
|
yield formula
|
||||||
|
ensure
|
||||||
|
Tab.clear_cache
|
||||||
|
keg.unlink
|
||||||
|
keg.uninstall
|
||||||
|
formula.clear_cache
|
||||||
|
# there will be log files when sandbox is enable.
|
||||||
|
formula.logs.rmtree if formula.logs.directory?
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(keg).not_to exist
|
||||||
|
expect(formula).not_to be_installed
|
||||||
|
end
|
||||||
|
|
||||||
|
specify "basic installation" do
|
||||||
|
ARGV << "--with-invalid_flag" # added to ensure it doesn't fail install
|
||||||
|
|
||||||
|
temporary_install(Testball.new) do |f|
|
||||||
|
# Test that things made it into the Keg
|
||||||
|
expect(f.prefix/"readme").to exist
|
||||||
|
|
||||||
|
expect(f.bin).to be_a_directory
|
||||||
|
expect(f.bin.children.count).to eq(3)
|
||||||
|
|
||||||
|
expect(f.libexec).to be_a_directory
|
||||||
|
expect(f.libexec.children.count).to eq(1)
|
||||||
|
|
||||||
|
expect(f.prefix/"main.c").not_to exist
|
||||||
|
expect(f.prefix/"license").not_to exist
|
||||||
|
|
||||||
|
# Test that things make it into the Cellar
|
||||||
|
keg = Keg.new f.prefix
|
||||||
|
keg.link
|
||||||
|
|
||||||
|
bin = HOMEBREW_PREFIX/"bin"
|
||||||
|
expect(bin).to be_a_directory
|
||||||
|
expect(bin.children.count).to eq(3)
|
||||||
|
expect(f.prefix/".brew/testball.rb").to be_readable
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
specify "Formula installation with unneeded bottle" do
|
||||||
|
allow(DevelopmentTools).to receive(:installed?).and_return(false)
|
||||||
|
|
||||||
|
formula = Testball.new
|
||||||
|
allow(formula).to receive(:bottle_unneeded?).and_return(true)
|
||||||
|
allow(formula).to receive(:bottle_disabled?).and_return(true)
|
||||||
|
|
||||||
|
expect(formula).not_to be_bottled
|
||||||
|
expect(formula).not_to need_bottle
|
||||||
|
expect(formula).to have_disabled_bottle
|
||||||
|
|
||||||
|
temporary_install(formula) do |f|
|
||||||
|
expect(f).to be_installed
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
specify "Formula is not poured from bottle when compiler specified" do
|
||||||
|
expect(ARGV.cc).to be nil
|
||||||
|
|
||||||
|
cc_arg = "--cc=clang"
|
||||||
|
ARGV << cc_arg
|
||||||
|
|
||||||
|
temporary_install(TestballBottle.new) do |f|
|
||||||
|
tab = Tab.for_formula(f)
|
||||||
|
expect(tab.compiler).to eq("clang")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
specify "check installation sanity pinned dependency" do
|
||||||
|
dep_name = "dependency"
|
||||||
|
dep_path = CoreTap.new.formula_dir/"#{dep_name}.rb"
|
||||||
|
dep_path.write <<-EOS.undent
|
||||||
|
class #{Formulary.class_s(dep_name)} < Formula
|
||||||
|
url "foo"
|
||||||
|
version "0.2"
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
|
||||||
|
Formulary::FORMULAE.delete(dep_path)
|
||||||
|
dependency = Formulary.factory(dep_name)
|
||||||
|
|
||||||
|
dependent = formula do
|
||||||
|
url "foo"
|
||||||
|
version "0.5"
|
||||||
|
depends_on dependency.name.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
(dependency.prefix("0.1")/"bin"/"a").mkpath
|
||||||
|
HOMEBREW_PINNED_KEGS.mkpath
|
||||||
|
FileUtils.ln_s dependency.prefix("0.1"), HOMEBREW_PINNED_KEGS/dep_name
|
||||||
|
|
||||||
|
dependency_keg = Keg.new(dependency.prefix("0.1"))
|
||||||
|
dependency_keg.link
|
||||||
|
|
||||||
|
expect(dependency_keg).to be_linked
|
||||||
|
expect(dependency).to be_pinned
|
||||||
|
|
||||||
|
fi = FormulaInstaller.new(dependent)
|
||||||
|
|
||||||
|
expect {
|
||||||
|
fi.check_install_sanity
|
||||||
|
}.to raise_error(CannotInstallFormulaError)
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,131 +0,0 @@
|
|||||||
require "testing_env"
|
|
||||||
require "formula"
|
|
||||||
require "formula_installer"
|
|
||||||
require "keg"
|
|
||||||
require "tab"
|
|
||||||
require "test/support/fixtures/testball"
|
|
||||||
require "test/support/fixtures/testball_bottle"
|
|
||||||
|
|
||||||
class InstallTests < Homebrew::TestCase
|
|
||||||
def temporary_install(formula)
|
|
||||||
refute_predicate formula, :installed?
|
|
||||||
|
|
||||||
installer = FormulaInstaller.new(formula)
|
|
||||||
|
|
||||||
shutup { installer.install }
|
|
||||||
|
|
||||||
keg = Keg.new(formula.prefix)
|
|
||||||
|
|
||||||
assert_predicate formula, :installed?
|
|
||||||
|
|
||||||
begin
|
|
||||||
Tab.clear_cache
|
|
||||||
refute_predicate Tab.for_keg(keg), :poured_from_bottle
|
|
||||||
|
|
||||||
yield formula
|
|
||||||
ensure
|
|
||||||
Tab.clear_cache
|
|
||||||
keg.unlink
|
|
||||||
keg.uninstall
|
|
||||||
formula.clear_cache
|
|
||||||
# there will be log files when sandbox is enable.
|
|
||||||
formula.logs.rmtree if formula.logs.directory?
|
|
||||||
end
|
|
||||||
|
|
||||||
refute_predicate keg, :exist?
|
|
||||||
refute_predicate formula, :installed?
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_a_basic_install
|
|
||||||
ARGV << "--with-invalid_flag" # added to ensure it doesn't fail install
|
|
||||||
temporary_install(Testball.new) do |f|
|
|
||||||
# Test that things made it into the Keg
|
|
||||||
assert_predicate f.prefix+"readme", :exist?
|
|
||||||
|
|
||||||
assert_predicate f.bin, :directory?
|
|
||||||
assert_equal 3, f.bin.children.length
|
|
||||||
|
|
||||||
assert_predicate f.libexec, :directory?
|
|
||||||
assert_equal 1, f.libexec.children.length
|
|
||||||
|
|
||||||
refute_predicate f.prefix+"main.c", :exist?
|
|
||||||
|
|
||||||
refute_predicate f.prefix+"license", :exist?
|
|
||||||
|
|
||||||
# Test that things make it into the Cellar
|
|
||||||
keg = Keg.new f.prefix
|
|
||||||
keg.link
|
|
||||||
|
|
||||||
bin = HOMEBREW_PREFIX+"bin"
|
|
||||||
assert_predicate bin, :directory?
|
|
||||||
assert_equal 3, bin.children.length
|
|
||||||
assert_predicate f.prefix/".brew/testball.rb", :readable?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_bottle_unneeded_formula_install
|
|
||||||
DevelopmentTools.stubs(:installed?).returns(false)
|
|
||||||
|
|
||||||
formula = Testball.new
|
|
||||||
formula.stubs(:bottle_unneeded?).returns(true)
|
|
||||||
formula.stubs(:bottle_disabled?).returns(true)
|
|
||||||
|
|
||||||
refute_predicate formula, :bottled?
|
|
||||||
assert_predicate formula, :bottle_unneeded?
|
|
||||||
assert_predicate formula, :bottle_disabled?
|
|
||||||
|
|
||||||
temporary_install(formula) do |f|
|
|
||||||
assert_predicate f, :installed?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_not_poured_from_bottle_when_compiler_specified
|
|
||||||
assert_nil ARGV.cc
|
|
||||||
|
|
||||||
cc_arg = "--cc=clang"
|
|
||||||
ARGV << cc_arg
|
|
||||||
|
|
||||||
temporary_install(TestballBottle.new) do |f|
|
|
||||||
tab = Tab.for_formula(f)
|
|
||||||
assert_equal "clang", tab.compiler
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class FormulaInstallerTests < Homebrew::TestCase
|
|
||||||
def test_check_install_sanity_pinned_dep
|
|
||||||
dep_name = "dependency"
|
|
||||||
dep_path = CoreTap.new.formula_dir/"#{dep_name}.rb"
|
|
||||||
dep_path.write <<-EOS.undent
|
|
||||||
class #{Formulary.class_s(dep_name)} < Formula
|
|
||||||
url "foo"
|
|
||||||
version "0.2"
|
|
||||||
end
|
|
||||||
EOS
|
|
||||||
|
|
||||||
Formulary::FORMULAE.delete(dep_path)
|
|
||||||
dependency = Formulary.factory(dep_name)
|
|
||||||
|
|
||||||
dependent = formula do
|
|
||||||
url "foo"
|
|
||||||
version "0.5"
|
|
||||||
depends_on dependency.name.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
dependency.prefix("0.1").join("bin/a").mkpath
|
|
||||||
HOMEBREW_PINNED_KEGS.mkpath
|
|
||||||
FileUtils.ln_s dependency.prefix("0.1"), HOMEBREW_PINNED_KEGS/dep_name
|
|
||||||
|
|
||||||
dependency_keg = Keg.new(dependency.prefix("0.1"))
|
|
||||||
dependency_keg.link
|
|
||||||
|
|
||||||
assert_predicate dependency_keg, :linked?
|
|
||||||
assert_predicate dependency, :pinned?
|
|
||||||
|
|
||||||
fi = FormulaInstaller.new(dependent)
|
|
||||||
assert_raises(CannotInstallFormulaError) { fi.check_install_sanity }
|
|
||||||
ensure
|
|
||||||
dependency_keg.unlink
|
|
||||||
Formulary::FORMULAE.delete(dep_path)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Loading…
x
Reference in New Issue
Block a user