diff options
Diffstat (limited to 'Library/Homebrew/test')
| -rw-r--r-- | Library/Homebrew/test/cmd/commands_spec.rb | 85 | ||||
| -rw-r--r-- | Library/Homebrew/test/cmd/uninstall_spec.rb | 64 | ||||
| -rw-r--r-- | Library/Homebrew/test/commands_test.rb | 77 | ||||
| -rw-r--r-- | Library/Homebrew/test/dependencies_spec.rb | 86 | ||||
| -rw-r--r-- | Library/Homebrew/test/dependencies_test.rb | 117 | ||||
| -rw-r--r-- | Library/Homebrew/test/formula_installer_spec.rb | 137 | ||||
| -rw-r--r-- | Library/Homebrew/test/formula_installer_test.rb | 131 | ||||
| -rw-r--r-- | Library/Homebrew/test/formula_spec_selection_spec.rb | 100 | ||||
| -rw-r--r-- | Library/Homebrew/test/formula_spec_selection_test.rb | 99 | ||||
| -rw-r--r-- | Library/Homebrew/test/requirements_spec.rb | 26 | ||||
| -rw-r--r-- | Library/Homebrew/test/uninstall_test.rb | 62 |
11 files changed, 498 insertions, 486 deletions
diff --git a/Library/Homebrew/test/cmd/commands_spec.rb b/Library/Homebrew/test/cmd/commands_spec.rb index f42072956..32d07a0bc 100644 --- a/Library/Homebrew/test/cmd/commands_spec.rb +++ b/Library/Homebrew/test/cmd/commands_spec.rb @@ -1,3 +1,7 @@ +require "cmd/command" +require "cmd/commands" +require "fileutils" + describe "brew commands", :integration_test do it "prints a list of all available commands" do expect { brew "commands" } @@ -5,3 +9,84 @@ describe "brew commands", :integration_test do .and be_a_success end end + +RSpec.shared_context "custom internal commands" do + let(:cmds) do + [ + # internal commands + HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb", + HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh", + + # internal developer-commands + HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb", + HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh", + ] + end + + around(:each) do |example| + begin + cmds.each do |f| + FileUtils.touch f + end + + example.run + ensure + FileUtils.rm_f cmds + end + end +end + +describe Homebrew do + include_context "custom internal commands" + + specify "::internal_commands" do + cmds = described_class.internal_commands + expect(cmds).to include("rbcmd"), "Ruby commands files should be recognized" + expect(cmds).to include("shcmd"), "Shell commands files should be recognized" + expect(cmds).not_to include("rbdevcmd"), "Dev commands shouldn't be included" + end + + specify "::internal_developer_commands" do + cmds = described_class.internal_developer_commands + expect(cmds).to include("rbdevcmd"), "Ruby commands files should be recognized" + expect(cmds).to include("shdevcmd"), "Shell commands files should be recognized" + expect(cmds).not_to include("rbcmd"), "Non-dev commands shouldn't be included" + end + + specify "::external_commands" do + Dir.mktmpdir do |dir| + %w[brew-t1 brew-t2.rb brew-t3.py].each do |file| + path = "#{dir}/#{file}" + FileUtils.touch path + FileUtils.chmod 0755, path + end + + FileUtils.touch "#{dir}/brew-t4" + + ENV["PATH"] += "#{File::PATH_SEPARATOR}#{dir}" + cmds = described_class.external_commands + + expect(cmds).to include("t1"), "Executable files should be included" + expect(cmds).to include("t2"), "Executable Ruby files should be included" + expect(cmds).not_to include("t3"), "Executable files with a non Ruby extension shoudn't be included" + expect(cmds).not_to include("t4"), "Non-executable files shouldn't be included" + end + end +end + +describe Commands do + include_context "custom internal commands" + + describe "::path" do + specify "returns the path for an internal command" do + expect(described_class.path("rbcmd")).to eq(HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb") + expect(described_class.path("shcmd")).to eq(HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh") + expect(described_class.path("idontexist1234")).to be nil + end + + specify "returns the path for an internal developer-command" do + expect(described_class.path("rbdevcmd")).to eq(HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb") + expect(described_class.path("shdevcmd")).to eq(HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh") + end + end +end diff --git a/Library/Homebrew/test/cmd/uninstall_spec.rb b/Library/Homebrew/test/cmd/uninstall_spec.rb index 65f69e802..b9a0d8d40 100644 --- a/Library/Homebrew/test/cmd/uninstall_spec.rb +++ b/Library/Homebrew/test/cmd/uninstall_spec.rb @@ -1,3 +1,5 @@ +require "cmd/uninstall" + describe "brew uninstall", :integration_test do it "uninstalls a given Formula" do shutup do @@ -10,3 +12,65 @@ describe "brew uninstall", :integration_test do .and be_a_success end end + +describe Homebrew do + let(:dependency) { formula("dependency") { url "f-1" } } + let(:dependent) do + formula("dependent") do + url "f-1" + depends_on "dependency" + end + end + + let(:opts) { { dependency.rack => [Keg.new(dependency.installed_prefix)] } } + + before(:each) do + [dependency, dependent].each do |f| + f.installed_prefix.mkpath + Keg.new(f.installed_prefix).optlink + end + + tab = Tab.empty + tab.homebrew_version = "1.1.6" + tab.tabfile = dependent.installed_prefix/Tab::FILENAME + tab.runtime_dependencies = [ + { "full_name" => "dependency", "version" => "1" }, + ] + tab.write + + stub_formula_loader dependency + stub_formula_loader dependent + end + + describe "::handle_unsatisfied_dependents" do + specify "when developer" do + expect { + described_class.handle_unsatisfied_dependents(opts) + }.to output(/Warning/).to_stderr + + expect(described_class).not_to have_failed + end + + specify "when not developer" do + run_as_not_developer do + expect { + described_class.handle_unsatisfied_dependents(opts) + }.to output(/Error/).to_stderr + + expect(described_class).to have_failed + end + end + + specify "when not developer and --ignore-dependencies is specified" do + ARGV << "--ignore-dependencies" + + run_as_not_developer do + expect { + described_class.handle_unsatisfied_dependents(opts) + }.not_to output.to_stderr + + expect(described_class).not_to have_failed + end + end + end +end diff --git a/Library/Homebrew/test/commands_test.rb b/Library/Homebrew/test/commands_test.rb deleted file mode 100644 index da88ee2d5..000000000 --- a/Library/Homebrew/test/commands_test.rb +++ /dev/null @@ -1,77 +0,0 @@ -require "testing_env" -require "cmd/command" -require "cmd/commands" -require "fileutils" -require "testing_env" - -class CommandsTests < Homebrew::TestCase - def setup - super - @cmds = [ - # internal commands - HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb", - HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh", - - # internal development commands - HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb", - HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh", - ] - - @cmds.each { |f| FileUtils.touch f } - end - - def teardown - @cmds.each(&:unlink) - super - end - - def test_internal_commands - cmds = Homebrew.internal_commands - assert cmds.include?("rbcmd"), "Ruby commands files should be recognized" - assert cmds.include?("shcmd"), "Shell commands files should be recognized" - refute cmds.include?("rbdevcmd"), "Dev commands shouldn't be included" - end - - def test_internal_developer_commands - cmds = Homebrew.internal_developer_commands - assert cmds.include?("rbdevcmd"), "Ruby commands files should be recognized" - assert cmds.include?("shdevcmd"), "Shell commands files should be recognized" - refute cmds.include?("rbcmd"), "Non-dev commands shouldn't be included" - end - - def test_external_commands - mktmpdir do |dir| - %w[brew-t1 brew-t2.rb brew-t3.py].each do |file| - path = "#{dir}/#{file}" - FileUtils.touch path - FileUtils.chmod 0755, path - end - - FileUtils.touch "#{dir}/brew-t4" - - ENV["PATH"] += "#{File::PATH_SEPARATOR}#{dir}" - cmds = Homebrew.external_commands - - assert cmds.include?("t1"), "Executable files should be included" - assert cmds.include?("t2"), "Executable Ruby files should be included" - refute cmds.include?("t3"), - "Executable files with a non Ruby extension shoudn't be included" - refute cmds.include?("t4"), "Non-executable files shouldn't be included" - end - end - - def test_internal_command_path - assert_equal HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb", - Commands.path("rbcmd") - assert_equal HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh", - Commands.path("shcmd") - assert_nil Commands.path("idontexist1234") - end - - def test_internal_dev_command_path - assert_equal HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb", - Commands.path("rbdevcmd") - assert_equal HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh", - Commands.path("shdevcmd") - end -end diff --git a/Library/Homebrew/test/dependencies_spec.rb b/Library/Homebrew/test/dependencies_spec.rb new file mode 100644 index 000000000..84ea53181 --- /dev/null +++ b/Library/Homebrew/test/dependencies_spec.rb @@ -0,0 +1,86 @@ +require "dependencies" +require "dependency" + +describe Dependencies do + describe "#<<" do + it "returns itself" do + expect(subject << Dependency.new("foo")).to eq(subject) + end + + it "preserves order" do + hash = { 0 => "foo", 1 => "bar", 2 => "baz" } + + subject << Dependency.new(hash[0]) + subject << Dependency.new(hash[1]) + subject << Dependency.new(hash[2]) + + subject.each_with_index do |dep, i| + expect(dep.name).to eq(hash[i]) + end + end + end + + specify "#*" do + subject << Dependency.new("foo") + subject << Dependency.new("bar") + expect(subject * ", ").to eq("foo, bar") + end + + specify "#to_a" do + dep = Dependency.new("foo") + subject << dep + expect(subject.to_a).to eq([dep]) + end + + specify "#to_ary" do + dep = Dependency.new("foo") + subject << dep + expect(subject.to_ary).to eq([dep]) + end + + specify "type helpers" do + foo = Dependency.new("foo") + bar = Dependency.new("bar", [:optional]) + baz = Dependency.new("baz", [:build]) + qux = Dependency.new("qux", [:recommended]) + quux = Dependency.new("quux") + subject << foo << bar << baz << qux << quux + expect(subject.required).to eq([foo, quux]) + expect(subject.optional).to eq([bar]) + expect(subject.build).to eq([baz]) + expect(subject.recommended).to eq([qux]) + expect(subject.default.sort_by(&:name)).to eq([foo, baz, quux, qux].sort_by(&:name)) + end + + specify "equality" do + a = Dependencies.new + b = Dependencies.new + + dep = Dependency.new("foo") + + a << dep + b << dep + + expect(a).to eq(b) + expect(a).to eql(b) + + b << Dependency.new("bar", [:optional]) + + expect(a).not_to eq(b) + expect(a).not_to eql(b) + end + + specify "#empty?" do + expect(subject).to be_empty + + subject << Dependency.new("foo") + expect(subject).not_to be_empty + end + + specify "#inspect" do + expect(subject.inspect).to eq("#<Dependencies: []>") + + subject << Dependency.new("foo") + expect(subject.inspect).to eq("#<Dependencies: [#<Dependency: \"foo\" []>]>") + end +end diff --git a/Library/Homebrew/test/dependencies_test.rb b/Library/Homebrew/test/dependencies_test.rb deleted file mode 100644 index c5444fcbc..000000000 --- a/Library/Homebrew/test/dependencies_test.rb +++ /dev/null @@ -1,117 +0,0 @@ -require "testing_env" -require "dependencies" -require "dependency" -require "requirements" - -class DependenciesTests < Homebrew::TestCase - def setup - super - @deps = Dependencies.new - end - - def test_shovel_returns_self - assert_same @deps, @deps << Dependency.new("foo") - end - - def test_preserves_order - hash = { 0 => "foo", 1 => "bar", 2 => "baz" } - @deps << Dependency.new(hash[0]) - @deps << Dependency.new(hash[1]) - @deps << Dependency.new(hash[2]) - @deps.each_with_index do |dep, idx| - assert_equal hash[idx], dep.name - end - end - - def test_repetition - @deps << Dependency.new("foo") - @deps << Dependency.new("bar") - assert_equal "foo, bar", @deps*", " - end - - def test_to_a - dep = Dependency.new("foo") - @deps << dep - assert_equal [dep], @deps.to_a - end - - def test_to_ary - dep = Dependency.new("foo") - @deps << dep - assert_equal [dep], @deps.to_ary - end - - def test_type_helpers - foo = Dependency.new("foo") - bar = Dependency.new("bar", [:optional]) - baz = Dependency.new("baz", [:build]) - qux = Dependency.new("qux", [:recommended]) - quux = Dependency.new("quux") - @deps << foo << bar << baz << qux << quux - assert_equal [foo, quux], @deps.required - assert_equal [bar], @deps.optional - assert_equal [baz], @deps.build - assert_equal [qux], @deps.recommended - assert_equal [foo, baz, quux, qux].sort_by(&:name), @deps.default.sort_by(&:name) - end - - def test_equality - a = Dependencies.new - b = Dependencies.new - - dep = Dependency.new("foo") - - a << dep - b << dep - - assert_equal a, b - assert_eql a, b - - b << Dependency.new("bar", [:optional]) - - refute_equal a, b - refute_eql a, b - end - - def test_empty - a = Dependencies.new - assert a.empty? - a << Dependency.new("foo") - refute a.empty? - end - - def test_inspect - a = Dependencies.new - assert_equal "#<Dependencies: []>", a.inspect - a << Dependency.new("foo") - assert_equal "#<Dependencies: [#<Dependency: \"foo\" []>]>", a.inspect - end -end - -class RequirementsTests < Homebrew::TestCase - def setup - super - @reqs = Requirements.new - end - - def test_shovel_returns_self - assert_same @reqs, @reqs << Object.new - end - - def test_merging_multiple_dependencies - @reqs << X11Requirement.new << X11Requirement.new - assert_equal 1, @reqs.count - @reqs << Requirement.new - assert_equal 2, @reqs.count - end - - def test_comparison_prefers_larger - @reqs << X11Requirement.new << X11Requirement.new("x11", %w[2.6]) - assert_equal [X11Requirement.new("x11", %w[2.6])], @reqs.to_a - end - - def test_comparison_does_not_merge_smaller - @reqs << X11Requirement.new("x11", %w[2.6]) << X11Requirement.new - assert_equal [X11Requirement.new("x11", %w[2.6])], @reqs.to_a - end -end diff --git a/Library/Homebrew/test/formula_installer_spec.rb b/Library/Homebrew/test/formula_installer_spec.rb new file mode 100644 index 000000000..600b4560f --- /dev/null +++ b/Library/Homebrew/test/formula_installer_spec.rb @@ -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 diff --git a/Library/Homebrew/test/formula_installer_test.rb b/Library/Homebrew/test/formula_installer_test.rb deleted file mode 100644 index c99b2de74..000000000 --- a/Library/Homebrew/test/formula_installer_test.rb +++ /dev/null @@ -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 diff --git a/Library/Homebrew/test/formula_spec_selection_spec.rb b/Library/Homebrew/test/formula_spec_selection_spec.rb new file mode 100644 index 000000000..20231ffda --- /dev/null +++ b/Library/Homebrew/test/formula_spec_selection_spec.rb @@ -0,0 +1,100 @@ +require "formula" + +describe Formula do + describe "::new" do + it "selects stable by default" do + f = formula do + url "foo-1.0" + devel { url "foo-1.1a" } + head "foo" + end + + expect(f).to be_stable + end + + it "selects stable when exclusive" do + f = formula { url "foo-1.0" } + expect(f).to be_stable + end + + it "selects devel before HEAD" do + f = formula do + devel { url "foo-1.1a" } + head "foo" + end + + expect(f).to be_devel + end + + it "selects devel when exclusive" do + f = formula { devel { url "foo-1.1a" } } + expect(f).to be_devel + end + + it "selects HEAD when exclusive" do + f = formula { head "foo" } + expect(f).to be_head + end + + it "does not select an incomplete spec" do + f = formula do + sha256 TEST_SHA256 + version "1.0" + head "foo" + end + + expect(f).to be_head + end + + it "does not set an incomplete stable spec" do + f = formula do + sha256 TEST_SHA256 + devel { url "foo-1.1a" } + head "foo" + end + + expect(f.stable).to be nil + expect(f).to be_devel + end + + it "selects HEAD when requested" do + f = formula("test", spec: :head) do + url "foo-1.0" + devel { url "foo-1.1a" } + head "foo" + end + + expect(f).to be_head + end + + it "selects devel when requested" do + f = formula("test", spec: :devel) do + url "foo-1.0" + devel { url "foo-1.1a" } + head "foo" + end + + expect(f).to be_devel + end + + it "does not set an incomplete devel spec" do + f = formula do + url "foo-1.0" + devel { version "1.1a" } + head "foo" + end + + expect(f.devel).to be nil + expect(f).to be_stable + end + + it "does not raise an error for a missing spec" do + f = formula("test", spec: :devel) do + url "foo-1.0" + head "foo" + end + + expect(f).to be_stable + end + end +end diff --git a/Library/Homebrew/test/formula_spec_selection_test.rb b/Library/Homebrew/test/formula_spec_selection_test.rb deleted file mode 100644 index 7148df173..000000000 --- a/Library/Homebrew/test/formula_spec_selection_test.rb +++ /dev/null @@ -1,99 +0,0 @@ -require "testing_env" -require "formula" - -class FormulaSpecSelectionTests < Homebrew::TestCase - def test_selects_stable_by_default - f = formula do - url "foo-1.0" - devel { url "foo-1.1a" } - head "foo" - end - - assert_predicate f, :stable? - end - - def test_selects_stable_when_exclusive - f = formula { url "foo-1.0" } - assert_predicate f, :stable? - end - - def test_selects_devel_before_head - f = formula do - devel { url "foo-1.1a" } - head "foo" - end - - assert_predicate f, :devel? - end - - def test_selects_devel_when_exclusive - f = formula { devel { url "foo-1.1a" } } - assert_predicate f, :devel? - end - - def test_selects_head_when_exclusive - f = formula { head "foo" } - assert_predicate f, :head? - end - - def test_incomplete_spec_not_selected - f = formula do - sha256 TEST_SHA256 - version "1.0" - head "foo" - end - - assert_predicate f, :head? - end - - def test_incomplete_stable_not_set - f = formula do - sha256 TEST_SHA256 - devel { url "foo-1.1a" } - head "foo" - end - - assert_nil f.stable - assert_predicate f, :devel? - end - - def test_selects_head_when_requested - f = formula("test", Pathname.new(__FILE__).expand_path, :head) do - url "foo-1.0" - devel { url "foo-1.1a" } - head "foo" - end - - assert_predicate f, :head? - end - - def test_selects_devel_when_requested - f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do - url "foo-1.0" - devel { url "foo-1.1a" } - head "foo" - end - - assert_predicate f, :devel? - end - - def test_incomplete_devel_not_set - f = formula do - url "foo-1.0" - devel { version "1.1a" } - head "foo" - end - - assert_nil f.devel - assert_predicate f, :stable? - end - - def test_does_not_raise_for_missing_spec - f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do - url "foo-1.0" - head "foo" - end - - assert_predicate f, :stable? - end -end diff --git a/Library/Homebrew/test/requirements_spec.rb b/Library/Homebrew/test/requirements_spec.rb new file mode 100644 index 000000000..3111a7c9c --- /dev/null +++ b/Library/Homebrew/test/requirements_spec.rb @@ -0,0 +1,26 @@ +require "requirements" + +describe Requirements do + describe "#<<" do + it "returns itself" do + expect(subject << Object.new).to be(subject) + end + + it "merges duplicate requirements" do + subject << X11Requirement.new << X11Requirement.new + expect(subject.count).to eq(1) + subject << Requirement.new + expect(subject.count).to eq(2) + end + + it "prefers the larger requirement when merging duplicates" do + subject << X11Requirement.new << X11Requirement.new("x11", %w[2.6]) + expect(subject.to_a).to eq([X11Requirement.new("x11", %w[2.6])]) + end + + it "does not use the smaller requirement when merging duplicates" do + subject << X11Requirement.new("x11", %w[2.6]) << X11Requirement.new + expect(subject.to_a).to eq([X11Requirement.new("x11", %w[2.6])]) + end + end +end diff --git a/Library/Homebrew/test/uninstall_test.rb b/Library/Homebrew/test/uninstall_test.rb deleted file mode 100644 index a9230ffac..000000000 --- a/Library/Homebrew/test/uninstall_test.rb +++ /dev/null @@ -1,62 +0,0 @@ -require "testing_env" -require "cmd/uninstall" - -class UninstallTests < Homebrew::TestCase - def setup - super - - @dependency = formula("dependency") { url "f-1" } - @dependent = formula("dependent") do - url "f-1" - depends_on "dependency" - end - - [@dependency, @dependent].each do |f| - f.installed_prefix.mkpath - Keg.new(f.installed_prefix).optlink - end - - tab = Tab.empty - tab.homebrew_version = "1.1.6" - tab.tabfile = @dependent.installed_prefix/Tab::FILENAME - tab.runtime_dependencies = [ - { "full_name" => "dependency", "version" => "1" }, - ] - tab.write - - stub_formula_loader @dependency - stub_formula_loader @dependent - end - - def teardown - Homebrew.failed = false - super - end - - def handle_unsatisfied_dependents - capture_stderr do - opts = { @dependency.rack => [Keg.new(@dependency.installed_prefix)] } - Homebrew.handle_unsatisfied_dependents(opts) - end - end - - def test_check_for_testball_f2s_when_developer - assert_match "Warning", handle_unsatisfied_dependents - refute_predicate Homebrew, :failed? - end - - def test_check_for_dependents_when_not_developer - run_as_not_developer do - assert_match "Error", handle_unsatisfied_dependents - assert_predicate Homebrew, :failed? - end - end - - def test_check_for_dependents_when_ignore_dependencies - ARGV << "--ignore-dependencies" - run_as_not_developer do - assert_empty handle_unsatisfied_dependents - refute_predicate Homebrew, :failed? - end - end -end |
